コード例 #1
0
ファイル: l2vpn.py プロジェクト: wilbeacham85/genielibs
        def build_config(self, apply=True, attributes=None, unconfig=False,
                         **kwargs):
            assert not kwargs, kwargs
            attributes = AttributesHelper(self, attributes)
            configurations = CliConfigBuilder(unconfig=unconfig)


            for bd, attributes2 in attributes.sequence_values('bridge_domains'):
                configurations.append_block(
                    str(bd.build_config(apply=False, attributes=attributes2, unconfig=unconfig,
                                    contained=True)))

            for xc, attributes2 in attributes.sequence_values('xconnects'):
                configurations.append_block(
                    str(xc.build_config(apply=False, attributes=attributes2, unconfig=unconfig,
                                    contained=True)))

            for pwc, attributes2 in attributes.sequence_values('pseudowire_classes'):
                configurations.append_block(
                    str(pwc.build_config(apply=False, attributes=attributes2, unconfig=unconfig,
                                     contained=True)))

            if apply:
                if configurations:
                    self.device.configure(configurations, fail_invalid=True)
            else:
                return CliConfig(device=self.device, unconfig=unconfig,
                                 cli_config=configurations, fail_invalid=True)
コード例 #2
0
ファイル: evi.py プロジェクト: wilbeacham85/genielibs
        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 attributes.value('enabled', force=True):

                configurations.append_line(
                    attributes.format('rd {rd}'))

                both_route_targets = set(self.export_route_targets) & set(self.import_route_targets)

                for v, attributes2 in attributes.sequence_values('export_route_targets', sort=True):
                    if v in both_route_targets:
                        cfg = 'route-target {}'.format(v.route_target)
                    else:
                        cfg = 'route-target export {}'.format(v.route_target)
                    configurations.append_line(cfg)

                for v, attributes2 in attributes.sequence_values('import_route_targets', sort=True):
                    if v in both_route_targets:
                        continue  # Already done above
                    cfg = 'route-target import {}'.format(v.route_target)
                    configurations.append_line(cfg)

                if attributes.value('auto_route_target') is not None:
                    if attributes.value('auto_route_target'):
                        configurations.append_line('auto-route-target')
                    else:
                        configurations.append_line('no auto-route-target', unconfig_cmd = 'auto-route-target')

            return str(configurations)
コード例 #3
0
        def build_config(self,
                         apply=True,
                         attributes=None,
                         unconfig=False,
                         contained=False,
                         **kwargs):
            assert not kwargs, kwargs
            attributes = AttributesHelper(self, attributes)
            configurations = CliConfigBuilder(unconfig=unconfig)

            # create vfi configurations
            for vfi, attributes2 in attributes.sequence_values('vfis'):
                configurations.append_block(
                    str(
                        vfi.build_config(apply=False,
                                         attributes=attributes2,
                                         unconfig=unconfig,
                                         **kwargs)))

            with configurations.submode_context(
                    attributes.format('bridge-domain {name}', force=True)):
                if unconfig and attributes.iswildcard:
                    configurations.submode_unconfig()

                for evi, attributes2 in attributes.mapping_values(
                        'evi_attr', keys=self.evis, sort=True):
                    cfg = attributes2.format('member evpn-instance {evi_id}')
                    if cfg:
                        cfg += attributes2.format(' vlan {vlan}', force=True)
                        configurations.append_line(cfg)

                for vfi, attributes2 in attributes.sequence_values('vfis'):
                    configurations.append_line(
                        attributes2.format('member vfi {name}'))

                for sub, attributes2 in attributes.mapping_values(
                        'interface_attr', keys=self.interfaces, sort=True):
                    if isinstance(sub.interface, EFPInterface):
                        configurations.append_line(
                            attributes2.format(
                                'member {interface.parent_interface.name} service-instance {interface.service_instance}'
                            ))
                    elif isinstance(sub.interface, EthernetInterface):
                        configurations.append_line(
                            attributes2.format('member {interface.name}'))
                    else:
                        raise NotImplementedError(sub.interface)

            if apply:
                if configurations:
                    self.device.configure(str(configurations),
                                          fail_invalid=True)
            else:
                return CliConfig(device=self.device,
                                 unconfig=unconfig,
                                 cli_config=configurations,
                                 fail_invalid=True)
コード例 #4
0
            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)

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

                    # import_from_global_map
                    if attributes.value('import_from_global_map'):
                        configurations.append_line(
                            attributes.format('import {address_family.value} '
                                              'map {import_from_global_map}', force=True))

                    # export_to_global_map
                    if attributes.value('export_to_global_map'):
                        configurations.append_line(
                            attributes.format('export {address_family.value} '
                                              'map {export_to_global_map}', force=True))

                    # routing_table_limit_number
                    if attributes.value('routing_table_limit_number') and \
                       attributes.value('alert_percent_value'):
                        configurations.append_line(
                            attributes.format('maximum routes {routing_table_limit_number} '
                                              '{alert_percent_value}'))
                    elif attributes.value('routing_table_limit_number') and \
                       attributes.value('simple_alert'):
                        configurations.append_line(
                            attributes.format('maximum routes {routing_table_limit_number} '
                                              'warning-only'))

                    # keep old handle
                    if self.address_family.value == 'ipv4 unicast':
                        if attributes.value('export_route_targets'):
                            for v, attributes3 in attributes.sequence_values('export_route_targets'):
                                configurations.append_line('route-target export {}'.format(v.route_target))

                        if attributes.value('import_route_targets'):
                            for v, attributes3 in attributes.sequence_values('import_route_targets'):
                                configurations.append_line('route-target import {}'.format(v.route_target))
                    
                    if attributes.value('maximum_routes'):
                        configurations.append(attributes.format('maximum routes {maximum_routes}'))


                    # loop over all route-target
                    for sub, attributes2 in attributes.mapping_values(
                            'route_target_attr', keys=self.route_target_attr.keys(), sort=True):
                        configurations.append_block(sub.build_config(apply=False,
                            attributes=attributes2, unconfig=unconfig, **kwargs))

                return str(configurations)
コード例 #5
0
ファイル: igmp.py プロジェクト: wilbeacham85/genielibs
            def build_config(self, apply=True, attributes=None, unconfig=False,
                             **kwargs):
                assert not kwargs, kwargs
                attributes = AttributesHelper(self, attributes)
                configurations = CliConfigBuilder(unconfig=unconfig)

                # global_max_groups -- not supported on nxos

                with configurations.submode_context(
                    attributes.format('vrf context {vrf_id}' if 
                            self.vrf_id != 'default' else '', force=True)):
                    if unconfig and attributes.iswildcard and self.vrf_id != 'default':
                        configurations.submode_unconfig()

                    # Ssm Attributes under vrf level config
                    for ssm, attributes2 in attributes.sequence_values('ssm', sort=True):
                        if unconfig:
                            configurations.append_block(ssm.build_unconfig(
                                apply=False, attributes=attributes2, **kwargs))
                        else:
                            configurations.append_block(ssm.build_config(
                                apply=False, attributes=attributes2, **kwargs))

                # InterfaceAttributes
                for sub, attributes2 in attributes.mapping_values('interface_attr',
                        sort=True, keys=self.interface_attr):
                            configurations.append_block(
                                sub.build_config(apply=False,
                                                 attributes=attributes2,
                                                 unconfig=unconfig))

                return str(configurations)
コード例 #6
0
ファイル: mcast.py プロジェクト: wilbeacham85/genielibs
                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)

                    # Set decider key af_name from user set address family
                    self.af_name = self.address_family.value

                    # ======
                    # enable
                    # ======
                    if attributes.value('enabled'):
                        if unconfig is False:
                            if self.af_name == 'ipv4':
                                configurations.append_line(
                                    attributes.format('feature pim'))
                            elif self.af_name == 'ipv6':
                                configurations.append_line(
                                    attributes.format('feature pim6'))
                        elif unconfig is True:
                            if self.af_name == 'ipv4':
                                configurations.append_line('no feature pim',
                                                           raw=True)
                            elif self.af_name == 'ipv6':
                                configurations.append_line('no feature pim6',
                                                           raw=True)

                    # =========
                    # multipath
                    # =========
                    if attributes.value('multipath'):
                        if unconfig is False:
                            configurations.append_line(
                                attributes.format('ip multicast multipath'))
                        elif unconfig is True:
                            configurations.append_line(
                                'no ip multicast multipath', raw=True)

                    # Mroute attributes configs
                    for mroute, attributes2 in attributes.sequence_values(
                            'mroutes', sort=True):
                        kwargs = {'vrf': self.vrf_id, 'af_name': self.af_name}
                        if unconfig:
                            configurations.append_block(
                                mroute.build_unconfig(apply=False,
                                                      attributes=attributes2,
                                                      **kwargs))
                        else:
                            configurations.append_block(
                                mroute.build_config(apply=False,
                                                    attributes=attributes2,
                                                    **kwargs))

                    return str(configurations)
コード例 #7
0
ファイル: mld.py プロジェクト: karmoham/genielibs
            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)

                # global_max_groups
                if attributes.value('global_max_groups'):
                    cfg_str = 'ipv6 mld state-limit {global_max_groups}' \
                        if self.vrf_id == 'default' else \
                            'ipv6 mld vrf {vrf_id} state-limit {global_max_groups}'

                    configurations.append_line(
                        attributes.format(cfg_str, force=True))

                # ipv6 mld [vrf <vrf>] ssm-map enable
                if hasattr(attributes.value('ssm'), 'data'):
                    if attributes.value('ssm').data:
                        cfg_str = 'ipv6 mld ssm-map enable' \
                            if self.vrf_id == 'default' else \
                                'ipv6 mld vrf {} ssm-map enable'.format(self.vrf_id)

                        configurations.append_line(attributes.format(cfg_str))

                # Ssm Attributes under vrf level config
                for ssm, attributes2 in attributes.sequence_values('ssm',
                                                                   sort=True):
                    kwargs = {'vrf': self.vrf_id}
                    if unconfig:
                        configurations.append_block(
                            ssm.build_unconfig(apply=False,
                                               attributes=attributes2,
                                               **kwargs))
                    else:
                        configurations.append_block(
                            ssm.build_config(apply=False,
                                             attributes=attributes2,
                                             **kwargs))

                # InterfaceAttributes
                for sub, attributes2 in attributes.mapping_values(
                        'interface_attr', sort=True, keys=self.interface_attr):
                    configurations.append_block(
                        sub.build_config(apply=False,
                                         attributes=attributes2,
                                         unconfig=unconfig))

                return str(configurations)
コード例 #8
0
                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)

                    self.af_name = self.address_family.value
                    self.af_name = self.af_name.replace('ipv4', 'ip')

                    # enable
                    if attributes.value('enable'):
                        if self.vrf_id == 'default':
                            cfg_str = '{af_name} multicast-routing'
                        else:
                            cfg_str = '{af_name} multicast-routing vrf {vrf_id}'

                        if self.af_name == 'ip':
                            cfg_str += ' distributed'

                        configurations.append_line(attributes.format(cfg_str))

                    # multipath
                    if attributes.value('multipath'):
                        configurations.append_line(
                            attributes.format('{af_name} multicast multipath'))

                    # Mroute Attributes under top level config
                    for mroute, attributes2 in attributes.sequence_values(
                            'mroutes', sort=True):
                        kwargs = {'vrf': self.vrf_id, 'af_name': self.af_name}
                        if unconfig:
                            configurations.append_block(
                                mroute.build_unconfig(apply=False,
                                                      attributes=attributes2,
                                                      **kwargs))
                        else:
                            configurations.append_block(
                                mroute.build_config(apply=False,
                                                    attributes=attributes2,
                                                    **kwargs))

                    return str(configurations)
コード例 #9
0
ファイル: evpn.py プロジェクト: wilbeacham85/genielibs
        def build_config(self,
                         interfaces=None,
                         apply=True,
                         attributes=None,
                         unconfig=False,
                         **kwargs):
            assert not apply
            attributes = AttributesHelper(self, attributes)
            configurations = CliConfigBuilder(unconfig=unconfig)

            if interfaces is None:
                interfaces = set(self.interfaces)
            else:
                interfaces = set(self.interfaces).intersection(interfaces)

            with configurations.submode_context('l2vpn evpn'):
                if unconfig and attributes.iswildcard:
                    configurations.submode_unconfig()

                if attributes.value('arp_flooding_suppression') is not None:
                    if attributes.value('arp_flooding_suppression') is False:
                        configurations.append(
                            'arp flooding-suppression disable')

                configurations.append_line(
                    attributes.format('replication-type {replication_type}'))
                configurations.append_line(
                    attributes.format('mpls label mode {label_mode}'))

            for evi, attributes2 in attributes.sequence_values('evis',
                                                               sort=True):
                if unconfig:
                    configurations.append_block(
                        evi.build_unconfig(apply=False,
                                           attributes=attributes2))
                else:
                    configurations.append_block(
                        evi.build_config(apply=False, attributes=attributes2))

            if apply:
                if configurations:
                    self.device.configure(configurations, fail_invalid=True)
            else:
                return str(configurations)
コード例 #10
0
ファイル: vfi.py プロジェクト: wilbeacham85/genielibs
        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)

            # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp (config-l2vpn-bg-bd-vfi-ad)
            with configurations.submode_context('autodiscovery bgp'):
                if not attributes.value('enabled', force=True):
                    configurations.submode_cancel()

                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / control-word
                if attributes.value('control_word'):
                    configurations.append_line('control-word')

                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / rd 1.2.3.4:1
                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / rd 100000:200
                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / rd 100:200000
                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / rd auto
                configurations.append_line(attributes.format('rd {rd}'))

                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-policy export <rtepol>
                configurations.append_line(
                    attributes.format('route-policy {export_route_policy}'))

                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target 1.2.3.4:1
                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target 100000:200
                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target 100:200000
                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target export 1.2.3.4:1
                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target export 100000:200
                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target export 100:200000
                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target export import 1.2.3.4:1 (bug)
                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target export import 100000:200 (bug)
                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target export import 100:200000 (bug)
                both_route_targets = set(self.export_route_targets) & set(
                    self.import_route_targets)
                for v, attributes2 in attributes.sequence_values(
                        'export_route_targets', sort=True):
                    if v in both_route_targets:
                        cfg = 'route-target {}'.format(v.route_target)
                    else:
                        cfg = 'route-target export {}'.format(v.route_target)
                    if v.stitching:
                        warnings.warn(UnsupportedAttributeWarning,
                                      'route-target export/import stitching')
                    configurations.append_line(cfg)

                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target import 1.2.3.4:1
                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target import 100000:200
                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target import 100:200000
                for v, attributes2 in attributes.sequence_values(
                        'import_route_targets', sort=True):
                    if v not in both_route_targets:
                        cfg = 'route-target import {}'.format(v.route_target)
                        if v.stitching:
                            warnings.warn(
                                UnsupportedAttributeWarning,
                                'route-target export/import stitching')
                        configurations.append_line(cfg)

                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / signaling-protocol bgp (config-l2vpn-bg-bd-vfi-ad-sig)
                sub, attributes2 = attributes.namespace(
                    'signaling_protocol_bgp')
                if sub is not None:
                    configurations.append_block(
                        sub.build_config(apply=False,
                                         attributes=attributes2,
                                         unconfig=unconfig))

                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / signaling-protocol ldp (config-l2vpn-bg-bd-vfi-ad-sig)
                sub, attributes2 = attributes.namespace(
                    'signaling_protocol_ldp')
                if sub is not None:
                    configurations.append_block(
                        sub.build_config(apply=False,
                                         attributes=attributes2,
                                         unconfig=unconfig))

                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / table-policy <rtepol>
                configurations.append_line(
                    attributes.format('table-policy {table_policy}'))

            return str(configurations)
