예제 #1
0
    def learn_config(self, device, **kwargs):
        '''
            A method that learn the device configurational state and create
            a conf object with the same configuration.

            Args:
                self (`obj`): Conf object.
                device (`obj`): The device that will be used to parse the
                    command.
        '''

        # Abstracting the show running trm as per device os
        ret = Lookup.from_device(device)
        cmd = ret.parser.show_trm.ShowRunningConfigTrm
        maker = ops_Base(device=device)

        maker.add_leaf(cmd=cmd,
                       src='[advertise_evpn_multicast]',
                       dest='trm[advertise_evpn_multicast]')


        # A workaround to pass the context as in maker it expects Context.cli
        # not just a string 'cli.
        maker.context_manager[cmd] = Context.cli
        maker.make()
        # Take a copy of the object dictionary
        if not hasattr(maker, 'trm'):
            maker.trm= {}
        new_trm = maker.trm

        # List of mapped conf objects
        conf_obj_list = []

        # Main structure attributes in the conf object
        structure_keys = ['']

        conf_obj = self()
        # Pass the class method.
        maker.dict_to_obj(conf=conf_obj, \
                          struct=structure_keys, \
                          struct_to_map=new_trm)


        conf_obj_list.append(conf_obj)

        # List of mapped conf objects
        return conf_obj_list
예제 #2
0
    def learn_config(self, device, **kwargs):
        '''
            A method that learn the device configurational state and create
            a conf object with the same configuration.

            Args:
                self (`obj`): Conf object.
                device (`obj`): The device that will be used to parse the
                    command.
        '''

        # Abstracting the show running bgp as per device os
        ret = Lookup.from_device(device)
        cmd = ret.parser.show_bgp.ShowRunningConfigBgp

        maker = ops_Base(device=device)

        maker.add_leaf(cmd=cmd,
                       src='[bgp][instance][(?P<instance>.*)][bgp_id]',
                       dest='bgp[instance][(?P<instance>.*)][bgp_id]')

        maker.add_leaf(cmd=cmd,
                       src='[bgp][instance][(?P<instance>.*)]'
                           '[protocol_shutdown]',
                       dest='bgp[instance][(?P<instance>.*)]'
                            '[protocol_shutdown]')

        maker.add_leaf(cmd=cmd,
                       src='[bgp][instance][(?P<instance>.*)][pp_name]'
                           '[(?P<pp_name>.*)]',
                       dest='bgp[instance][(?P<instance>.*)][peer_policy_attr]'
                            '[(?P<pp_name>.*)]')

        maker.add_leaf(cmd=cmd,
                       src='[bgp][instance][(?P<instance>.*)][ps_name]'
                           '[(?P<ps_name>.*)]',
                       dest='bgp[instance][(?P<instance>.*)]'
                            '[peer_session_attr][(?P<ps_name>.*)]')

        maker.add_leaf(cmd=cmd,
                       src='[bgp][instance][(?P<instance>.*)]'
                           '[vrf][(?P<vrf>.*)]',
                       dest='bgp[instance][(?P<instance>.*)][vrf_attr]'
                            '[(?P<vrf>.*)]')

        maker.add_leaf(cmd=cmd,
                       src='[bgp][instance][(?P<instance>.*)][vrf]'
                           '[(?P<vrf>.*)][af_name][(?P<af_name>.*)]',
                       dest='bgp[instance][(?P<instance>.*)][vrf_attr]'
                            '[(?P<vrf>.*)][address_family_attr]'
                            '[(?P<af_name>.*)]')

        maker.add_leaf(cmd=cmd,
                       src='[bgp][instance][(?P<instance>.*)][vrf]'
                           '[(?P<vrf>.*)][neighbor_id][(?P<neighbor_id>.*)]',
                       dest='bgp[instance][(?P<instance>.*)][vrf_attr]'
                            '[(?P<vrf>.*)][neighbor_attr]'
                            '[(?P<neighbor_id>.*)]')

        maker.add_leaf(cmd=cmd,
                       src='[bgp][instance][(?P<instance>.*)][vrf]'
                           '[(?P<vrf>.*)][neighbor_id][(?P<neighbor_id>.*)]'
                           '[nbr_af_name][(?P<nbr_af_name>.*)]',
                       dest='bgp[instance][(?P<instance>.*)][vrf_attr]'
                            '[(?P<vrf>.*)][neighbor_attr][(?P<neighbor_id>.*)]'
                            '[address_family_attr][(?P<nbr_af_name>.*)]')

        # A workaround to pass the context as in maker it expects Context.cli
        # not just a string 'cli.
        maker.context_manager[cmd] = Context.cli

        maker.make()

        # Take a copy of the object dictionary
        if not hasattr(maker, 'bgp'):
            maker.bgp = {}
        new_bgp = maker.bgp

        # List of mapped conf objects
        conf_obj_list = []

        # Main structure attributes in the conf object
        structure_keys = ['peer_policy_attr',
                          'vrf_attr',
                          'peer_session_attr',
                          'address_family_attr',
                          'neighbor_attr']

        # Deleting the old format keys from the object and building the
        # conf objects
        for instance_key in new_bgp['instance']:
            if 'vrf_attr' in new_bgp['instance'][instance_key]:
                for vrf in new_bgp['instance'][instance_key]['vrf_attr']:
                    if 'neighbor_id' in new_bgp['instance'][instance_key]\
                        ['vrf_attr'][vrf]:
                        del new_bgp['instance'][instance_key]['vrf_attr'][vrf]\
                            ['neighbor_id']
                    if 'af_name' in new_bgp['instance'][instance_key]\
                        ['vrf_attr'][vrf]:
                        del new_bgp['instance'][instance_key]['vrf_attr'][vrf]\
                            ['af_name']
                    if 'neighbor_attr' in new_bgp['instance'][instance_key]\
                        ['vrf_attr'][vrf]:
                        for neighbor in new_bgp['instance'][instance_key]\
                            ['vrf_attr'][vrf]['neighbor_attr'].keys():
                            if 'nbr_af_name' in new_bgp['instance']\
                                [instance_key]['vrf_attr'][vrf]\
                                ['neighbor_attr'][neighbor]:
                                del new_bgp['instance'][instance_key]\
                                    ['vrf_attr'][vrf]['neighbor_attr']\
                                    [neighbor]['nbr_af_name']

            # Instiantiate a BGP conf object
            conf_obj = self(bgp_id=new_bgp['instance'][instance_key]['bgp_id'])

            # Pass the class method not the instnace.
            maker.dict_to_obj(conf=conf_obj,\
                              struct=structure_keys,\
                              struct_to_map=new_bgp['instance'][instance_key])

            conf_obj_list.append(conf_obj)

        # List of mapped conf objects
        return conf_obj_list
