How to use the genie.conf.base.attributes.AttributesHelper function in genie

To help you get started, we’ve selected a few genie examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CiscoTestAutomation / genielibs / pkgs / conf-pkg / src / genie / libs / conf / bgp / nxos / bgp.py View on Github external
def build_config(self, apply=True, attributes=None,
                                 unconfig=False, **kwargs):
                    assert not apply
                    attributes = AttributesHelper(self, attributes)
                    configurations = CliConfigBuilder(unconfig=unconfig)

                    with configurations.submode_context(
                        attributes.format('address-family '
                                          '{address_family.value}',
                                          force=True)):
                        if unconfig and attributes.iswildcard:
                            # Never reached!
                            configurations.submode_unconfig()

                        # nxos: address-family ipv4 unicast/
                        # redistribute  route-map 
                        isis_route_policy_name = ''
                        ospf_route_policy_name = ''
                        rip_route_policy_name = ''
                        if attributes.value('af_redist_isis_route_policy'):
github CiscoTestAutomation / genielibs / pkgs / conf-pkg / src / genie / libs / conf / bgp / nxos / bgp.py View on Github external
def build_config(self, apply=True, attributes=None,
                              unconfig=False, **kwargs):
                assert not apply
                attributes = AttributesHelper(self, attributes)
                configurations = CliConfigBuilder(unconfig=unconfig)
                with configurations.submode_context(
                    attributes.format(
                        'template peer-session {ps_name}',force=True)):
                    if unconfig and attributes.iswildcard:
                        # Never reached!
                        configurations.submode_unconfig()

                    # nxos: template peer-session  \ bfd
                    if attributes.value('ps_fall_over_bfd'):
                        configurations.append_line(
                            attributes.format('bfd'))

                    # nxos: template peer-session  \
                    # remote-as 500
                    if attributes.value('ps_remote_as'):
github CiscoTestAutomation / genielibs / pkgs / conf-pkg / src / genie / libs / conf / interface / iosxe / interface.py View on Github external
def build_config(self, apply=True, attributes=None, unconfig=False,
                         **kwargs):
            assert not apply
            assert not kwargs
            attributes = AttributesHelper(self, attributes)
            configurations = CliConfigBuilder(unconfig=unconfig)

            # iosxe: interface tunnel1 / tunnel mpls traffic-eng path-option 1 dynamic
            if attributes.value('dynamic'):
                configurations.append_line(attributes.format('tunnel mpls traffic-eng path-option {path_option} dynamic'))

            # iosxe: interface tunnel1 / tunnel mpls traffic-eng path-option 1 explicit name someword
            configurations.append_line(attributes.format\
                    ('tunnel mpls traffic-eng path-option {path_option} explicit name {explicit_name}'))

            return str(configurations)
github CiscoTestAutomation / genielibs / pkgs / conf-pkg / src / genie / libs / conf / vlan / iosxr / yang / vlan.py View on Github external
def build_config(self, apply=True, attributes=None, unconfig=False, 
            **kwargs):
            attributes = AttributesHelper(self, attributes)
            configurations = CliConfigBuilder(unconfig=unconfig)
            ydk_obj = xr_ifmgr_cfg.InterfaceConfigurations()

            vlan_config = []

            for sub, attributes2 in attributes.mapping_values(
                    'interface_attr', 
                    keys=self.interface_attr):
                vlan_config.extend(sub.build_config(apply=False, 
                                                    attributes=attributes2,
                                                    unconfig=unconfig, 
                                                    ydk_obj=ydk_obj, 
                                                    **kwargs))

            # instantiate crud service
            crud_service = CRUDService()
github CiscoTestAutomation / genielibs / pkgs / conf-pkg / src / genie / libs / conf / l2vpn / iosxr / vfi.py View on Github external
def build_config(self, apply=True, attributes=None, unconfig=False,
                         **kwargs):
            assert not apply
            assert not kwargs, kwargs
            attributes = AttributesHelper(self, attributes)
            configurations = CliConfigBuilder(unconfig=unconfig)

            if isinstance(self.neighbor, PseudowireIPv4Neighbor):
                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / neighbor 1.2.3.4 pw-id 1 (config-l2vpn-bg-bd-vfi-pw)
                assert self.ip is not None
                assert self.pw_id is not None
                nbr_ctx = attributes.format('neighbor {ip} pw-id {pw_id}', force=True)
            else:
                raise ValueError(self.neighbor)
            assert nbr_ctx
            with configurations.submode_context(nbr_ctx):

                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / neighbor 1.2.3.4 pw-id 1 / dhcp ipv4 none
                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / neighbor 1.2.3.4 pw-id 1 / dhcp ipv4 snoop profile someword4
                v = attributes.value('dhcp_ipv4_snooping_profile')
                if v is not None:
github CiscoTestAutomation / genielibs / pkgs / conf-pkg / src / genie / libs / conf / lisp / iosxe / lisp.py View on Github external
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs):
                            assert not apply
                            attributes = AttributesHelper(self, attributes)
                            configurations = CliConfigBuilder(unconfig=unconfig)

                            # eid-record instance-id 101 88.88.88.0/24
                            cfg_str = 'eid-record instance-id {iid} {eid}'.\
                                        format(iid=kwargs['instance_id'], eid=self.ms_eid_id)

                            if attributes.value('ms_eid_accept_more_specifics') is True:
                                cfg_str += ' accept-more-specifics'

                            configurations.append_line(attributes.format(cfg_str))

                            return str(configurations)
github CiscoTestAutomation / genielibs / pkgs / conf-pkg / src / genie / libs / conf / lisp / iosxe / lisp.py View on Github external
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs):
                        assert not apply
                        attributes = AttributesHelper(self, attributes)
                        configurations = CliConfigBuilder(unconfig=unconfig)

                        # +- DeviceAttributes
                        #   +- RouterInstanceAttributes
                        #     +- LocatorSetAttributes
                        #       +- InterfaceAttributes
                        #         +- InterfaceTypeAttributes
                        # -----------------------------------
                        # Add InterfaceTypeAttributes configurations under InterfaceAttributes
                        for sub, attributes2 in attributes.mapping_values('locator_set_intf_type_attr', 
                                                                          sort=True, 
                                                                          keys=self.locator_set_intf_type_attr):
                            configurations.append_block(
                                sub.build_config(apply=False,
                                                 attributes=attributes2,
                                                 unconfig=unconfig,
github CiscoTestAutomation / genielibs / pkgs / conf-pkg / src / genie / libs / conf / lisp / iosxe / lisp.py View on Github external
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs):
                        assert not apply
                        attributes = AttributesHelper(self, attributes)
                        configurations = CliConfigBuilder(unconfig=unconfig)

                        # service ipv4
                        #   etr map-server 5.5.5.5 key cisco123
                        if attributes.value('etr_auth_key'):
                            cfg_str = 'etr map-resolver {etr_map_server} key {etr_auth_key}'
                            if attributes.value('etr_auth_key_type').value is not None:
                                cfg_str += ' hash-function {}'.format(attributes.value('etr_auth_key_type').name)
                            configurations.append_line(attributes.format(cfg_str))

                        # service ipv4
                        #   etr map-server 5.5.5.5 proxy-reply
                        if attributes.value('etr_proxy_reply') is True:
                            configurations.append_line(attributes.format('etr map-resolver {etr_map_server} proxy-reply'))

                        return str(configurations)
github CiscoTestAutomation / genielibs / src / conf / ospf / nxos / ospf.py View on Github external
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs):
                        assert not apply
                        attributes = AttributesHelper(self, attributes)
                        configurations = CliConfigBuilder(unconfig=unconfig)

                        # router ospf 1
                        #  area 2 virtual-link 7.7.7.7
                        if attributes.value('vl_router_id') and \
                            attributes.value('area_type') != 'stub' and \
                            attributes.value('area_type') != 'nssa':
                            with configurations.submode_context(
                                attributes.format('area {area} virtual-link {vl_router_id}', force=True)):

                                if unconfig and attributes.iswildcard:
                                    configurations.submode_unconfig()

                                # router ospf 1
                                #  area 2 virtual-link 7.7.7.7
                                #    hello-interval 55
github CiscoTestAutomation / genielibs / pkgs / conf-pkg / src / genie / libs / conf / vrf / nxos / vrf.py View on Github external
def build_config(self, apply=True, attributes=None,
                                 unconfig=False, **kwargs):
                    assert not apply
                    attributes = AttributesHelper(self, attributes)
                    configurations = CliConfigBuilder(unconfig=unconfig)

                    if unconfig:
                        if attributes.attributes['rt_type'] == {'both': None} or\
                            attributes.attributes['rt_type'] == {'import': None} or\
                            attributes.attributes['rt_type'] == {'export': None}:
                            for key, value in attributes.attributes['rt_type'].items():
                                self.tmp_rt_type = key
                        else:
                            self.tmp_rt_type = attributes.attributes['rt_type']

                        if not self.tmp_rt_type:
                            configurations.append_line(
                                'route-target import {rt}'.format(rt=self.rt))
                            configurations.append_line(
                                'route-target export {rt}'.format(rt=self.rt))