コード例 #11
0
        def build_config(self,
                         interfaces=None,
                         apply=True,
                         attributes=None,
                         unconfig=False,
                         **kwargs):
            # assert not apply
            attributes = AttributesHelper(self, attributes)
            configurations = CliConfigBuilder(unconfig=unconfig)
            if interfaces is None:
                interfaces = set(self.interfaces)
            else:
                interfaces = set(self.interfaces).intersection(interfaces)

            # iosxr: evpn (config-evpn)
            with configurations.submode_context('evpn'):
                if unconfig and attributes.iswildcard:
                    configurations.submode_unconfig()

                # iosxr: evpn / bgp (config-evpn-bgp)
                ns, attributes2 = attributes.namespace('bgp')
                if ns is not None:
                    configurations.append_block(
                        ns.build_config(apply=False,
                                        attributes=attributes2,
                                        unconfig=unconfig,
                                        **kwargs))

                # iosxr: evpn / evi 1 (config-evpn-evi)
                for evi, attributes2 in attributes.sequence_values('evis',
                                                                   sort=True):
                    if unconfig:
                        configurations.append_block(
                            evi.build_unconfig(apply=False,
                                               attributes=attributes2))
                    else:
                        configurations.append_block(
                            evi.build_config(apply=False,
                                             attributes=attributes2))

                # iosxr: evpn / interface Bundle-Ether1 (config-evpn-ac)
                for sub, attributes2 in attributes.mapping_values(
                        'interface_attr', keys=interfaces, sort=True):
                    configurations.append_block(
                        sub.build_config(apply=False,
                                         attributes=attributes2,
                                         unconfig=unconfig,
                                         **kwargs))

                # iosxr: evpn /  virtual neighbor 70.70.70.70 pw-id 17300005
                for sub, attributes2 in attributes.mapping_values(
                        'pw_neighbor_attr', sort=True):
                    configurations.append_block(
                        sub.build_config(apply=False,
                                         attributes=attributes2,
                                         unconfig=unconfig,
                                         **kwargs))

                # iosxr: evpn /  virtual vfi ac-vfi-5
                for sub, attributes2 in attributes.mapping_values('vfi_attr',
                                                                  sort=True):
                    configurations.append_block(
                        sub.build_config(apply=False,
                                         attributes=attributes2,
                                         unconfig=unconfig,
                                         **kwargs))

                # iosxr: evpn / timers (config-evpn-timers)
                with configurations.submode_context('timers',
                                                    cancel_empty=True):

                    # iosxr: evpn / timers / recovery 20
                    configurations.append_line(
                        attributes.format('recovery {recovery_timer}'))

                    # iosxr: evpn / timers / peering <0-300>
                    configurations.append_line(
                        attributes.format('peering {peering_timer}'))

                # iosxr: evpn / source interface Loopback0
                configurations.append_line(
                    attributes.format(
                        'source interface {source_interface.name}'))

                # iosxr: evpn / load-balancing (config-evpn-lb)
                ns, attributes2 = attributes.namespace('load_balancing')
                if ns is not None:
                    configurations.append_block(
                        ns.build_config(apply=False,
                                        attributes=attributes2,
                                        unconfig=unconfig,
                                        **kwargs))

                # iosxr: evpn / bgp (config-evpn-bgp)
                ns, attributes2 = attributes.namespace('bgp')
                if ns is not None:
                    configurations.append_block(
                        ns.build_config(apply=False,
                                        attributes=attributes2,
                                        unconfig=unconfig,
                                        **kwargs))

            if apply:
                if configurations:
                    self.device.configure(configurations, fail_invalid=True)
            else:
                return CliConfig(device=self.device,
                                 unconfig=unconfig,
                                 cli_config=configurations,
                                 fail_invalid=True)
コード例 #12
0
                    def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs):
                        assert not apply
                        attributes = AttributesHelper(self, attributes)
                        configurations = CliConfigBuilder(unconfig=unconfig)
                        intf_rtr_cfgs = CliConfigBuilder(unconfig=unconfig)

                        # passive-interface GigabitEthernet1
                        if attributes.value('if_passive'):
                            intf_rtr_cfgs.append_line(attributes.format('passive-interface {interface_name}'))

                        # InterfaceStaticNeighbor attributes config
                        for intf_staticnbr_key, attributes2 in attributes.sequence_values('intf_staticnbr_keys', sort=True):
                            if unconfig:
                                intf_rtr_cfgs.append_block(intf_staticnbr_key.build_unconfig(
                                    apply=False, attributes=attributes2, **kwargs))
                            else:
                                intf_rtr_cfgs.append_block(intf_staticnbr_key.build_config(
                                    apply=False, attributes=attributes2, **kwargs))

                        # Add intf_rtr_cfgs to VrfAttributes
                        self.parent.parent.interface_router_configurations.append_block(intf_rtr_cfgs)

                        # interface GigabitEthernet1
                        with configurations.submode_context(
                            attributes.format('interface {interface_name}', force=True)):

                            # interface GigabitEthernet1
                            #   ip ospf 1 area 2
                            if attributes.value('if_admin_control'):
                                configurations.append_line(attributes.format('ip ospf {instance} area {area}'))

                            # interface GigabitEthernet1
                            #   ip ospf cost 100
                            if attributes.value('if_cost'):
                                configurations.append_line(attributes.format('ip ospf cost {if_cost}'))

                            # interface GigabitEthernet1
                            #   ip ospf network point-to-point
                            if attributes.value('if_type'):
                                iftype = attributes.value('if_type').value
                                configurations.append_line(attributes.format('ip ospf network {}'.format(iftype)))

                            # interface GigabitEthernet1
                            #   ip ospf demand-circuit
                            if attributes.value('if_demand_circuit'):
                                configurations.append_line(attributes.format('ip ospf demand-circuit'))

                            # interface GigabitEthernet1
                            #   ip ospf priority 100
                            if attributes.value('if_priority'):
                                configurations.append_line(attributes.format('ip ospf priority {if_priority}'))

                            # interface GigabitEthernet1
                            #   ip ospf bfd
                            if attributes.value('if_bfd_enable'):
                                configurations.append_line(attributes.format('ip ospf bfd'))

                            # interface GigabitEthernet1
                            #   bfd interval 50 min_rx 60 multiplier 2
                            if attributes.value('if_bfd_interval'):

                                # bfd interval [if_bfd_interval]
                                bfd_str = 'bfd interval {if_bfd_interval}'

                                # + min_rx {if_bfd_min_interval}
                                if attributes.value('if_bfd_min_interval'):
                                    bfd_str += ' min_rx {if_bfd_min_interval}'

                                # + multiplier {if_bfd_multiplier}
                                if attributes.value('if_bfd_multiplier'):
                                    bfd_str += ' multiplier {if_bfd_multiplier}'

                                configurations.append_line(attributes.format(bfd_str))

                            # interface GigabitEthernet1
                            #   ip ospf hello-interval 10
                            if attributes.value('if_hello_interval'):
                                configurations.append_line(attributes.format('ip ospf hello-interval {if_hello_interval}'))

                            # interface GigabitEthernet1
                            #   ip ospf dead-interval 10
                            if attributes.value('if_dead_interval'):
                                configurations.append_line(attributes.format('ip ospf dead-interval {if_dead_interval}'))

                            # interface GigabitEthernet1
                            #   ip ospf retransmit-interval 10
                            if attributes.value('if_retransmit_interval'):
                                configurations.append_line(attributes.format('ip ospf retransmit-interval {if_retransmit_interval}'))

                            # interface GigabitEthernet1
                            #   ip ospf lls
                            #   ip ospf lls disable
                            if attributes.value('if_lls') is True:
                                configurations.append_line(attributes.format('ip ospf lls'))
                            elif attributes.value('if_lls') is False:
                                configurations.append_line(attributes.format('ip ospf lls disable'))

                            # interface GigabitEthernet1
                            #   ip ospf ttl-security hops 50
                            if attributes.value('if_ttl_sec_enable'):

                                # ip ospf ttl-security
                                ttl_str = 'ip ospf ttl-security'

                                # + hops 50
                                if attributes.value('if_ttl_sec_hops'):
                                    ttl_str += ' hops {if_ttl_sec_hops}'

                                configurations.append_line(attributes.format(ttl_str))

                            # interface GigabitEthernet1
                            #   ip ospf authentication key-chain ottawa
                            if attributes.value('if_auth_trailer_key_chain'):
                                configurations.append_line(attributes.format('ip ospf authentication key-chain {if_auth_trailer_key_chain}'))

                            # interface GigabitEthernet1
                            #   ip ospf authentication
                            #   ip ospf authentication-key anything
                            #   ip ospf authentication message-digest
                            #   ip ospf message-digest-key 1 md5 anything
                            if attributes.value('if_auth_trailer_key_crypto_algorithm'):

                                auth_type = attributes.value('if_auth_trailer_key_crypto_algorithm').value

                                # ip ospf authentication
                                if auth_type == 'simple':
                                    configurations.append_line(attributes.format('ip ospf authentication'))

                                    # ip ospf authentication-key anything
                                    if attributes.value('if_auth_trailer_key'):
                                        configurations.append_line(attributes.format('ip ospf authentication-key {if_auth_trailer_key}'))

                                # ip ospf authentication message-digest
                                elif auth_type == 'md5':
                                    configurations.append_line(attributes.format('ip ospf authentication message-digest'))

                                    # ip ospf message-digest-key 1 md5 anything
                                    if attributes.value('if_auth_trailer_key'):
                                        configurations.append_line(attributes.format('ip ospf message-digest-key 1 md5 {if_auth_trailer_key}'))

                            # interface GigabitEthernet1
                            #   ip ospf mtu-ignore
                            if attributes.value('if_mtu_ignore'):
                                configurations.append_line(attributes.format('ip ospf mtu-ignore'))

                            # interface GigabitEthernet1
                            #   ip ospf prefix-suppression
                            if attributes.value('if_prefix_suppression'):
                                configurations.append_line(attributes.format('ip ospf prefix-suppression'))

                        return str(configurations)