예제 #3
0
    def learn_config(self, device, **kwargs):
        '''
            A method that learn the device configurational state and create
            a conf object with the same configuration.

            Args:
                self (`obj`): Conf object.
                device (`obj`): The device that will be used to parse the
                    command.
        '''

        # Abstracting the show running vrf as per device os
        ret = Lookup.from_device(device)
        cmd = ret.parser.show_vrf.ShowRunningConfigVrf
        maker = ops_Base(device=device)

        maker.add_leaf(cmd=cmd,
                       src='[vrf][(?P<vrf>.*)][rd]',
                       dest='vrf[vrf][(?P<vrf>.*)][rd]')
        maker.add_leaf(cmd=cmd,
                       src='[vrf][(?P<vrf>.*)]'
                       '[vni]',
                       dest='vrf[vrf][(?P<vrf>.*)]'
                       '[vni]')
        maker.add_leaf(cmd=cmd,
                       src='[vrf][(?P<vrf>.*)]'
                       '[vni_mode_l3] l3',
                       dest='vrf[vrf][(?P<vrf>.*)]'
                       '[vni_mode_l3] l3')
        maker.add_leaf(cmd=cmd,
                       src='[vrf][(?P<vrf>.*)]'
                       '[vrf_name]',
                       dest='vrf[vrf][(?P<vrf>.*)]'
                       '[vrf_name]')
        maker.add_leaf(cmd=cmd,
                       src='[vrf][(?P<vrf>.*)][address_family]'
                       '[(?P<af_name>.*)]',
                       dest='vrf[vrf][(?P<vrf>.*)][address_family_attr]'
                       '[(?P<af_name>.*)]')

        maker.add_leaf(cmd=cmd,
                       src='[vrf][(?P<vrf>.*)][address_family]'
                       '[(?P<af_name>.*)][route_target][(?P<rt>.*)][rt_type]',
                       dest='vrf[vrf][(?P<vrf>.*)][address_family_attr]'
                       '[(?P<af_name>.*)][route_target_attr][(?P<rt>.*)]'
                       '[rt_type]')

        maker.add_leaf(cmd=cmd,
                       src='[vrf][(?P<vrf>.*)][address_family]'
                       '[(?P<af_name>.*)][route_target][(?P<rt>.*)]'
                       '[protocol][(?P<protocol>.*)]',
                       dest='vrf[vrf][(?P<vrf>.*)][address_family_attr]'
                       '[(?P<af_name>.*)][route_target_attr][(?P<rt>.*)]'
                       '[protocol_attr][(?P<protocol>.*)]')

        # A workaround to pass the context as in maker it expects Context.cli
        # not just a string 'cli.
        maker.context_manager[cmd] = Context.cli

        maker.make()
        # Take a copy of the object dictionary
        if not hasattr(maker, 'vrf'):
            maker.vrf = {}
        new_vrf = maker.vrf

        # List of mapped conf objects
        conf_obj_list = []

        # Main structure attributes in the conf object
        structure_keys = [
            'address_family_attr', 'route_target_attr', 'protocol_attr'
        ]
        if len(new_vrf):
            for vrf in new_vrf['vrf'].keys():
                if 'address_family_attr' in new_vrf['vrf'][vrf]:
                    for af_name in new_vrf['vrf'][vrf][
                            'address_family_attr'].keys():
                        if 'route_target' in new_vrf['vrf'][vrf][
                                'address_family_attr'][af_name]:
                            del new_vrf['vrf'][vrf]['address_family_attr'][
                                af_name]['route_target']

            for i in list(new_vrf['vrf']):
                if 'address_family_attr' not in new_vrf['vrf'][i]:
                    new_vrf['vrf'].pop(i)

            for vrf in new_vrf['vrf'].keys():
                conf_obj = self(name=vrf)
                # Pass the class method not the instnace.
                maker.dict_to_obj(conf=conf_obj, \
                                  struct=structure_keys, \
                                  struct_to_map=new_vrf['vrf'][vrf])

                conf_obj_list.append(conf_obj)

        # List of mapped conf objects
        return conf_obj_list