コード例 #13
0
            def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs):
                assert not apply
                attributes = AttributesHelper(self, attributes)
                configurations = CliConfigBuilder(unconfig=unconfig)
                self.interface_router_configurations = CliConfigBuilder(unconfig=unconfig)

                # router ospf 1
                # router ospf 1 vrf VRF1
                with configurations.submode_context(
                    attributes.format('router ospf {instance} vrf {vrf_name}', force=True) if self.vrf_name != 'default' else \
                    attributes.format('router ospf {instance}', force=True)):

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

                    # router ospf 1
                    #   shutdown/no shutdown
                    if attributes.value('enable') is True:
                        configurations.append_line(attributes.format('no shutdown'))
                    elif attributes.value('enable'):
                        configurations.append_line(attributes.format('shutdown'))

                    # router ospf 1
                    #   router-id 1.1.1.1
                    if attributes.value('router_id'):
                        configurations.append_line(attributes.format('router-id {router_id}'))

                    # router ospf 1
                    #   distance 110
                    if attributes.value('pref_all'):
                        configurations.append_line(attributes.format('distance {pref_all}'))

                    # router ospf 1
                    #   distance ospf inter-area 30 intra-area 40 external 50
                    if attributes.value('pref_intra_area') or \
                        attributes.value('pref_inter_area') or \
                        attributes.value('pref_external'):

                        # distance ospf
                        dist_cfg_str = 'distance ospf'

                        # If internal, overwrite intra with inter
                        if attributes.value('pref_internal'):
                            attributes.value('pref_intra_area').value = attributes.value('pref_inter_area').value

                        # + intra-area {pref_intra_area}
                        if attributes.value('pref_intra_area'):
                            dist_cfg_str += ' intra-area {pref_intra_area}'
                        
                        # + inter-area {pref_inter_area}
                        if attributes.value('pref_inter_area'):
                            dist_cfg_str += ' inter-area {pref_inter_area}'
                        
                        # + external {pref_external}
                        if attributes.value('pref_external'):
                            dist_cfg_str += ' external {pref_external}'

                        configurations.append_line(attributes.format(dist_cfg_str))

                    # router ospf 1
                    #   nsr
                    if attributes.value('nsr_enable'):
                        configurations.append_line(attributes.format('nsr'))

                    # GracefulRestart attributes config
                    for gr_key, attributes2 in attributes.sequence_values('gr_keys', sort=True):
                        if unconfig:
                            configurations.append_block(gr_key.build_unconfig(
                                apply=False, attributes=attributes2, **kwargs))
                        else:
                            configurations.append_block(gr_key.build_config(
                                apply=False, attributes=attributes2, **kwargs))
                    
                    # router ospf 1
                    #   mpls ldp autoconfig area 0.0.0.0
                    if attributes.value('ldp_autoconfig'):
                        
                        # mpls ldp autoconfig
                        ldp_str = 'mpls ldp autoconfig'

                        # + area {ldp_auto_config_area_id}
                        if attributes.value('ldp_auto_config_area_id'):
                            ldp_str += ' area {ldp_auto_config_area_id}'

                        configurations.append_line(attributes.format(ldp_str))

                    # router ospf 1
                    #   mpls ldp sync
                    if attributes.value('ldp_igp_sync'):
                        configurations.append_line(attributes.format('mpls ldp sync'))

                    # router ospf 1
                    #   redistribute bgp 100 metric 10 metric-type 1 subnets nssa-only tag 5 route-map ottawa
                    if attributes.value('redist_bgp_id'):

                        # redistribute bgp {redist_bgp_id}
                        redist_bgp_str = 'redistribute bgp {redist_bgp_id}'

                        # + metric {redist_bgp_metric}
                        if attributes.value('redist_bgp_metric'):
                            redist_bgp_str += ' metric {redist_bgp_metric}'

                        # + metric-type {redist_bgp_metric_type}
                        if attributes.value('redist_bgp_metric_type'):
                            redist_type = attributes.value('redist_bgp_metric_type').value
                            redist_bgp_str += ' metric-type {}'.format(redist_type)

                        # + subnets
                        if attributes.value('redist_bgp_subnets'):
                            redist_bgp_str += ' subnets'

                        # + nssa-only
                        if attributes.value('redist_bgp_nssa_only'):
                            redist_bgp_str += ' nssa-only'

                        # + tag {redist_bgp_tag}
                        if attributes.value('redist_bgp_tag'):
                            redist_bgp_str += ' tag {redist_bgp_tag}'

                        # + route-map {redist_bgp_route_map}
                        if attributes.value('redist_bgp_route_map'):
                            redist_bgp_str += ' route-map {redist_bgp_route_map}'

                        configurations.append_line(attributes.format(redist_bgp_str))

                    # router ospf 1
                    #   redistribute connected metric 10 route-map toronto
                    if attributes.value('redist_connected'):

                        # redistribute connected
                        redist_connected_str = 'redistribute connected'

                        # + metric {redist_connected_metric}
                        if attributes.value('redist_connected_metric'):
                            redist_connected_str += ' metric {redist_connected_metric}'

                        # + route-map {redist_connected_route_policy}
                        if attributes.value('redist_connected_route_policy'):
                            redist_connected_str += ' route-map {redist_connected_route_policy}'

                        configurations.append_line(attributes.format(redist_connected_str))

                    # router ospf 1
                    #   redistribute static metric 10 route-map montreal
                    if attributes.value('redist_static'):

                        # redistribute static
                        redist_static_str = 'redistribute static'

                        # + metric {redist_static_metric}
                        if attributes.value('redist_static_metric'):
                            redist_static_str += ' metric {redist_static_metric}'

                        # + route-map {redist_static_route_policy}
                        if attributes.value('redist_static_route_policy'):
                            redist_static_str += ' route-map {redist_static_route_policy}'

                        configurations.append_line(attributes.format(redist_static_str))

                    # router ospf 1
                    #   redistribute isis metric 10 route-map test
                    if attributes.value('redist_isis'):

                        # redistribute isis {redist_isis}
                        redist_isis_str = 'redistribute isis {redist_isis}'

                        # + metric {redist_isis_metric}
                        if attributes.value('redist_isis_metric'):
                            redist_isis_str += ' metric {redist_isis_metric}'

                        # + route-map {redist_isis_route_policy}
                        if attributes.value('redist_isis_route_policy'):
                            redist_isis_str += ' route-map {redist_isis_route_policy}'

                        configurations.append_line(attributes.format(redist_isis_str))

                    # router ospf 1
                    #   redistribute maximum-prefix 10 50 warning-only
                    if attributes.value('redist_max_prefix'):

                        # redistribute maximum-prefix {redist_max_prefix}
                        redist_maxpfx_str = 'redistribute maximum-prefix {redist_max_prefix}'

                        # + {redist_max_prefix_thld}
                        if attributes.value('redist_max_prefix_thld'):
                            redist_maxpfx_str += ' {redist_max_prefix_thld}'

                        # + warning-only
                        if attributes.value('redist_max_prefix_warn_only'):
                            redist_maxpfx_str += ' warning-only'

                        configurations.append_line(attributes.format(redist_maxpfx_str))

                    # router ospf 1
                    #   bfd all-interfaces strict-mode
                    if attributes.value('bfd_enable'):

                        # bfd all-interfaces
                        bfd_str = 'bfd all-interfaces'

                        if attributes.value('bfd_strict_mode'):
                            bfd_str += ' strict-mode'

                        configurations.append_line(attributes.format(bfd_str))

                    # router ospf 1
                    #   mpls traffic-eng router-id Loopback0
                    if attributes.value('te_router_id'):
                        configurations.append_line(attributes.format('mpls traffic-eng router-id {te_router_id}'))

                    # router ospf 1
                    #   log-adjacency-changes
                    #   log-adjacency-changes detail
                    if attributes.value('log_adjacency_changes'):

                        # log-adjacency-changes
                        log_str = 'log-adjacency-changes'

                        # + detail
                        if attributes.value('log_adjacency_changes_detail'):
                            log_str += ' detail'
                        
                        configurations.append_line(attributes.format(log_str))

                    # router ospf 1
                    #   adjacency stagger 563 1625
                    if attributes.value('adjacency_stagger_initial_number'):
                        
                        # adjacency stagger {adjacency_stagger_initial_number}
                        stagger_str = 'adjacency stagger {adjacency_stagger_initial_number}'

                        # + {adjacency_stagger_maximum_number}
                        if attributes.value('adjacency_stagger_maximum_number'):
                            stagger_str += ' {adjacency_stagger_maximum_number}'

                        configurations.append_line(attributes.format(stagger_str))

                    # router ospf 1
                    #   auto-cost
                    #   auto-cost reference-bandwidth 60000
                    if attributes.value('auto_cost_enable') is False:
                        configurations.append_line(attributes.format('no auto-cost'))
                    elif attributes.value('auto_cost_enable') is True:

                        # auto-cost
                        auto_cost_str = 'auto-cost'

                        # + reference-bandwidth
                        if attributes.value('auto_cost_reference_bandwidth'):
                            auto_cost_str += ' reference-bandwidth'
                            # Calculate bandwidth based on unit type
                            if attributes.value('auto_cost_bandwidth_unit').value == 'gbps':
                                bandwidth = str(attributes.value('auto_cost_reference_bandwidth') * 1000)
                            else:
                                bandwidth = attributes.value('auto_cost_reference_bandwidth')
                            auto_cost_str += ' {}'.format(bandwidth)

                        configurations.append_line(attributes.format(auto_cost_str))

                    # router ospf 1
                    #   maximum-paths 15
                    if attributes.value('spf_paths'):
                        configurations.append_line(attributes.format('maximum-paths {spf_paths}'))

                    # router ospf 1
                    #   timers throttle spf 5000 10000 20000
                    if attributes.value('spf_start'):

                        # timers throttle spf {spf_start}
                        throttle_str = 'timers throttle spf {spf_start}'

                        # + {spf_hold}
                        if attributes.value('spf_hold'):
                            throttle_str += ' {spf_hold}'

                        # + {spf_maximum}
                        if attributes.value('spf_maximum'):
                            throttle_str += ' {spf_maximum}'

                        configurations.append_line(attributes.format(throttle_str))

                    # router ospf 1
                    #   timers throttle lsa 5000 10000 20000
                    if attributes.value('spf_lsa_start'):

                        # timers throttle {spf_lsa_start}
                        throttle_lsa = 'timers throttle lsa {spf_lsa_start}'

                        # + {spf_lsa_hold}
                        if attributes.value('spf_lsa_hold'):
                            throttle_lsa += ' {spf_lsa_hold}'

                        # + {spf_lsa_maximum}
                        if attributes.value('spf_lsa_maximum'):
                            throttle_lsa += ' {spf_lsa_maximum}'

                        configurations.append_line(attributes.format(throttle_lsa))

                    # router ospf 1
                    #   max-lsa 56666666
                    if attributes.value('db_ctrl_max_lsa'):
                        configurations.append_line(attributes.format('max-lsa {db_ctrl_max_lsa}'))

                    # StubRouter attributes config
                    for sr_key, attributes2 in attributes.sequence_values('sr_keys', sort=True):
                        if unconfig:
                            configurations.append_block(sr_key.build_unconfig(
                                apply=False, attributes=attributes2, **kwargs))
                        else:
                            configurations.append_block(sr_key.build_config(
                                apply=False, attributes=attributes2, **kwargs))

                    # router ospf 1
                    #   default-information originate always
                    if attributes.value('default_originate'):
                        
                        # + default-information originate
                        default_originate_str = 'default-information originate'

                        # + always
                        if attributes.value('default_originate_always'):
                            default_originate_str += ' always'

                        configurations.append_line(attributes.format(default_originate_str))

                    # +- DeviceAttributes
                    #   +- VrfAttributes
                    #     +- AreaAttributes
                    for sub, attributes2 in attributes.mapping_values('area_attr', 
                                                                      sort=True, 
                                                                      keys=self.area_attr):
                        configurations.append_block(
                            sub.build_config(apply=False,
                                             attributes=attributes2,
                                             unconfig=unconfig))
                
                    # Add interface configurations under router submode
                    configurations.append_block(self.interface_router_configurations)

                return str(configurations)
コード例 #14
0
                def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs):
                    assert not apply
                    attributes = AttributesHelper(self, attributes)
                    configurations = CliConfigBuilder(unconfig=unconfig)

                    # AreaNetwork attributes config
                    for areanetwork_key, attributes2 in attributes.sequence_values('areanetwork_keys', sort=True):
                        kwargs = {'area':self.area}
                        if unconfig:
                            configurations.append_block(areanetwork_key.build_unconfig(
                                apply=False, attributes=attributes2, **kwargs))
                        else:
                            configurations.append_block(areanetwork_key.build_config(
                                apply=False, attributes=attributes2, **kwargs))

                    # router ospf 1
                    #   mpls traffic-eng area 2
                    if attributes.value('area_te_enable'):
                        configurations.append_line(attributes.format('mpls traffic-eng area {area}'))

                    # router ospf 1
                    #   area 2 stub
                    #   area 2 nssa
                    #   area 2 stub no-summary
                    #   area 2 nssa no-summary
                    if attributes.value('area_type').value != 'normal':
                        #   area 2 stub
                        #   area 2 nssa
                        type_str = 'area {area}'
                        atype = attributes.value('area_type').value
                        type_str += ' {}'.format(atype)

                        # + summary
                        if attributes.value('summary') is False:
                            type_str += ' no-summary'

                        configurations.append_line(attributes.format(type_str))

                    # router ospf 1
                    #   area 2 default-cost 100
                    if attributes.value('default_cost'):
                        configurations.append_line(attributes.format('area {area} default-cost {default_cost}'))

                    # AreaRange attributes config
                    for arearange_key, attributes2 in attributes.sequence_values('arearange_keys', sort=True):
                        kwargs = {'area':self.area}
                        if unconfig:
                            configurations.append_block(arearange_key.build_unconfig(
                                apply=False, attributes=attributes2, **kwargs))
                        else:
                            configurations.append_block(arearange_key.build_config(
                                apply=False, attributes=attributes2, **kwargs))

                    # +- DeviceAttributes
                    #   +- VrfAttributes
                    #     +- AreaAttributes
                    #       +- VirtualLinkAttributes
                    for sub, attributes2 in attributes.mapping_values('virtual_link_attr', 
                                                                      sort=True, 
                                                                      keys=self.virtual_link_attr):
                        configurations.append_block(
                            sub.build_config(apply=False,
                                             attributes=attributes2,
                                             unconfig=unconfig))

                    # +- DeviceAttributes
                    #   +- VrfAttributes
                    #     +- AreaAttributes
                    #       +- ShamLinkAttributes
                    for sub, attributes2 in attributes.mapping_values('sham_link_attr', 
                                                                      sort=True, 
                                                                      keys=self.sham_link_attr):
                        configurations.append_block(
                            sub.build_config(apply=False,
                                             attributes=attributes2,
                                             unconfig=unconfig))

                    # +- DeviceAttributes
                    #   +- VrfAttributes
                    #     +- AreaAttributes
                    #       +- InterfaceAttributes
                    interface_config = CliConfigBuilder(unconfig=unconfig)
                    for sub, attributes2 in attributes.mapping_values('interface_attr', 
                                                                      sort=True, 
                                                                      keys=self.interface_attr):
                        interface_config.append_block(
                            sub.build_config(apply=False,
                                             attributes=attributes2,
                                             unconfig=unconfig))

                    self.parent.parent.interface_config.append_block(interface_config)
                    return str(configurations)
コード例 #15
0
ファイル: l2vpn.py プロジェクト: wilbeacham85/genielibs
        def build_config(self,
                         apply=True,
                         attributes=None,
                         unconfig=False,
                         **kwargs):
            assert not kwargs, kwargs
            attributes = AttributesHelper(self, attributes)
            configurations = CliConfigBuilder(unconfig=unconfig)

            # iosxr: l2vpn (config-l2vpn)
            with configurations.submode_context('l2vpn'):
                if unconfig and attributes.iswildcard:
                    configurations.submode_unconfig()

                # iosxr: l2vpn / autodiscovery bgp (config-l2vpn-ad)
                # iosxr: l2vpn / autodiscovery bgp / signaling-protocol bgp (config-l2vpn-ad-sig)
                # iosxr: l2vpn / autodiscovery bgp / signaling-protocol bgp / mtu mismatch ignore

                # iosxr: l2vpn / bridge group someword (config-l2vpn-bg)
                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 (config-l2vpn-bg-bd)
                for bd, attributes2 in attributes.sequence_values(
                        'bridge_domains'):
                    configurations.append_block(
                        str(
                            bd.build_config(apply=False,
                                            attributes=attributes2,
                                            unconfig=unconfig,
                                            contained=True)))

                # iosxr: l2vpn / capability high-mode
                # iosxr: l2vpn / capability single-mode
                # iosxr: l2vpn / description someword

                # iosxr: l2vpn / ethernet ring g8032 someword (config-l2vpn)
                for ring, attributes2 in attributes.sequence_values(
                        'g8032_rings'):
                    configurations.append_block(
                        str(
                            ring.build_config(apply=False,
                                              attributes=attributes2,
                                              unconfig=unconfig)))

                # iosxr: l2vpn / flexible-xconnect-service vlan-unaware someword (config-l2vpn)
                # iosxr: l2vpn / flexible-xconnect-service vlan-unaware someword / interface Bundle-Ether1
                # iosxr: l2vpn / flexible-xconnect-service vlan-unaware someword / neighbor evpn evi 1 target 1
                # iosxr: l2vpn / flexible-xconnect-service vlan-unaware someword / neighbor evpn evi 1 target 1 source 1

                # iosxr: l2vpn / ignore-mtu-mismatch
                # iosxr: l2vpn / load-balancing flow src-dst-ip
                # iosxr: l2vpn / load-balancing flow src-dst-mac
                # iosxr: l2vpn / logging (config-l2vpn)
                # iosxr: l2vpn / logging / bridge-domain
                # iosxr: l2vpn / logging / nsr
                # iosxr: l2vpn / logging / pseudowire
                # iosxr: l2vpn / logging / pwhe-replication disable
                # iosxr: l2vpn / logging / vfi
                # iosxr: l2vpn / neighbor all ldp flap

                # iosxr: l2vpn / pbb (config-l2vpn)
                ns, attributes2 = attributes.namespace('pbb')
                if ns is not None:
                    configurations.append_block(
                        str(
                            ns.build_config(apply=False,
                                            attributes=attributes2,
                                            unconfig=unconfig)))

                # iosxr: l2vpn / pw-class someword (config-l2vpn)
                for pwc, attributes2 in attributes.sequence_values(
                        'pseudowire_classes'):
                    configurations.append_block(
                        str(
                            pwc.build_config(apply=False,
                                             attributes=attributes2,
                                             unconfig=unconfig,
                                             contained=True)))

                # iosxr: l2vpn / pw-grouping
                # iosxr: l2vpn / pw-oam refresh transmit 1
                # iosxr: l2vpn / pw-routing (config-l2vpn)
                # iosxr: l2vpn / pw-routing / bgp (config-l2vpn)
                # iosxr: l2vpn / pw-routing / bgp / rd 100:200000
                # iosxr: l2vpn / pw-routing / bgp / rd 65536:200
                # iosxr: l2vpn / pw-routing / bgp / rd 1.2.3.4:1
                # iosxr: l2vpn / pw-routing / global-id 1
                # iosxr: l2vpn / pw-status disable

                # iosxr: l2vpn / redundancy (config-l2vpn)
                # iosxr: l2vpn / redundancy / iccp group 1 (config-l2vpn)
                # See IccpGroup objects

                # iosxr: l2vpn / router-id 1.2.3.4
                configurations.append_line(
                    attributes.format('router-id {router_id}'))

                # iosxr: l2vpn / snmp mib interface format external
                # iosxr: l2vpn / snmp mib pseudowire statistics
                # iosxr: l2vpn / tcn-propagation

                # iosxr: l2vpn / xconnect group someword (config-l2vpn)
                # iosxr: l2vpn / xconnect group someword / mp2mp someword2 (config-l2vpn)
                # iosxr: l2vpn / xconnect group someword / p2p someword2 (config-l2vpn)
                for xc, attributes2 in attributes.sequence_values('xconnects'):
                    configurations.append_block(
                        str(
                            xc.build_config(apply=False,
                                            attributes=attributes2,
                                            unconfig=unconfig,
                                            contained=True)))

            if apply:
                if configurations:
                    self.device.configure(configurations, fail_invalid=True)
            else:
                return CliConfig(device=self.device,
                                 unconfig=unconfig,
                                 cli_config=configurations,
                                 fail_invalid=True)