예제 #4
0
    def learn_config(self, device, **kwargs):
        '''
            A method that learn the device configurational state and create
            a conf object with the same configuration.

            Args:
                self (`obj`): Conf object.
                device (`obj`): The device that will be used to parse the
                    command.
        '''
        if kwargs.get('attributes', None):
            kwargs['attributes'].append('vrfs_list')

        # Abstracting the show running bgp as per device os
        ret = Lookup.from_device(device)
        cmd = ret.parser.show_msdp.ShowRunningConfigMsdp

        maker = ops_Base(device=device, **kwargs)

        # get vrfs for usage on attribtues of specific vrf
        maker.add_leaf(cmd=cmd,
                       src='[vrf]',
                       dest='vrfs_list',
                       pip_str='vrf',
                       action=lambda x: list(x.keys()))

        # A workaround to pass the context as lin maker it expects Context.cli
        # not just a string 'cli.
        maker.context_manager[cmd] = Context.cli
        maker.make()

        maker.vrfs_list = getattr(maker, 'vrfs_list', [])
        maker.vrfs_list.append('default')
        maker.vrfs_list = set(maker.vrfs_list)

        for vrf in maker.vrfs_list:

            # -----  global attributes -----
            global_src = '[vrf][{vrf}][global]'.format(vrf=vrf)
            global_dest = 'msdp[vrf_attr][{vrf}]'.format(vrf=vrf)

            # connect_retry_interval
            maker.add_leaf(cmd=cmd,
                           src=global_src + '[timer][connect_retry_interval]',
                           dest=global_dest +
                           '[global_connect_retry_interval]',
                           pip_str='reconnect-interval',
                           vrf=vrf)

            # originating_rp
            maker.add_leaf(cmd=cmd,
                           src=global_src + '[originating_rp]',
                           dest=global_dest + '[originating_rp]',
                           pip_str='originator-id',
                           vrf=vrf)

            # -----  peer attributes -----
            peer_src = '[vrf][{vrf}][peer][(?P<peer>.*)]'.format(vrf=vrf)
            peer_dest = 'msdp[vrf_attr][{vrf}][peer_attr][(?P<peer>.*)]'.format(
                vrf=vrf)

            # description
            maker.add_leaf(cmd=cmd,
                           src=peer_src + '[description]',
                           dest=peer_dest + '[description]',
                           pip_str='description',
                           vrf=vrf)

            # connected_source, peer_as
            for src, dest in {
                    '[connect_source]': '[connected_source]',
                    '[peer_as]': '[peer_as]'
            }.items():

                maker.add_leaf(cmd=cmd,
                               src=peer_src + src,
                               dest=peer_dest + dest,
                               pip_str='connect-source',
                               vrf=vrf)

            #keepalive_interval, holdtime_interval
            for src, dest in {
                    '[timer][keepalive_interval]': '[keepalive_interval]',
                    '[timer][holdtime_interval]': '[holdtime_interval]'
            }.items():

                maker.add_leaf(cmd=cmd,
                               src=peer_src + src,
                               dest=peer_dest + dest,
                               pip_str='keepalive',
                               vrf=vrf)

        maker.make()

        if kwargs.get('attributes', None):
            kwargs['attributes'].remove('vrfs_list')

        # Take a copy of the object dictionary
        if not hasattr(maker, 'msdp'):
            maker.msdp = {}
        new_msdp = maker.msdp

        # List of mapped conf objects
        conf_obj_list = []

        # Main structure attributes in the conf object
        structure_keys = ['vrf_attr', 'peer_attr']

        # Instiantiate a PIM conf object
        conf_obj = self()

        # Pass the class method not the instnace.
        maker.dict_to_obj(conf=conf_obj,\
                          struct=structure_keys,\
                          struct_to_map=new_msdp)

        conf_obj_list.append(conf_obj)

        # List of mapped conf objects
        return conf_obj_list