コード例 #16
0
            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)

                with configurations.submode_context(
                        attributes.format('router ospfv3 {instance}',
                                          force=True)):

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

                    with configurations.submode_context(
                            None if self.vrf_name == 'default' else attributes.
                            format('vrf {vrf_name}', force=True)):
                        if self.vrf_name != 'default' and unconfig and \
                                attributes.iswildcard:
                            configurations.submode_unconfig()
                        # router ospfv3 1
                        #   vrf <default/someword>
                        #     router-id 1.1.1.1
                        if attributes.value('router_id'):
                            configurations.append_line(
                                attributes.format('router-id {router_id}'))

                        # router ospfv3 1
                        #   vrf <default/someword>
                        #     shutdown
                        if attributes.value('inst_shutdown'):
                            configurations.append_line(
                                attributes.format('shutdown'))

                        # router ospfv3 1
                        #   vrf <default/someword>
                        #     passive-interface default
                        if attributes.value('passive_interface'):
                            configurations.append_line(
                                attributes.format('passive-interface default'))

                        # router ospfv3 1
                        #   log-adjacency-changes
                        #   log-adjacency-changes detail
                        if attributes.value('log_adjacency_changes'):

                            # log-adjacency-changes
                            log_str = 'log-adjacency-changes'

                            # + detail
                            if attributes.value(
                                    'log_adjacency_changes_detail'):
                                log_str += ' detail'

                            configurations.append_line(
                                attributes.format(log_str))

                        # router ospfv3 1
                        #   bfd
                        if attributes.value('bfd_enable'):
                            configurations.append_line(
                                attributes.format('bfd'))

                        # timers lsa-arrival msec
                        if attributes.value('lsa_arrival'):
                            configurations.append_line(
                                attributes.format(
                                    'timers lsa-arrival {lsa_arrival}'))

                        # timers lsa-group-pacing seconds
                        if attributes.value('lsa_group_pacing'):
                            configurations.append_line(
                                attributes.format(
                                    'timers lsa-group-pacing {lsa_group_pacing}'
                                ))

                        # timers throttle lsa start-time hold-interval max-time
                        if attributes.value(
                                'lsa_start_time') and attributes.value(
                                    'lsa_hold_time') and attributes.value(
                                        'lsa_max_time'):
                            configurations.append_line(
                                attributes.format(
                                    'timers throttle lsa {lsa_start_time} {lsa_hold_time} {lsa_max_time}'
                                ))

                        # GracefulRestart attributes config
                        for gr_key, attributes2 in attributes.sequence_values(
                                'gr_keys'):
                            if unconfig:
                                configurations.append_block(
                                    gr_key.build_unconfig(
                                        apply=False,
                                        attributes=attributes2,
                                        **kwargs))
                            else:
                                configurations.append_block(
                                    gr_key.build_config(apply=False,
                                                        attributes=attributes2,
                                                        **kwargs))

                        # +- DeviceAttributes
                        #   +- VrfAttributes
                        #     +- AddressFamilyAttributes
                        for sub, attributes2 in attributes.mapping_values(
                                'address_family_attr',
                                sort=True,
                                keys=self.address_family_attr):
                            configurations.append_block(
                                sub.build_config(apply=False,
                                                 attributes=attributes2,
                                                 unconfig=unconfig))

                        # +- DeviceAttributes
                        #   +- VrfAttributes
                        #     +- AreaAttributes
                        for sub, attributes2 in attributes.mapping_values(
                                'area_attr', sort=True, keys=self.area_attr):
                            configurations.append_block(
                                sub.build_config(apply=False,
                                                 attributes=attributes2,
                                                 unconfig=unconfig))

                return str(configurations)
コード例 #17
0
ファイル: mld.py プロジェクト: karmoham/genielibs
                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)

                    with configurations.submode_context(
                            attributes.format('interface {interface.name}',
                                              force=True)):

                        # enable
                        if attributes.value('enable'):
                            configurations.append_line('ipv6 mld router')

                        # group_policy
                        if attributes.value('group_policy'):
                            configurations.append_line(
                                attributes.format(
                                    'ipv6 mld access-group {group_policy}'))

                        # immediate_leave  -- not supported on iosxe

                        # max_groups
                        if attributes.value('max_groups'):
                            configurations.append_line(
                                attributes.format(
                                    'ipv6 mld limit {max_groups}'))

                        # query_interval
                        if attributes.value('query_interval'):
                            configurations.append_line(
                                attributes.format(
                                    'ipv6 mld query-interval {query_interval}')
                            )

                        # query_max_response_time
                        if attributes.value('query_max_response_time'):
                            configurations.append_line(
                                attributes.format(
                                    'ipv6 mld query-max-response-time '
                                    '{query_max_response_time}'))

                        # version  --  not supported on iosxe

                        # robustness_variable  --  not supported on iosxe

                        # Groups Attributes under top level config
                        for groups, attributes2 in attributes.sequence_values(
                                'groups', sort=True):
                            if unconfig:
                                configurations.append_block(
                                    groups.build_unconfig(
                                        apply=False,
                                        attributes=attributes2,
                                        **kwargs))
                            else:
                                configurations.append_block(
                                    groups.build_config(apply=False,
                                                        attributes=attributes2,
                                                        **kwargs))

                    return str(configurations)
コード例 #18
0
ファイル: iccp_group.py プロジェクト: wilbeacham85/genielibs
        def build_config(self,
                         apply=True,
                         attributes=None,
                         unconfig=False,
                         **kwargs):
            assert not kwargs, kwargs
            attributes = AttributesHelper(self, attributes)
            configurations = CliConfigBuilder(unconfig=unconfig)

            # iosxr: l2vpn (config-l2vpn)
            # iosxr: l2vpn / redundancy (config-l2vpn)
            # iosxr: redundancy (config-redundancy)
            # NOTE:
            #   Starting in release 6.2.1, redundancy is not under l2vpn
            #   submode anymore; Enter l2vpn+redundancy but exit back root in
            #   case parser automatically went up one level.
            #with configurations.submode_context('l2vpn', cancel_empty=True, exit_cmd=None), \
            #        configurations.submode_context('redundancy', cancel_empty=True, exit_cmd='root'):
            with configurations.submode_context('redundancy',
                                                cancel_empty=True):

                # iosxr: l2vpn / redundancy / iccp group 1 (config-l2vpn)
                with configurations.submode_context(
                        attributes.format('iccp group {group_id}',
                                          force=True)):
                    if unconfig and attributes.iswildcard:
                        configurations.submode_unconfig()

                    # iosxr: l2vpn / redundancy / iccp group 1 / backbone (config-redundancy-group-iccp-backbone)
                    with configurations.submode_context('backbone',
                                                        cancel_empty=True):

                        # iosxr: l2vpn / redundancy / iccp group 1 / backbone / interface <intf>
                        for sub, attributes2 in attributes.sequence_values(
                                'backbone_interfaces', sort=True):
                            configurations.append_line(
                                'interface {sub.name}'.format(sub=sub))

                    # iosxr: l2vpn / redundancy / iccp group 1 / interface Bundle-Ether1 (config-l2vpn)
                    for sub, attributes2 in attributes.mapping_values(
                            'interface_attr', keys=self.interfaces, sort=True):
                        configurations.append_block(
                            sub.build_config(apply=False,
                                             attributes=attributes2,
                                             unconfig=unconfig))

                    # iosxr: l2vpn / redundancy / iccp group 1 / isolation recovery-delay 30
                    configurations.append_line(
                        attributes.format(
                            'isolation recovery-delay {isolation_recovery_delay}'
                        ))

                    # iosxr: l2vpn / redundancy / iccp group 1 / member (config-redundancy-group-iccp-member)
                    # iosxr: l2vpn / redundancy / iccp group 1 / member / neighbor 1.2.3.4

                    # iosxr: l2vpn / redundancy / iccp group 1 / mlacp connect timeout 0

                    # iosxr: l2vpn / redundancy / iccp group 1 / mlacp node 0
                    configurations.append_line(
                        attributes.format('mlacp node {mlacp_node_id}'))

                    # iosxr: l2vpn / redundancy / iccp group 1 / mlacp system mac aaaa.bbbb.cccc
                    configurations.append_line(
                        attributes.format(
                            'mlacp system mac {mlacp_system_mac}'))

                    # iosxr: l2vpn / redundancy / iccp group 1 / mlacp system priority 1
                    configurations.append_line(
                        attributes.format(
                            'mlacp system priority {mlacp_system_priority}'))

                    # iosxr: l2vpn / redundancy / iccp group 1 / mode singleton
                    configurations.append_line(
                        attributes.format('mode {mode}'))

                    # iosxr: l2vpn / redundancy / iccp group 1 / multi-homing node-id <0-254>
                    configurations.append_line(
                        attributes.format(
                            'multi-homing node-id {multi_homing_node_id}'))

            if apply:
                if configurations:
                    self.device.configure(configurations, fail_invalid=True)
            else:
                return CliConfig(device=self.device,
                                 unconfig=unconfig,
                                 cli_config=configurations,
                                 fail_invalid=True)
コード例 #19
0
ファイル: xconnect.py プロジェクト: wilbeacham85/genielibs
        def build_config(self,
                         apply=True,
                         attributes=None,
                         unconfig=False,
                         contained=False,
                         **kwargs):
            assert not kwargs, kwargs
            attributes = AttributesHelper(self, attributes)
            configurations = CliConfigBuilder(unconfig=unconfig)

            with configurations.submode_context(
                    attributes.format('l2vpn xconnect context {name}',
                                      force=True,
                                      cancel_empty=True)):
                if attributes.value('redundancy_predictive'):
                    configurations.append_line('redundancy predictive enable')

                for interface, attributes2 in attributes.sequence_values(
                        'interfaces', sort=True):
                    if isinstance(interface, EFPInterface):
                        configurations.append_line('member {parent_interface} service-instance {service_instance}'.format\
                                                   (parent_interface = interface.parent_interface.name,\
                                                    service_instance = interface.service_instance))
                    elif isinstance(interface, EthernetInterface):
                        configurations.append_line('member {interface} '.format\
                                                   (interface = interface.name))

                for neighbor, neighbor_sub, neighbor_attributes in attributes.mapping_items(
                        'neighbor_attr', keys=self.pseudowire_neighbors,
                        sort=True):
                    if getattr(neighbor, 'pseudowire_interface',
                               None) is not None:
                        if neighbor_attributes.value(
                                'redundancy_group'
                        ) is None and neighbor_attributes.value(
                                'redundancy_priority') is None:
                            configurations.append_line(
                                'member %s' %
                                neighbor.pseudowire_interface.name)
                        elif neighbor_attributes.value(
                                'redundancy_group'
                        ) is not None and neighbor_attributes.value(
                                'redundancy_priority') is None:
                            configurations.append_line(
                                neighbor_attributes.format(
                                    'member %s group {redundancy_group}' %
                                    neighbor.pseudowire_interface.name,
                                    force=True))
                        elif neighbor_attributes.value(
                                'redundancy_group'
                        ) is not None and neighbor_attributes.value(
                                'redundancy_priority') is not None:
                            configurations.append_line(neighbor_attributes.format('member %s group {redundancy_group} priority {redundancy_priority}' \
                                                                                   % neighbor.pseudowire_interface.name,force=True))

            if apply:
                if configurations:
                    self.device.configure(str(configurations),
                                          fail_invalid=True)
            else:
                return str(configurations)
コード例 #20
0
ファイル: igmp.py プロジェクト: wilbeacham85/genielibs
                def build_config(self, apply=True, attributes=None, unconfig=False,
                                 **kwargs):
                    assert not kwargs, kwargs
                    attributes = AttributesHelper(self, attributes)
                    configurations = CliConfigBuilder(unconfig=unconfig)

                    with configurations.submode_context(
                        attributes.format('interface {intf}', force=True)):

                        # enable
                        if attributes.value('enable'):
                            configurations.append_line('ip pim sparse-mode')

                        # last_member_query_interval -- not supported on nxos

                        # group_policy
                        if attributes.value('group_policy'):
                            configurations.append_line(
                                attributes.format('ip igmp access-group {group_policy}'))

                        # immediate_leave
                        if attributes.value('immediate_leave'):
                            configurations.append_line('ip igmp immediate-leave')

                        # max_groups
                        if attributes.value('max_groups'):
                            configurations.append_line(
                                attributes.format('ip igmp state-limit {max_groups}'))

                        # query_interval
                        if attributes.value('query_interval'):
                            configurations.append_line(
                                attributes.format('ip igmp query-interval {query_interval}'))

                        # query_max_response_time
                        if attributes.value('query_max_response_time'):
                            configurations.append_line(
                                attributes.format('ip igmp query-max-response-time '
                                                  '{query_max_response_time}'))

                        # robustness_variable
                        if attributes.value('robustness_variable'):
                            configurations.append_line(
                                attributes.format('ip igmp robustness-variable '
                                                  '{robustness_variable}'))

                        # version
                        if attributes.value('version'):
                            configurations.append_line(
                                attributes.format('ip igmp version {version}'))


                        # Mroute Attributes under top level config
                        for groups, attributes2 in attributes.sequence_values(
                                'groups', sort=True):
                            if unconfig:
                                configurations.append_block(groups.build_unconfig(
                                    apply=False, attributes=attributes2, **kwargs))
                            else:
                                configurations.append_block(groups.build_config(
                                    apply=False, attributes=attributes2, **kwargs))

                    return str(configurations)
コード例 #21
0
ファイル: ldp.py プロジェクト: wilbeacham85/genielibs
                def build_config(self,
                                 apply=True,
                                 attributes=None,
                                 unconfig=False,
                                 **kwargs):
                    assert not apply
                    attributes = AttributesHelper(self, attributes)
                    configurations = CliConfigBuilder(unconfig=unconfig)

                    # iosxr: mpls ldp / address-family ipv4 (config-ldp-af)
                    # iosxr: mpls ldp / address-family ipv6 (config-ldp-af)
                    # iosxr: mpls ldp / vrf someword / address-family ipv4 (config-ldp-vrf-af)
                    with configurations.submode_context(
                            attributes.format(
                                'address-family {address_family.value}',
                                force=True)):
                        if unconfig and attributes.iswildcard:
                            configurations.submode_unconfig()

                        if self.vrf_name == 'default':
                            if self.targeted_hello_accept_from_acl:
                                # iosxr: mpls ldp / address-family ipv4|ipv6 / discovery targeted-hello accept from someword
                                configurations.append_line(
                                    attributes.format(
                                        'discovery targeted-hello accept from {targeted_hello_accept_from_acl.name}'
                                    ))
                            else:
                                # iosxr: mpls ldp / address-family ipv4|ipv6 / discovery targeted-hello accept
                                if attributes.value('targeted_hello_accept'):
                                    configurations.append_line(
                                        'discovery targeted-hello accept')

                        if self.address_family is AddressFamily.ipv4 or self.vrf_name == 'default':
                            # iosxr: mpls ldp / [vrf someword] / address-family ipv4 / discovery transport-address 1.2.3.4
                            # iosxr: mpls ldp / address-family ipv6 / discovery transport-address 1:2::3
                            v = attributes.value('transport_address')
                            if v is not None:
                                if v == 'interface':
                                    pass
                                else:
                                    configurations.append_line(
                                        attributes.format(
                                            'discovery transport-address {transport_address}'
                                        ))

                        if self.address_family is AddressFamily.ipv4 or self.vrf_name == 'default':
                            # iosxr: mpls ldp / address-family ipv4 / label (config-ldp-af-lbl)
                            # iosxr: mpls ldp / vrf someword / address-family ipv4 / label (config-ldp-vrf-af-lbl)
                            # iosxr: mpls ldp / address-family ipv6 / label (config-ldp-af-lbl)
                            with configurations.submode_context(
                                    'label', cancel_empty=True):

                                # iosxr: mpls ldp / address-family ipv4 / label / local (config-ldp-af-lbl-lcl)
                                # iosxr: mpls ldp / vrf someword / address-family ipv4 / label / local (config-ldp-vrf-af-lbl-lcl)
                                # iosxr: mpls ldp / address-family ipv6 / label / local (config-ldp-af-lbl-lcl)
                                with configurations.submode_context(
                                        'local', cancel_empty=True):

                                    # iosxr: mpls ldp / address-family ipv4 / label / local / advertise (config-ldp-af-lbl-lcl-advt)
                                    # iosxr: mpls ldp / vrf someword / address-family ipv4 / label / local / advertise (config-ldp-vrf-af-lbl-lcl-advt)
                                    # iosxr: mpls ldp / address-family ipv6 / label / local / advertise (config-ldp-af-lbl-lcl-advt)
                                    with configurations.submode_context(
                                            'advertise', cancel_empty=True):

                                        # iosxr: mpls ldp / [vrf someword] / address-family ipv4 / label / local / advertise / disable
                                        # iosxr: mpls ldp / address-family ipv6 / label / local / advertise / disable
                                        if attributes.value(
                                                'advertise') is False:
                                            configurations.append_line(
                                                'disable')

                                        # iosxr: mpls ldp / [vrf someword] / address-family ipv4 / label / local / advertise / explicit-null
                                        # iosxr: mpls ldp / [vrf someword] / address-family ipv4 / label / local / advertise / explicit-null for someword
                                        # iosxr: mpls ldp / [vrf someword] / address-family ipv4 / label / local / advertise / explicit-null for someword to someword2
                                        # iosxr: mpls ldp / [vrf someword] / address-family ipv4 / label / local / advertise / explicit-null to someword
                                        # iosxr: mpls ldp / address-family ipv6 / label / local / advertise / explicit-null
                                        # iosxr: mpls ldp / address-family ipv6 / label / local / advertise / explicit-null for someword
                                        # iosxr: mpls ldp / address-family ipv6 / label / local / advertise / explicit-null for someword to someword2
                                        # iosxr: mpls ldp / address-family ipv6 / label / local / advertise / explicit-null to someword
                                        if self.advertise_expnull_for_acl and self.advertise_expnull_to_acl:
                                            configurations.append_line(
                                                attributes.format(
                                                    'explicit-null for {advertise_expnull_for_acl.name} to {advertise_expnull_to_acl.name}'
                                                ))
                                        elif self.advertise_expnull_to_acl:
                                            configurations.append_line(
                                                attributes.format(
                                                    'explicit-null to {advertise_expnull_to_acl.name}'
                                                ))
                                        elif self.advertise_expnull_for_acl:
                                            configurations.append_line(
                                                attributes.format(
                                                    'explicit-null for {advertise_expnull_for_acl.name}'
                                                ))
                                        elif attributes.value(
                                                'advertise_expnull'):
                                            configurations.append_line(
                                                'explicit-null')

                                        # iosxr: mpls ldp / address-family ipv4|ipv6 / label / local / advertise / for someword
                                        # iosxr: mpls ldp / address-family ipv4|ipv6 / label / local / advertise / for someword to someword2
                                        if self.advertise_for_acl and self.advertise_to_acl:
                                            configurations.append_line(
                                                attributes.format(
                                                    'for {advertise_for_acl.name} to {advertise_to_acl.name}'
                                                ))
                                        else:
                                            configurations.append_line(
                                                attributes.format(
                                                    'for {advertise_for_acl.name}'
                                                ))

                                        # iosxr: mpls ldp / [vrf someword] / address-family ipv4 / label / local / advertise / interface GigabitEthernet0/0/0/0
                                        # iosxr: mpls ldp / address-family ipv6 / label / local / advertise / interface GigabitEthernet0/0/0/0
                                        for v, attributes2 in attributes.sequence_values(
                                                'advertise_interfaces'):
                                            configurations.append_line(
                                                'interface {}'.format(v.name))

                                        for neighbor, neighbor_attributes in attributes.mapping_values(
                                                'neighbor_attr',
                                                keys=self.neighbors,
                                                sort=True):

                                            # iosxr: mpls ldp / [vrf someword] / address-family ipv4 / label / local / advertise / to 1.2.3.4:0 for someword
                                            # iosxr: mpls ldp / address-family ipv6 / label / local / advertise / to 1.2.3.4:0 for someword
                                            configurations.append_line(
                                                neighbor_attributes.format(
                                                    'to {neighbor} for {advertise_for_acl.name}',
                                                    force_neighbor=True,
                                                    inherited=False))

                                    # iosxr: mpls ldp / [vrf someword] / address-family ipv4 / label / local / allocate for someword
                                    # iosxr: mpls ldp / address-family ipv6 / label / local / allocate for someword
                                    configurations.append_line(
                                        attributes.format(
                                            'allocate for {allocate_for_acl.name}'
                                        ))

                                    # iosxr: mpls ldp / [vrf someword] / address-family ipv4 / label / local / allocate for host-routes
                                    # iosxr: mpls ldp / address-family ipv6 / label / local / allocate for host-routes
                                    if attributes.value(
                                            'allocate_for_host_routes'):
                                        configurations.append_line(
                                            'allocate for host-routes')

                                    # iosxr: mpls ldp / [vrf someword] / address-family ipv4 / label / local / default-route
                                    # iosxr: mpls ldp / address-family ipv6 / label / local / default-route
                                    if attributes.value('default_route'):
                                        configurations.append_line(
                                            'default-route')

                                    # iosxr: mpls ldp / [vrf someword] / address-family ipv4 / label / local / implicit-null-override for someword
                                    # iosxr: mpls ldp / address-family ipv6 / label / local / implicit-null-override for someword
                                    configurations.append_line(
                                        attributes.format(
                                            'implicit-null-override for {impnull_override_for_acl.name}'
                                        ))

                                # iosxr: mpls ldp / address-family ipv4 / label / remote (config-ldp-af-lbl-rmt)
                                # iosxr: mpls ldp / vrf someword / address-family ipv4 / label / remote (config-ldp-vrf-af-lbl-rmt)
                                # iosxr: mpls ldp / address-family ipv6 / label / remote (config-ldp-af-lbl-rmt)
                                with configurations.submode_context(
                                        'remote', cancel_empty=True):

                                    # iosxr: mpls ldp / address-family ipv4|ipv6 / label / remote / accept (config-ldp-af-lbl-rmt-acpt)
                                    # iosxr: mpls ldp / vrf someword / address-family ipv4 / label / remote / accept (config-ldp-vrf-af-lbl-rmt-acpt)
                                    with configurations.submode_context(
                                            'accept', cancel_empty=True):

                                        for neighbor, neighbor_attributes in attributes.mapping_values(
                                                'neighbor_attr',
                                                keys=self.neighbors,
                                                sort=True):

                                            # iosxr: mpls ldp / [vrf someword] / address-family ipv4 / label / remote / accept / from 1.2.3.4:0 for someword
                                            # iosxr: mpls ldp / address-family ipv6 / label / remote / accept / from 1.2.3.4:0 for someword
                                            configurations.append_line(
                                                neighbor_attributes.format(
                                                    'from {neighbor} for {accept_for_acl.name}',
                                                    force_neighbor=True))

                        for neighbor, neighbor_attributes in attributes.mapping_values(
                                'neighbor_attr', keys=self.neighbors,
                                sort=True):

                            if self.vrf_name == 'default':
                                # iosxr: mpls ldp / address-family ipv4 / neighbor 1.2.3.4 targeted
                                # iosxr: mpls ldp / address-family ipv6 / neighbor 1:2::3 targeted
                                if neighbor_attributes.value('targeted'):
                                    configurations.append_line(
                                        neighbor_attributes.format(
                                            'neighbor {neighbor.ip} targeted',
                                            force_neighbor=True))

                        if self.vrf_name == 'default':
                            # iosxr: mpls ldp / address-family ipv4|ipv6 / redistribute (config-ldp-af-redist)
                            with configurations.submode_context(
                                    'redistribute', cancel_empty=True):

                                # iosxr: mpls ldp / address-family ipv4|ipv6 / redistribute / bgp (config-ldp-af-redist-bgp)
                                with configurations.submode_context(
                                        'bgp',
                                        cancel_empty=attributes.value(
                                            'redist_bgp') is not True):

                                    # iosxr: mpls ldp / address-family ipv4|ipv6 / redistribute / bgp / advertise-to someword
                                    configurations.append_line(
                                        attributes.format(
                                            'advertise-to {redist_bgp_advto_acl.name}'
                                        ))

                                    # iosxr: mpls ldp / address-family ipv4|ipv6 / redistribute / bgp / as 1
                                    # iosxr: mpls ldp / address-family ipv4|ipv6 / redistribute / bgp / as 100.200
                                    # iosxr: mpls ldp / address-family ipv4|ipv6 / redistribute / bgp / as 65536
                                    configurations.append_line(
                                        attributes.format(
                                            'as {redist_bgp_as}'))

                        if self.vrf_name == 'default':
                            # iosxr: mpls ldp / address-family ipv4|ipv6 / traffic-eng (config-ldp-af-te)
                            with configurations.submode_context(
                                    'traffic-eng', cancel_empty=True):

                                # iosxr: mpls ldp / address-family ipv4|ipv6 / traffic-eng / auto-tunnel mesh (config-ldp-af-te-mesh)
                                with configurations.submode_context(
                                        'auto-tunnel mesh', cancel_empty=True):

                                    # iosxr: mpls ldp / address-family ipv4|ipv6 / traffic-eng / auto-tunnel mesh / group <0-4294967295>
                                    # iosxr: mpls ldp / address-family ipv4|ipv6 / traffic-eng / auto-tunnel mesh / group all
                                    v = attributes.value(
                                        'te_autotunnel_mesh_group_id')
                                    if v is not None:
                                        if v == 'all':
                                            configurations.append_line(
                                                'group all')
                                        else:
                                            configurations.append_line(
                                                attributes.format(
                                                    'group {te_autotunnel_mesh_group_id}'
                                                ))

                    return str(configurations)
コード例 #22
0
ファイル: pim.py プロジェクト: wilbeacham85/genielibs
                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)
                    # assign ip version according to the address_family_attr
                    if hasattr(self, 'address_family'):
                        if 'ipv4' in self.address_family.value:
                            self.ip = 'ip'
                        if 'ipv6' in self.address_family.value:
                            self.ip = 'ipv6'

                    base_cfg = '{ip} pim'.format(ip=self.ip) if self.vrf_name == 'default' else \
                                '{ip} pim vrf {vrf}'.format(ip=self.ip, vrf=self.vrf_name)

                    skip_unconfig = False

                    if self.ip == 'ip':
                        # ==== PIM Auto-RP =======
                        # send-rp-announce { <send_rp_announce_intf> | <send_rp_announce_rp_group> }
                        if attributes.value('send_rp_announce_rp_group'):
                            auto_rp_str = ' send-rp-announce {send_rp_announce_rp_group}'
                        elif attributes.value('send_rp_announce_intf'):
                            auto_rp_str = ' send-rp-announce {send_rp_announce_intf}'
                        else:
                            auto_rp_str = ''

                        # + scope <send_rp_announce_scope>
                        if auto_rp_str and attributes.value(
                                'send_rp_announce_scope'):
                            auto_rp_str += ' scope {send_rp_announce_scope}'
                        else:
                            auto_rp_str = ''

                        # + group-list {send_rp_announce_group_list}
                        if auto_rp_str and attributes.value(
                                'send_rp_announce_group_list'):
                            if attributes.value('send_rp_announce_group_list'):
                                auto_rp_str += ' group-list'\
                                               ' {send_rp_announce_group_list}'

                        # + interval {send_rp_announce_interval}
                        if auto_rp_str and attributes.value(
                                'send_rp_announce_interval'):
                            if attributes.value('send_rp_announce_interval'):
                                auto_rp_str += ' interval'\
                                               ' {send_rp_announce_interval}'

                        # + bidir
                        if auto_rp_str and attributes.value(
                                'send_rp_announce_bidir'):
                            if unconfig and attributes.value('enabled_bidir'):
                                skip_unconfig = True
                            else:
                                auto_rp_str += ' bidir'
                                skip_unconfig = False

                        if auto_rp_str and not skip_unconfig:
                            configurations.append_line(
                                attributes.format(base_cfg + auto_rp_str))

                        # === PIM Send-RP-Discovery ===
                        # ip pim [ vrf <vrf_name> ]
                        # send-rp-discovery [ <send_rp_discovery_intf> ]
                        # scope <send_rp_discovery_scope>
                        # [ interval <send_rp_discovery_interval> ]

                        #  <send_rp_discovery_intf>
                        #  [scope ,send_rp_discovery_scope>]
                        if not attributes.value('send_rp_discovery_intf') and \
                           attributes.value('send_rp_discovery_scope'):
                            pre_str = ' send-rp-discovery'\
                                      ' scope {send_rp_discovery_scope}'
                        elif attributes.value('send_rp_discovery_intf') and \
                           attributes.value('send_rp_discovery_scope'):
                            pre_str = ' send-rp-discovery {send_rp_discovery_intf}'\
                                       ' scope {send_rp_discovery_scope}'
                        else:
                            pre_str = ''

                        if pre_str and attributes.value(
                                'send_rp_discovery_scope'):
                            pre_str += ' interval {send_rp_discovery_interval}'

                        if pre_str:
                            configurations.append_line(
                                attributes.format(base_cfg + pre_str))

                        # ip pim autorp listener
                        if attributes.value('autorp_listener'):
                            configurations.append_line(
                                attributes.format('ip pim autorp listener'))

                    # ==== PIM BSR =======
                    # == bsr bsr-candidate ==
                    # ip/ipv6 pim [ vrf  <vrf_name>] bsr-candidate <bsr_candidate_interface>
                    if attributes.value('bsr_candidate_interface'):

                        # ip/ipv6 pim bsr-candidate {bsr_candidate_interface}
                        bsr_str = ' bsr-candidate '\
                                  '{bsr_candidate_interface}' if self.ip == 'ip' else \
                                  '  bsr candidate bsr'\
                                  '{bsr_candidate_interface}'

                        # + <bsr_candidate_hash_mask_length>
                        if attributes.value('bsr_candidate_hash_mask_length'):
                            bsr_str += ' {bsr_candidate_hash_mask_length}'

                        # + priority <bsr_candidate_priority> |
                        # <bsr_candidate_priority>
                        if attributes.value('bsr_candidate_priority'):
                            bsr_str += ' priority {bsr_candidate_priority}' if \
                                       self.ip == 'ipv6' else \
                                       ' {bsr_candidate_priority}'

                        # + [scope]  -- only for ipv6 pim
                        if attributes.value('scope') and self.ip == 'ipv6':
                            bsr_str += ' scope'

                        # + accept-rp-candidate <bsr_candidate_accept_rp_acl>
                        if attributes.value('bsr_candidate_accept_rp_acl'):
                            bsr_str += ' accept-rp-candidate {bsr_candidate_accept_rp_acl}'

                        configurations.append_line(
                            attributes.format(base_cfg + bsr_str))

                    # == bsr rp-candidate ==
                    # ip pim rp-candidate <bsr_rp_candidate_interface>
                    if attributes.value(
                            'bsr_rp_candidate_interface') and self.ip == 'ip':
                        # ip pim rp-candidate {bsr_rp_candidate_interface}
                        bsr_rp_str = ' rp-candidate '\
                                  '{bsr_rp_candidate_interface}'

                        # + group-list {bsr_rp_candidate_group_list}
                        if attributes.value('bsr_rp_candidate_group_list'):
                            bsr_rp_str += ' group-list'\
                                           ' {bsr_rp_candidate_group_list}'

                        # +interval <bsr_rp_candidate_interval>
                        if attributes.value('bsr_rp_candidate_interval'):
                            bsr_rp_str += ' interval {bsr_rp_candidate_interval}'

                        # +priority <bsr_rp_candidate_priority>
                        if attributes.value('bsr_rp_candidate_priority'):
                            bsr_rp_str += ' priority '\
                                       '{bsr_rp_candidate_priority}'

                        # +bidir
                        if attributes.value('bsr_rp_candidate_bidir'):
                            if unconfig and attributes.value('enabled_bidir'):
                                skip_unconfig = True
                            else:
                                bsr_rp_str += ' bidir'
                                skip_unconfig = False

                        if not skip_unconfig:
                            configurations.append_line(
                                attributes.format(base_cfg + bsr_rp_str))

                    elif attributes.value(
                            'bsr_rp_candidate_address') and self.ip == 'ipv6':
                        # ipv6 pim [ vrf <vrf_name> ]  bsr candidate rp <bsr_rp_candidate_address>
                        bsr_rp_str = ' bsr candidate rp '\
                                  '{bsr_rp_candidate_address}'

                        # + group-list {bsr_rp_candidate_group_list}
                        if attributes.value('bsr_rp_candidate_group_list'):
                            bsr_rp_str += ' group-list'\
                                           ' {bsr_rp_candidate_group_list}'

                        # +interval <bsr_rp_candidate_interval>
                        if attributes.value('bsr_rp_candidate_interval'):
                            bsr_rp_str += ' interval {bsr_rp_candidate_interval}'

                        # +priority <bsr_rp_candidate_priority>
                        if attributes.value('bsr_rp_candidate_priority'):
                            bsr_rp_str += ' priority '\
                                       '{bsr_rp_candidate_priority}'

                        # +bidir
                        if attributes.value('bsr_rp_candidate_bidir'):
                            if unconfig and attributes.value('enabled_bidir'):
                                skip_unconfig = True
                            else:
                                bsr_rp_str += ' bidir'
                                skip_unconfig = False

                        if not skip_unconfig:
                            configurations.append_line(
                                attributes.format(base_cfg + bsr_rp_str))

                    # ip/ipv6 pim register-policy list <accept_register>
                    if attributes.value('accept_register'):
                        if self.ip == 'ip':
                            configurations.append_line(
                                attributes.format(
                                    'ip pim accept-register list '
                                    '{accept_register}',
                                    force=True))
                        else:
                            configurations.append_line(
                                attributes.format(base_cfg +
                                                  ' accept-register list '
                                                  '{accept_register}',
                                                  force=True))

                    # ip pim log-neighbor-changes
                    if attributes.value(
                            'log_neighbor_changes') and self.ip == 'ip':
                        configurations.append_line(
                            attributes.format('ip pim log-neighbor-changes'))

                    # ip/ipv6 pim [vrf <vrf_name>] register-source <register_source>
                    if attributes.value('register_source'):
                        configurations.append_line(
                            attributes.format(
                                base_cfg +
                                ' register-source {register_source}'))

                    # ip pim [ vrf <vrf_name> ] sparse sg-expiry-timer <sg_expiry_timer>
                    if attributes.value('sg_expiry_timer') and self.ip == 'ip':
                        sg_cfg = ' sparse sg-expiry-timer {sg_expiry_timer}'

                        if attributes.value('sg_expiry_timer_sg_list'):
                            sg_cfg += ' sg-list {sg_expiry_timer_sg_list}'
                        configurations.append_line(
                            attributes.format(base_cfg + sg_cfg))

                    # ip/ipv6 pim spt-threshold infinity group-list
                    #   <spt_switch_policy>
                    if attributes.value('spt_switch_infinity') and \
                       attributes.value('spt_switch_policy'):
                        configurations.append_line(
                            attributes.format(
                                base_cfg +
                                ' spt-threshold {spt_switch_infinity.value} '
                                'group-list {spt_switch_policy}'))
                    elif attributes.value('spt_switch_infinity') and \
                       not attributes.value('spt_switch_policy'):
                        configurations.append_line(
                            attributes.format(
                                base_cfg +
                                ' spt-threshold {spt_switch_infinity.value}'))

                    # Static RP address Attributes under top level config
                    for groups, attributes2 in attributes.sequence_values(
                            'rp_addresses', sort=True):
                        kwargs = {
                            'ip_type': self.ip,
                            'vrf': self.vrf_name,
                            'bidir': attributes.value('enabled_bidir')
                        }
                        if unconfig:
                            configurations.append_block(
                                groups.build_unconfig(apply=False,
                                                      attributes=attributes2,
                                                      **kwargs))
                        else:
                            configurations.append_block(
                                groups.build_config(apply=False,
                                                    attributes=attributes2,
                                                    **kwargs))

                    # InterfaceAttributes
                    for sub, attributes2 in attributes.mapping_values(
                            'interface_attr', keys=self.interface_attr,
                            sort=True):
                        configurations.append_block(
                            sub.build_config(apply=False,
                                             attributes=attributes2,
                                             unconfig=unconfig))

                    return str(configurations)