예제 #5
0
    def learn_config(self, device, **kwargs):
        '''
            A method that learn the device configurational state and create
            a conf object with the same configuration.

            Args:
                self (`obj`): Conf object.
                device (`obj`): The device that will be used to parse the
                    command.
        '''
        if kwargs.get('attributes', None):
            kwargs['attributes'].extend(['v4_vrfs_list', 'v6_vrfs_list'])

        # Abstracting the show running bgp as per device os
        ret = Lookup.from_device(device)
        cmd = ret.parser.show_pim.ShowRunningConfigPim

        maker = ops_Base(device=device, **kwargs)

        maker.add_leaf(cmd=cmd,
                       src='[feature_pim]',
                       dest='pim[enabled_pim]',
                       address_family='ipv4',
                       pip_str='feature')

        maker.add_leaf(cmd=cmd,
                       src='[feature_pim6]',
                       dest='pim[enabled_pim6]',
                       address_family='ipv6',
                       pip_str='feature')

        # get vrfs for usage on attribtues of specific vrf
        maker.add_leaf(cmd=cmd,
                       src='[vrf]',
                       dest='v4_vrfs_list',
                       pip_str='vrf',
                       address_family='ipv4',
                       action=lambda x: list(x.keys()))

        maker.add_leaf(cmd=cmd,
                       src='[vrf]',
                       dest='v6_vrfs_list',
                       pip_str='vrf',
                       address_family='ipv6',
                       action=lambda x: list(x.keys()))

        # A workaround to pass the context as in maker it expects Context.cli
        # not just a string 'cli.
        maker.context_manager[cmd] = Context.cli
        maker.make()

        maker.v4_vrfs_list = getattr(maker, 'v4_vrfs_list', [])
        maker.v4_vrfs_list.append('default')
        maker.v4_vrfs_list = set(maker.v4_vrfs_list)

        maker.v6_vrfs_list = getattr(maker, 'v6_vrfs_list', [])
        maker.v6_vrfs_list.append('default')
        maker.v6_vrfs_list = set(maker.v6_vrfs_list)

        v4_map = map(lambda x: (x, 'ipv4'), maker.v4_vrfs_list)
        v6_map = map(lambda x: (x, 'ipv6'), maker.v6_vrfs_list)

        for vrf, af in list(v4_map) + list(v6_map):

            # only support on ipv4
            # auto-rp
            if af == 'ipv4':
                atuo_an_src = '[vrf][{vrf}][address_family][ipv4][rp][autorp][send_rp_announce]'.format(
                    vrf=vrf)
                atuo_an_dest = 'pim[vrf_attr][{vrf}][address_family_attr][ipv4]'.format(
                    vrf=vrf)

                for src_key, dest_key in {
                        'interface': 'send_rp_announce_intf',
                        'group': 'send_rp_announce_rp_group',
                        'group_list': 'send_rp_announce_group_list',
                        'route_map': 'send_rp_announce_route_map',
                        'prefix_list': 'send_rp_announce_prefix_list',
                        'interval': 'send_rp_announce_interval',
                        'scope': 'send_rp_announce_scope',
                        'bidir': 'send_rp_announce_bidir',
                }.items():

                    maker.add_leaf(cmd=cmd,
                                   src=atuo_an_src + '[%s]' % src_key,
                                   dest=atuo_an_dest + '[%s]' % dest_key,
                                   pip_str='send-rp-announce',
                                   vrf=vrf,
                                   address_family='ipv4')

        maker.make()

        if kwargs.get('attributes', None):
            kwargs['attributes'].remove('v4_vrfs_list')
            kwargs['attributes'].remove('v6_vrfs_list')

        # Take a copy of the object dictionary
        if not hasattr(maker, 'pim'):
            maker.pim = {}
        new_pim = maker.pim

        # List of mapped conf objects
        conf_obj_list = []

        # Main structure attributes in the conf object
        structure_keys = ['vrf_attr', 'address_family_attr']

        # Instiantiate a PIM conf object
        conf_obj = self()

        # Pass the class method not the instnace.
        maker.dict_to_obj(conf=conf_obj,\
                          struct=structure_keys,\
                          struct_to_map=new_pim)

        conf_obj_list.append(conf_obj)

        # List of mapped conf objects
        return conf_obj_list