コード例 #23
0
                def build_config(self,
                                 apply=True,
                                 attributes=None,
                                 unconfig=False,
                                 **kwargs):
                    assert not apply
                    attributes = AttributesHelper(self, attributes)
                    configurations = CliConfigBuilder(unconfig=unconfig)

                    if attributes.value(
                            'address_family') is AddressFamily.ipv6_unicast:

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

                            # router ospfv3 1
                            #   address-family ipv6 unicast
                            #     default-information originate [ always ] [ route-map map-name ]
                            if attributes.value('default_originate'):
                                cfg_str = 'default-information originate {default_originate}'

                                if attributes.value(
                                        'default_originate_always'):
                                    cfg_str += ' always'
                                if attributes.value(
                                        'default_originate_routemap'):
                                    cfg_str += ' route-map {default_originate_routemap}'

                                configurations.append_line(
                                    attributes.format(cfg_str))

                            # router ospfv3 1
                            #   address-family ipv6 unicast
                            #     default-metric <>
                            if attributes.value('default_metric'):
                                configurations.append_line(
                                    attributes.format(
                                        'default-metric {default_metric}'))

                            #   redistribute bgp 100 route-map <str>
                            if attributes.value('redist_bgp_id') and \
                                    attributes.value('redist_bgp_route_map'):
                                configurations.append_line(
                                    attributes.format(
                                        'redistribute bgp {redist_bgp_id} route-map {redist_bgp_route_map}'
                                    ))

                            #   redistribute direct route-map <str>
                            if attributes.value('redist_direct') and \
                                    attributes.value('redist_direct_route_map'):
                                configurations.append_line(
                                    attributes.format(
                                        'redistribute direct route-map {redist_direct_route_map}'
                                    ))

                            #   redistribute static route-map <str>
                            if attributes.value('redist_static') and \
                                    attributes.value('redist_static_route_map'):
                                configurations.append_line(
                                    attributes.format(
                                        'redistribute static route-map {redist_static_route_map}'
                                    ))

                            #   redistribute isis ABC route-map <str>
                            if attributes.value('redist_isis_id') and \
                                    attributes.value('redist_isis_route_map'):
                                configurations.append_line(
                                    attributes.format(
                                        'redistribute isis {redist_isis_id} route-map {redist_isis_route_map}'
                                    ))

                            #   redistribute rip ABC route-map <str>
                            if attributes.value('redist_rip_id') and \
                                    attributes.value('redist_rip_route_map'):
                                configurations.append_line(
                                    attributes.format(
                                        'redistribute rip {redist_rip_id} route-map {redist_rip_route_map}'
                                    ))

                            # router ospfv3 1
                            #   address-family ipv6 unicast
                            #     redistribute maximum-prefix <> [ threshold ] [ warning-only | withdraw [ num-retries timeout ]]--
                            if attributes.value('redist_max_prefix'):
                                cfg_str = 'redistribute maximum-prefix {redist_max_prefix}'

                                if attributes.value('redist_max_prefix_thld'):
                                    cfg_str += ' {redist_max_prefix_thld}'

                                if attributes.value(
                                        'redist_max_prefix_warn_only'):
                                    cfg_str += ' warning-only'
                                elif attributes.value(
                                        'redist_max_prefix_withdraw'):
                                    cfg_str += ' withdraw'
                                    if attributes.value('redist_max_prefix_retries') and \
                                            attributes.value('redist_max_prefix_retries_timeout'):
                                        cfg_str += ' {redist_max_prefix_retries} {redist_max_prefix_retries_timeout}'

                                configurations.append_line(
                                    attributes.format(cfg_str))

                            # router ospfv3 1
                            #   address-family ipv6 unicast
                            #     table-map <>
                            if attributes.value('table_map'):
                                configurations.append_line(
                                    attributes.format('table-map {table_map}'))

                            # timers throttle spf start-time hold-interval max-time
                            if attributes.value('spf_start_time') and \
                                attributes.value('spf_hold_time') and \
                                    attributes.value('spf_max_time'):
                                configurations.append_line(
                                    attributes.format(
                                        'timers throttle lsa {spf_start_time} {spf_hold_time} {spf_max_time}'
                                    ))

                            # Area default cost attributes config
                            for areacost_key, attributes2 in attributes.sequence_values(
                                    'areacost_keys', sort=True):
                                if unconfig:
                                    configurations.append_block(
                                        areacost_key.build_unconfig(
                                            apply=False,
                                            attributes=attributes2,
                                            **kwargs))
                                else:
                                    configurations.append_block(
                                        areacost_key.build_config(
                                            apply=False,
                                            attributes=attributes2,
                                            **kwargs))

                            # Area route map attributes config
                            for arearoutemap_key, attributes2 in attributes.sequence_values(
                                    'arearoutemap_keys', sort=True):
                                if unconfig:
                                    configurations.append_block(
                                        arearoutemap_key.build_unconfig(
                                            apply=False,
                                            attributes=attributes2,
                                            **kwargs))
                                else:
                                    configurations.append_block(
                                        arearoutemap_key.build_config(
                                            apply=False,
                                            attributes=attributes2,
                                            **kwargs))

                            # SummaryAddress attributes config
                            for sumadd_key, attributes2 in attributes.sequence_values(
                                    'sumadd_keys', sort=True):
                                if unconfig:
                                    configurations.append_block(
                                        sumadd_key.build_unconfig(
                                            apply=False,
                                            attributes=attributes2,
                                            **kwargs))
                                else:
                                    configurations.append_block(
                                        sumadd_key.build_config(
                                            apply=False,
                                            attributes=attributes2,
                                            **kwargs))

                            # AreaRange attributes config
                            for arearange_key, attributes2 in attributes.sequence_values(
                                    'arearange_keys', sort=True):
                                if unconfig:
                                    configurations.append_block(
                                        arearange_key.build_unconfig(
                                            apply=False,
                                            attributes=attributes2,
                                            **kwargs))
                                else:
                                    configurations.append_block(
                                        arearange_key.build_config(
                                            apply=False,
                                            attributes=attributes2,
                                            **kwargs))

                    return str(configurations)
コード例 #24
0
ファイル: xconnect.py プロジェクト: wilbeacham85/genielibs
        def build_config(self,
                         apply=True,
                         attributes=None,
                         unconfig=False,
                         contained=False,
                         **kwargs):
            assert not kwargs, kwargs
            attributes = AttributesHelper(self, attributes)
            configurations = CliConfigBuilder(unconfig=unconfig)

            # iosxr: l2vpn (config-l2vpn)
            submode_stack = contextlib.ExitStack()
            if not contained:
                submode_stack.enter_context(
                    configurations.submode_context('l2vpn'))

            # iosxr: l2vpn / xconnect group someword (config-l2vpn)
            with configurations.submode_context(
                    attributes.format('xconnect group {group_name}',
                                      force=True,
                                      cancel_empty=True)):

                if self.xconnect_type is _Xconnect.Type.mp2mp:
                    # iosxr: l2vpn / xconnect group someword / mp2mp someword2 (config-l2vpn)
                    with configurations.submode_context(
                            attributes.format('mp2mp {name}', force=True)):
                        if unconfig and attributes.iswildcard:
                            configurations.submode_unconfig()

                        # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / control-word disable
                        # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / interworking ethernet
                        # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / l2-encapsulation ethernet
                        # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / l2-encapsulation vlan
                        # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / mtu 64
                        # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / shutdown
                        # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / vpn-id 1
                        configurations.append_line(
                            attributes.format('vpn-id {vpn_id}'))

                        # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / autodiscovery bgp (config-l2vpn)
                        ns, attributes2 = attributes.namespace(
                            'autodiscovery_bgp')
                        if ns:
                            configurations.append_block(
                                ns.build_config(apply=False,
                                                unconfig=unconfig,
                                                attributes=attributes2))

                elif self.xconnect_type is _Xconnect.Type.p2p:
                    # iosxr: l2vpn / xconnect group someword / p2p someword2 (config-l2vpn)
                    with configurations.submode_context(
                            attributes.format('p2p {name}', force=True)):
                        if unconfig and attributes.iswildcard:
                            configurations.submode_unconfig()

                        # iosxr: l2vpn / xconnect group someword / p2p someword2 / backup interface Bundle-Ether1

                        # iosxr: l2vpn / xconnect group someword / p2p someword2 / description someword3
                        configurations.append_line(
                            attributes.format('description {description}'))

                        # iosxr: l2vpn / xconnect group someword / p2p someword2 / interface Bundle-Ether1
                        for interface, attributes2 in attributes.sequence_values(
                                'interfaces', sort=True):
                            configurations.append_line('interface {}'.\
                                                  format(interface.name))

                        # iosxr: l2vpn / xconnect group someword / p2p someword2 / interworking ethernet
                        # iosxr: l2vpn / xconnect group someword / p2p someword2 / interworking ipv4
                        configurations.append_line(
                            attributes.format('interworking {interworking}'))

                        # iosxr: l2vpn / xconnect group someword / p2p someword2 / monitor-session someword3

                        # iosxr: l2vpn / xconnect group someword / p2p someword2 / neighbor 1.2.3.4 pw-id 1 (config-l2vpn)
                        # iosxr: l2vpn / xconnect group someword / p2p someword2 / neighbor ipv4 1.2.3.4 pw-id 1 (config-l2vpn)
                        # iosxr: l2vpn / xconnect group someword / p2p someword2 / neighbor ipv6 1:2::3 pw-id 1 (config-l2vpn)
                        for sub, attributes2 in attributes.mapping_values(
                                'neighbor_attr',
                                keys=self.pseudowire_neighbors,
                                sort=True):
                            configurations.append_block(
                                sub.build_config(apply=False,
                                                 attributes=attributes2,
                                                 unconfig=unconfig))

                        # iosxr: l2vpn / xconnect group someword / p2p someword2 / neighbor evpn evi 1 target 1 source 1

                else:
                    warnings.warn(
                        'xconnect type mode {}'.format(self.xconnect_type),
                        UnsupportedAttributeWarning)

            submode_stack.close()
            if apply:
                if configurations:
                    self.device.configure(str(configurations),
                                          fail_invalid=True)
            else:
                return CliConfig(device=self.device,
                                 unconfig=unconfig,
                                 cli_config=configurations,
                                 fail_invalid=True)
コード例 #25
0
        def build_config(self,
                         apply=True,
                         attributes=None,
                         unconfig=False,
                         contained=False,
                         **kwargs):
            assert not kwargs, kwargs
            attributes = AttributesHelper(self, attributes)
            configurations = CliConfigBuilder(unconfig=unconfig)

            # iosxr: l2vpn (config-l2vpn)
            submode_stack = contextlib.ExitStack()
            if not contained:
                submode_stack.enter_context(
                    configurations.submode_context('l2vpn'))

            # iosxr: l2vpn / bridge group someword (config-l2vpn-bg)
            with configurations.submode_context(
                    attributes.format('bridge group {group_name}',
                                      force=True,
                                      cancel_empty=True)):

                # iosxr: l2vpn / bridge group someword / bridge-domain someword2 (config-l2vpn-bg-bd)
                with configurations.submode_context(
                        attributes.format('bridge-domain {name}', force=True)):
                    if unconfig and attributes.iswildcard:
                        configurations.submode_unconfig()

                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / coupled-mode
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / dhcp ipv4 snoop profile someword3
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / dynamic-arp-inspection (config-l2vpn-bg-bd-dai)
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / dynamic-arp-inspection / address-validation (config-l2vpn-bg-bd-dai-av)
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / dynamic-arp-inspection / address-validation / dst-mac
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / dynamic-arp-inspection / address-validation / ipv4
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / dynamic-arp-inspection / address-validation / src-mac
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / dynamic-arp-inspection / logging

                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / evi 1 (config-l2vpn-bg-bd-evi)
                    for sub, attributes2 in attributes.mapping_values(
                            'evi_attr', keys=self.evis, sort=True):
                        configurations.append_block(
                            sub.build_config(apply=False,
                                             attributes=attributes2,
                                             unconfig=unconfig))

                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / flooding disable
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / flooding unknown-unicast disable
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / igmp snooping disable
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / igmp snooping profile someword3

                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / routed interface BVI1
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / interface Bundle-Ether1 (config-l2vpn-bg-bd-ac)
                    for sub, attributes2 in attributes.mapping_values(
                            'interface_attr', keys=self.interfaces, sort=True):
                        configurations.append_block(
                            sub.build_config(apply=False,
                                             attributes=attributes2,
                                             unconfig=unconfig))

                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / ip-source-guard (config-l2vpn-bg-bd-ipsg)
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / ip-source-guard / logging

                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / mac (config-l2vpn-bg-bd-mac)
                    ns, attributes2 = attributes.namespace('mac')
                    if ns is not None:
                        configurations.append_block(
                            ns.build_config(apply=False,
                                            attributes=attributes2,
                                            unconfig=unconfig))

                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / member vni 1 (config-l2vpn-bg-bd-vni)
                    for sub, attributes2 in attributes.mapping_values(
                            'vni_attr', keys=self.vnis, sort=True):
                        configurations.append_block(
                            sub.build_config(apply=False,
                                             attributes=attributes2,
                                             unconfig=unconfig))

                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / mld snooping profile someword3
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / mtu 100

                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / neighbor 1.2.3.4 pw-id 1 (config-l2vpn-bg-bd-pw)
                    for sub, attributes2 in attributes.mapping_values(
                            'neighbor_attr',
                            keys=self.pseudowire_neighbors,
                            sort=True):
                        configurations.append_block(
                            sub.build_config(apply=False,
                                             attributes=attributes2,
                                             unconfig=unconfig))

                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / neighbor evpn evi 1 target 1
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / neighbor evpn evi 1 target 1 source 1

                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / nv satellite (config-l2vpn-bg-bd-nv)
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / nv satellite / offload ipv4 multicast enable

                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb core (config-l2vpn-bg-bd-pbb-core)
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb core / evi 1 (config-l2vpn-bg-bd-pbb-core-evi)
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb core / mac (config-l2vpn-bg-bd-pbb-core-mac)
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb core / mac / aging (config-l2vpn-bg-bd-pbb-core-mac-aging)
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb core / mac / aging / time 300
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb core / mac / aging / type absolute
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb core / mac / aging / type inactivity
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb core / mac / learning
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb core / mac / learning disable
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb core / mmrp-flood-optimization
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb core / rewrite ingress tag push dot1ad 1 symmetric

                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 (config-l2vpn-bg-bd-pbb-edge)
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / dhcp ipv4 none
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / dhcp ipv4 snoop profile someword4
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / igmp snooping profile someword4
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac (config-l2vpn-bg-bd-pbb-edge-mac)
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / aging (config-l2vpn-bg-bd-pbb-edge-mac-aging)
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / aging / time 300
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / aging / type absolute
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / aging / type inactivity
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / learning
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / learning disable
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / limit (config-l2vpn-bg-bd-pbb-edge-mac-limit)
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / limit / action flood
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / limit / action no-flood
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / limit / action none
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / limit / action shutdown
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / limit / maximum 1
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / limit / notification both
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / limit / notification none
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / limit / notification syslog
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / limit / notification trap
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / secure (config-l2vpn-bg-bd-pbb-edge-mac-sec)
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / secure / accept-shutdown
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / secure / action none
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / secure / action restrict
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / secure / action shutdown
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / secure / disable
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / secure / logging
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / mac / secure / logging disable
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / split-horizon group vfi disable
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / static-mac-address aaaa.bbbb.cccc bmac aaaa.bbbb.cccc
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / pbb edge i-sid 256 core-bridge someword3 / unknown-unicast-bmac aaaa.bbbb.cccc

                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / shutdown
                    if attributes.value('shutdown'):
                        configurations.append_line('shutdown')

                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / storm-control broadcast kbps 64
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / storm-control broadcast pps 1
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / storm-control multicast kbps 64
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / storm-control multicast pps 1
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / storm-control unknown-unicast kbps 64
                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / storm-control unknown-unicast pps 1

                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / transport-mode vlan passthrough

                    # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 (config-l2vpn-bg-bd-vfi)
                    for vfi, attributes2 in attributes.sequence_values('vfis'):
                        configurations.append_block(
                            str(
                                vfi.build_config(apply=False,
                                                 attributes=attributes2,
                                                 unconfig=unconfig)))

            submode_stack.close()
            if apply:
                if configurations:
                    self.device.configure(str(configurations),
                                          fail_invalid=True)
            else:
                return CliConfig(device=self.device,
                                 unconfig=unconfig,
                                 cli_config=configurations,
                                 fail_invalid=True)
コード例 #26
0
ファイル: vrf.py プロジェクト: wilbeacham85/genielibs
            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)

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

                    if attributes.value('export_vrf') or attributes.value(
                            'import_vrf'):
                        warnings.warn('vrf export/import vrf',
                                      UnsupportedAttributeWarning)

                    # iosxr: vrf vrf1 / address-family ipv4 unicast / export route-policy <rtepol>
                    configurations.append_line(
                        attributes.format(
                            'export route-policy {export_route_policy}'))

                    # iosxr: vrf vrf1 / address-family ipv4 unicast / export route-target 100:200
                    # iosxr: vrf vrf1 / address-family ipv4 unicast / export route-target 100:20 stitching
                    for v, attributes2 in attributes.sequence_values(
                            'export_route_targets'):
                        cfg = 'export route-target {}'.format(v.route_target)
                        if v.stitching:
                            cfg += ' stitching'
                        configurations.append_line(cfg)

                    # iosxr: vrf vrf1 / address-family ipv4 unicast / export to default-vrf route-policy <rtepol>
                    configurations.append_line(
                        attributes.format(
                            'export to default-vrf route-policy {export_to_default_vrf_route_policy.name}'
                        ))

                    # iosxr: vrf vrf1 / address-family ipv4 unicast / export to vrf allow-imported-vpn
                    # iosxr: vrf vrf1 / address-family ipv4 unicast / export to vrf allow-imported-vpn import stitching-rt
                    # iosxr: vrf vrf1 / address-family ipv4 unicast / export to vrf import stitching-rt
                    if attributes.value('export_to_vrf_allow_imported_vpn') or \
                            attributes.value('export_to_vrf_import_stitching_rt'):
                        cfg = 'export to vrf'
                        if attributes.value('export_to_vrf_allow_imported_vpn',
                                            force=True):
                            cfg += ' allow-imported-vpn'
                        if attributes.value(
                                'export_to_vrf_import_stitching_rt',
                                force=True):
                            cfg += ' import stitching-rt'
                        configurations.append_line(cfg)

                    # iosxr: vrf vrf1 / address-family ipv4 unicast / import from default-vrf route-policy <rtepol>
                    # iosxr: vrf vrf1 / address-family ipv4 unicast / import from default-vrf route-policy <rtepol> advertise-as-vpn
                    v = attributes.value(
                        'import_from_default_vrf_route_policy')
                    if v is not None:
                        cfg = 'import from default-vrf route-policy {}'.format(
                            v)
                        if attributes.value(
                                'import_from_default_vrf_advertise_as_vpn',
                                force=True):
                            cfg += ' advertise-as-vpn'
                        configurations.append_line(cfg)

                    # iosxr: vrf vrf1 / address-family ipv4 unicast / import route-policy <rtepol>
                    configurations.append_line(
                        attributes.format(
                            'import route-policy {import_route_policy}'))

                    # iosxr: vrf vrf1 / address-family ipv4 unicast / import route-target 100:200
                    # iosxr: vrf vrf1 / address-family ipv4 unicast / import route-target 100:20 stitching
                    for v, attributes2 in attributes.sequence_values(
                            'import_route_targets'):
                        cfg = 'import route-target {}'.format(v.route_target)
                        if v.stitching:
                            cfg += ' stitching'
                        configurations.append_line(cfg)

                    # iosxr: vrf vrf1 / address-family ipv4 unicast / maximum prefix 32
                    # iosxr: vrf vrf1 / address-family ipv4 unicast / maximum prefix 32 1
                    cfg = attributes.format('maximum prefix {maximum_prefix}')
                    if cfg:
                        if attributes.value('maximum_prefix_warning_only',
                                            force=True):
                            warnings.warn('vrf maximum prefix warning-only',
                                          UnsupportedAttributeWarning)
                        v = attributes.value('maximum_prefix_threshold',
                                             force=True)
                        if v is not None:
                            cfg += ' {}'.format(v)
                            if attributes.value(
                                    'maximum_prefix_reinstall_threshold',
                                    force=True):
                                warnings.warn(
                                    'vrf maximum prefix reinstall threshold',
                                    UnsupportedAttributeWarning)
                        configurations.append_line(cfg)

                    # loop over all route-target
                    for sub, attributes2 in attributes.mapping_values(
                            'route_target_attr',
                            keys=self.route_target_attr,
                            sort=True):
                        configurations.append_block(
                            sub.build_config(apply=False,
                                             attributes=attributes2,
                                             unconfig=unconfig,
                                             **kwargs))

                return str(configurations)
コード例 #27
0
                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)
                    # assign ip version according to the address_family_attr
                    if hasattr(self, 'address_family'):
                        if 'ipv4' in self.address_family.value:
                            self.ip = 'ip'
                        if 'ipv6' in self.address_family.value:
                            self.ip = 'ipv6'

                    if unconfig:
                        attributes.attributes['ip'] = self.ip

                    with configurations.submode_context(
                            None if self.vrf_name == 'default' else attributes.
                            format('vrf context {vrf_name}', force=True)):
                        # no configuration append if vrf is default
                        if self.vrf_name != 'default' and unconfig and \
                            attributes.iswildcard:
                            configurations.submode_unconfig()

                        # ==== PIM Auto-RP =======
                        if attributes.value('auto_rp') or \
                           attributes.value('send_rp'):

                            # auto-rp rp-candidate | send-rp-announce
                            if attributes.value('auto_rp'):
                                auto_rp_str = 'ip pim auto-rp rp-candidate'
                            elif attributes.value('send_rp'):
                                auto_rp_str = 'ip pim send-rp-announce'

                            # + {send_rp_announce_rp_group} |
                            # + {send_rp_announce_intf}
                            if attributes.value('send_rp_announce_rp_group'):
                                auto_rp_str += ' {send_rp_announce_rp_group}'
                            elif attributes.value('send_rp_announce_intf'):
                                auto_rp_str += ' {send_rp_announce_intf}'
                            else:
                                auto_rp_str = ''

                            # + group-list {send_rp_announce_group_list} |
                            # + route-map {send_rp_announce_route_map} |
                            # + prefix-list {send_rp_announce_prefix_list}
                            if auto_rp_str:
                                if attributes.value(
                                        'send_rp_announce_group_list'):
                                    auto_rp_str += ' group-list'\
                                                   ' {send_rp_announce_group_list}'
                                elif attributes.value(
                                        'send_rp_announce_route_map'):
                                    auto_rp_str += ' route-map'\
                                                   ' {send_rp_announce_route_map}'
                                elif attributes.value(
                                        'send_rp_announce_prefix_list'):
                                    auto_rp_str += ' prefix-list'\
                                                   ' {send_rp_announce_prefix_list}'
                                else:
                                    auto_rp_str = ''

                            if auto_rp_str:
                                # + interval {send_rp_announce_interval}
                                if attributes.value(
                                        'send_rp_announce_interval'):
                                    auto_rp_str += ' interval'\
                                                   ' {send_rp_announce_interval}'

                                # + scope {send_rp_announce_scope}
                                if attributes.value('send_rp_announce_scope'):
                                    auto_rp_str += ' scope {send_rp_announce_scope}'

                                # + bidir
                                if attributes.value('send_rp_announce_bidir'):
                                    auto_rp_str += ' bidir'

                            configurations.append_line(
                                attributes.format(auto_rp_str))

                        # === PIM Send-RP-Discovery ===
                        # ip pim auto-rp mapping-agent|send-rp-discovery
                        #  <send_rp_discovery_intf>
                        #  [scope ,send_rp_discovery_scope>]
                        if attributes.value('auto_rp_discovery') or \
                           attributes.value('send_rp_discovery'):

                            # set auto-rp method
                            if attributes.value('auto_rp_discovery'):
                                pre_str = 'ip pim auto-rp mapping-agent'
                            if attributes.value('send_rp_discovery'):
                                pre_str = 'ip pim send-rp-discovery'

                            #  <send_rp_discovery_intf>
                            #  [scope ,send_rp_discovery_scope>]
                            if attributes.value('send_rp_discovery_intf') and \
                               attributes.value('send_rp_discovery_scope'):
                                pre_str +=' {send_rp_discovery_intf}'\
                                          ' scope {send_rp_discovery_scope}'

                            elif attributes.value('send_rp_discovery_intf') and \
                               not attributes.value('send_rp_discovery_scope'):
                                pre_str += ' {send_rp_discovery_intf}'

                            configurations.append_line(
                                attributes.format(pre_str))
                            # initial it back
                            pre_str = ''

                        # ip pim auto-rp forward listen
                        if attributes.value('autorp_listener'):
                            configurations.append_line(
                                attributes.format(
                                    'ip pim auto-rp forward listen'))

                        # ==== PIM BSR =======
                        # == bsr bsr-candidate ==
                        # ip/ipv6 pim auto-rp forward listen
                        # ip/ipv6 pim [bsr] bsr-candidate <bsr_candidate_interface>
                        if attributes.value('bsr_candidate_interface'):
                            # ip/ipv6 pim bsr forward listen
                            configurations.append_line(
                                attributes.format(
                                    '{ip} pim bsr forward listen'))

                            # ip/ipv6 pim bsr-candidate {bsr_candidate_interface}
                            bsr_str = '{ip} pim bsr-candidate '\
                                      '{bsr_candidate_interface}'

                            # + hash-len <bsr_candidate_hash_mask_length>
                            if attributes.value(
                                    'bsr_candidate_hash_mask_length'):
                                bsr_str += ' hash-len '\
                                           '{bsr_candidate_hash_mask_length}'

                            # + interval <bsr_candidate_interval>
                            if attributes.value('bsr_candidate_interval'):
                                bsr_str += ' interval {bsr_candidate_interval}'

                            # + priority <bsr_candidate_priority>
                            if attributes.value('bsr_candidate_priority'):
                                bsr_str += ' priority {bsr_candidate_priority}'

                            configurations.append_line(
                                attributes.format(bsr_str))

                        # == bsr rp-candidate ==
                        # ip/ipv6 pim auto-rp forward listen
                        # ip/ipv6 pim [bsr] rp-candidate <bsr_rp_candidate_interface>
                        if attributes.value('bsr_rp_candidate_interface'):
                            # ip/ipv6 pim bsr forward listen
                            configurations.append_line(
                                attributes.format(
                                    '{ip} pim bsr forward listen'))

                            # ip/ipv6 pim rp-candidate {bsr_rp_candidate_interface}
                            bsr_rp_str = '{ip} pim rp-candidate '\
                                      '{bsr_rp_candidate_interface}'

                            # + group-list {bsr_rp_candidate_group_list} |
                            # + route-map {bsr_rp_candidate_route_map} |
                            # + prefix-list {bsr_rp_candidate_prefix_list}
                            if attributes.value('bsr_rp_candidate_group_list'):
                                bsr_rp_str += ' group-list'\
                                               ' {bsr_rp_candidate_group_list}'
                            elif attributes.value(
                                    'bsr_rp_candidate_route_map'):
                                bsr_rp_str += ' route-map'\
                                               ' {bsr_rp_candidate_route_map}'
                            elif attributes.value(
                                    'bsr_rp_candidate_prefix_list'):
                                bsr_rp_str += ' prefix-list'\
                                               ' {bsr_rp_candidate_prefix_list}'
                            else:
                                bsr_rp_str = ''

                            if bsr_rp_str:
                                # +priority <bsr_rp_candidate_priority>
                                if attributes.value(
                                        'bsr_rp_candidate_priority'):
                                    bsr_rp_str += ' priority '\
                                               '{bsr_rp_candidate_priority}'

                                # +interval <bsr_rp_candidate_interval>
                                if attributes.value(
                                        'bsr_rp_candidate_interval'):
                                    bsr_rp_str += ' interval {bsr_rp_candidate_interval}'

                                # +bidir
                                if attributes.value('bsr_rp_candidate_bidir'):
                                    bsr_rp_str += ' bidir'

                            configurations.append_line(
                                attributes.format(bsr_rp_str))

                        # ip/ipv6 pim register-policy <accept_register>
                        if attributes.value('accept_register'):
                            configurations.append_line(
                                attributes.format('{ip} pim register-policy '
                                                  '{accept_register}'))

                        # ip pim register-policy prefix-list
                        #   <accept_register_prefix_list>
                        if attributes.value('accept_register_prefix_list') \
                           and self.ip == 'ip':
                            configurations.append_line(
                                attributes.format(
                                    'ip pim register-policy prefix-list '
                                    '{accept_register_prefix_list}'))

                        # ip/ipv6 pim log-neighbor-changes
                        if attributes.value('log_neighbor_changes'):
                            configurations.append_line(
                                attributes.format(
                                    '{ip} pim log-neighbor-changes'))

                        # ip pim register-source <register_source>
                        if attributes.value('register_source') and \
                           self.ip == 'ip':
                            configurations.append_line(
                                attributes.format(
                                    'ip pim register-source {register_source}')
                            )

                        # ip pim sg-expiry-timer infinity
                        if attributes.value('sg_expiry_timer_infinity') and \
                           not attributes.value('sg_expiry_timer_prefix_list') \
                           and not attributes.value('sg_expiry_timer_sg_list'):
                            configurations.append_line(
                                attributes.format(
                                    'ip pim sg-expiry-timer infinity'))

                        # ip pim sg-expiry-timer <sg_expiry_timer>
                        if attributes.value('sg_expiry_timer') and \
                           not attributes.value('sg_expiry_timer_prefix_list') \
                           and not attributes.value('sg_expiry_timer_sg_list'):
                            configurations.append_line(
                                attributes.format(
                                    'ip pim sg-expiry-timer {sg_expiry_timer}')
                            )

                        # ip pim sg-expiry-timer <sg_expiry_timer>
                        #   prefix-list <sg_expiry_timer_prefix_list>
                        if attributes.value('sg_expiry_timer') and \
                           attributes.value('sg_expiry_timer_prefix_list'):
                            configurations.append_line(
                                attributes.format(
                                    'ip pim sg-expiry-timer {sg_expiry_timer} '
                                    'prefix-list {sg_expiry_timer_prefix_list}'
                                ))

                        # ip pim sg-expiry-timer <sg_expiry_timer>
                        #   sg-list <sg_expiry_timer_sg_list>
                        if attributes.value('sg_expiry_timer') and \
                           attributes.value('sg_expiry_timer_sg_list'):
                            configurations.append_line(
                                attributes.format(
                                    'ip pim sg-expiry-timer {sg_expiry_timer} '
                                    'sg-list {sg_expiry_timer_sg_list}'))

                        # ip pim sg-expiry-timer infinity
                        #   prefix-list <sg_expiry_timer_prefix_list>
                        if attributes.value('sg_expiry_timer_infinity') and \
                           attributes.value('sg_expiry_timer_prefix_list'):
                            configurations.append_line(
                                attributes.format(
                                    'ip pim sg-expiry-timer infinity '
                                    'prefix-list {sg_expiry_timer_prefix_list}'
                                ))

                        # ip pim sg-expiry-timer infinity
                        #   sg-list <sg_expiry_timer_sg_list>
                        if attributes.value('sg_expiry_timer_infinity') and \
                           attributes.value('sg_expiry_timer_sg_list'):
                            configurations.append_line(
                                attributes.format(
                                    'ip pim sg-expiry-timer infinity '
                                    'sg-list {sg_expiry_timer_sg_list}'))

                        # ip/ipv6 pim spt-threshold infinity group-list
                        #   <spt_switch_policy>
                        if attributes.value('spt_switch_infinity') and \
                           attributes.value('spt_switch_policy'):
                            configurations.append_line(
                                attributes.format(
                                    '{ip} pim spt-threshold {spt_switch_infinity.value} '
                                    'group-list {spt_switch_policy}'))

                        # ip/ipv6 pim use-shared-tree-only group-list <spt_switch_policy>
                        if not attributes.value('spt_switch_infinity') and \
                           attributes.value('spt_switch_policy'):
                            configurations.append_line(
                                attributes.format(
                                    '{ip} pim use-shared-tree-only group-list'
                                    ' {spt_switch_policy}'))

                        # Static RP address Attributes under top level config
                        for groups, attributes2 in attributes.sequence_values(
                                'rp_addresses', sort=True):
                            kwargs = {'ip_type': self.ip}
                            if unconfig:
                                configurations.append_block(
                                    groups.build_unconfig(
                                        apply=False,
                                        attributes=attributes2,
                                        **kwargs))
                            else:
                                configurations.append_block(
                                    groups.build_config(apply=False,
                                                        attributes=attributes2,
                                                        **kwargs))

                    # InterfaceAttributes
                    for sub, attributes2 in attributes.mapping_values(
                            'interface_attr', keys=self.interface_attr,
                            sort=True):
                        configurations.append_block(
                            sub.build_config(apply=False,
                                             attributes=attributes2,
                                             unconfig=unconfig))

                    return str(configurations)
コード例 #28
0
ファイル: evi.py プロジェクト: wilbeacham85/genielibs
        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)

            # iosxr: evpn / evi 1 / bgp (config-evpn-evi-bgp)
            if attributes.value('enabled', force=True):
                with configurations.submode_context('bgp'):
                    if unconfig and attributes.iswildcard:
                        configurations.submode_unconfig()

                    # iosxr: evpn / evi 1 / bgp / rd 100:200000
                    # iosxr: evpn / evi 1 / bgp / rd 65536:200
                    # iosxr: evpn / evi 1 / bgp / rd 1.2.3.4:1
                    configurations.append_line(attributes.format('rd {rd}'))

                    # iosxr: evpn / evi 1 / bgp / route-target 100:200000
                    # iosxr: evpn / evi 1 / bgp / route-target 100:200000 stitching
                    # iosxr: evpn / evi 1 / bgp / route-target 65536:200
                    # iosxr: evpn / evi 1 / bgp / route-target 65536:200 stitching
                    # iosxr: evpn / evi 1 / bgp / route-target 1.2.3.4:1
                    # iosxr: evpn / evi 1 / bgp / route-target 1.2.3.4:1 stitching
                    both_route_targets = set(self.export_route_targets) & set(
                        self.import_route_targets)

                    # iosxr: evpn / evi 1 / bgp / route-target export 100:200000
                    # iosxr: evpn / evi 1 / bgp / route-target export 100:200000 stitching
                    # iosxr: evpn / evi 1 / bgp / route-target export 65536:200
                    # iosxr: evpn / evi 1 / bgp / route-target export 65536:200 stitching
                    # iosxr: evpn / evi 1 / bgp / route-target export 1.2.3.4:1
                    # iosxr: evpn / evi 1 / bgp / route-target export 1.2.3.4:1 stitching
                    for v, attributes2 in attributes.sequence_values(
                            'export_route_targets', sort=True):
                        if v in both_route_targets:
                            cfg = 'route-target {}'.format(v.route_target)
                        else:
                            cfg = 'route-target export {}'.format(
                                v.route_target)
                        if v.stitching:
                            cfg += ' stitching'
                        configurations.append_line(cfg)

                    # iosxr: evpn / evi 1 / bgp / route-target import 100:200000
                    # iosxr: evpn / evi 1 / bgp / route-target import 100:200000 stitching
                    # iosxr: evpn / evi 1 / bgp / route-target import 65536:200
                    # iosxr: evpn / evi 1 / bgp / route-target import 65536:200 stitching
                    # iosxr: evpn / evi 1 / bgp / route-target import 1.2.3.4:1
                    # iosxr: evpn / evi 1 / bgp / route-target import 1.2.3.4:1 stitching
                    for v, attributes2 in attributes.sequence_values(
                            'import_route_targets', sort=True):
                        if v in both_route_targets:
                            continue  # Already done above
                        cfg = 'route-target import {}'.format(v.route_target)
                        if v.stitching:
                            cfg += ' stitching'
                        configurations.append_line(cfg)

                    # iosxr: evpn / evi 1 / bgp / route-target export none
                    if attributes.value('export_route_target_none'):
                        if attributes.value('import_route_target_none',
                                            force=True):
                            configurations.append_line('route-target none')
                        else:
                            configurations.append_line(
                                'route-target export none')

                    # iosxr: evpn / evi 1 / bgp / route-target import none
                    if attributes.value('import_route_target_none'):
                        if attributes.value('export_route_target_none',
                                            force=True):
                            pass  # Already done above
                        else:
                            configurations.append_line(
                                'route-target import none')

                    # iosxr: evpn / evi 1 / bgp / table-policy <rtepol>

            return str(configurations)
コード例 #29
0
ファイル: xconnect.py プロジェクト: wilbeacham85/genielibs
            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)

                # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / autodiscovery bgp (config-l2vpn)
                with configurations.submode_context('autodiscovery bgp'):
                    if not attributes.value('enabled', force=True):
                        configurations.submode_cancel()

                    # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / autodiscovery bgp / rd 100000:200
                    # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / autodiscovery bgp / rd 100:200000
                    # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / autodiscovery bgp / rd 1.2.3.4:1
                    # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / autodiscovery bgp / rd auto
                    configurations.append_line(attributes.format('rd {rd}'))

                    # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / autodiscovery bgp / route-policy export <rtepol>

                    # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / autodiscovery bgp / route-target 100000:200
                    # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / autodiscovery bgp / route-target 100:200000
                    # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / autodiscovery bgp / route-target 1.2.3.4:1
                    # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / autodiscovery bgp / route-target export 100000:200
                    # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / autodiscovery bgp / route-target export 100:200000
                    # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / autodiscovery bgp / route-target export 1.2.3.4:1
                    # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / autodiscovery bgp / route-target export import 100000:200 (bug)
                    # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / autodiscovery bgp / route-target export import 100:200000 (bug)
                    # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / autodiscovery bgp / route-target export import 1.2.3.4:1 (bug)
                    both_route_targets = set(self.export_route_targets) & set(
                        self.import_route_targets)
                    for v, attributes2 in attributes.sequence_values(
                            'export_route_targets', sort=True):
                        if v in both_route_targets:
                            cfg = 'route-target {}'.format(v.route_target)
                        else:
                            cfg = 'route-target export {}'.format(
                                v.route_target)
                        if v.stitching:
                            warnings.warn(
                                UnsupportedAttributeWarning,
                                'route-target export/import stitching')
                        configurations.append_line(cfg)

                    # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / autodiscovery bgp / route-target import 100000:200
                    # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / autodiscovery bgp / route-target import 100:200000
                    # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / autodiscovery bgp / route-target import 1.2.3.4:1
                    for v, attributes2 in attributes.sequence_values(
                            'import_route_targets', sort=True):
                        if v not in both_route_targets:
                            cfg = 'route-target import {}'.format(
                                v.route_target)
                            if v.stitching:
                                warnings.warn(
                                    UnsupportedAttributeWarning,
                                    'route-target export/import stitching')
                            configurations.append_line(cfg)

                    # iosxr: l2vpn / xconnect group someword / mp2mp someword2 / autodiscovery bgp / signaling-protocol bgp (config-l2vpn)
                    ns, attributes2 = attributes.namespace(
                        'signaling_protocol_bgp')
                    if ns:
                        configurations.append_block(
                            ns.build_config(apply=False,
                                            unconfig=unconfig,
                                            attributes=attributes2))

                return str(configurations)
コード例 #30
0
ファイル: mcast.py プロジェクト: wilbeacham85/genielibs
                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)

                    # # Set decider key af_name from user set address family
                    # self.af_name = self.address_family.value

                    with configurations.submode_context(
                            attributes.format(
                                'address-family {address_family.name}',
                                force=True)):

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

                        # ======
                        # enable
                        # ======
                        if attributes.value('enable'):
                            configurations.append_line(
                                attributes.format('interface all enable'))

                        # =========
                        # multipath
                        # =========
                        if attributes.value('multipath'):
                            configurations.append_line(
                                attributes.format('multipath'))

                        # Mroute attributes configs
                        for mroute, attributes2 in attributes.sequence_values(
                                'mroutes', sort=True):
                            if unconfig:
                                configurations.append_block(
                                    mroute.build_unconfig(
                                        apply=False,
                                        attributes=attributes2,
                                        **kwargs))
                            else:
                                configurations.append_block(
                                    mroute.build_config(apply=False,
                                                        attributes=attributes2,
                                                        **kwargs))

                        # InterfaceAttribute
                        for sub, attributes2 in attributes.mapping_values(
                                'interface_attr',
                                sort=True,
                                keys=self.interface_attr):
                            configurations.append_block(
                                sub.build_config(apply=False,
                                                 attributes=attributes2,
                                                 unconfig=unconfig))

                    return str(configurations)