Пример #1
0
    def test_cfg_without_igmp(self):
        Genie.testbed = testbed = Testbed()
        dev1 = Device(testbed=testbed, name='PE1', os='nxos')

        with self.assertNoWarnings():
            Genie.testbed = None
            with self.assertRaises(TypeError):
                vlan = Vlan()
            Genie.testbed = testbed

            vlan = Vlan(vlan='102')
            vlan.device_attr[dev1].vlan_attr['102'].name = 'vlan2'
            vlan.device_attr[dev1].vlan_attr['102'].state = 'active'
            vlan.device_attr[dev1].vlan_attr['102'].mode = 'ce'

            vlan.device_attr[dev1].config_vlan_attr['102'].config_vlan_id = '102'

            self.assertIs(vlan.testbed, testbed)

            dev1.add_feature(vlan)

            cfgs = vlan.build_config(apply=False)
            self.assertCountEqual(cfgs.keys(), [dev1.name])
            self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.join([
                'vlan 102',
                ' name vlan2',
                ' state active',
                ' mode ce',
                ' exit',
                'vlan configuration 102',
                ' exit',
            ]))
Пример #2
0
    def test_new_vlan_cfg(self):
        Genie.testbed = testbed = Testbed()
        dev1 = Device(testbed=testbed, name='PE1', os='iosxe')

        with self.assertNoWarnings():
            Genie.testbed = None
            with self.assertRaises(TypeError):
                vlan = Vlan()
            Genie.testbed = testbed

            vlan = Vlan(vlan='100')
            vlan.device_attr[dev1].vlan_attr['100'].name = 'new_vlan'
            vlan.device_attr[dev1].vlan_attr['100'].state = 'active'

            self.assertIs(vlan.testbed, testbed)

            dev1.add_feature(vlan)

            cfgs = vlan.build_config(apply=False)
            self.assertCountEqual(cfgs.keys(), [dev1.name])
            self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.join([
                'vlan 100',
                ' name new_vlan',
                ' state active',
                ' exit',
            ]))
Пример #3
0
    def test_vlan_interface_configuration(self):
        testbed = Genie.testbed = Testbed()
        dev1 = Device(testbed=testbed, name='PE1', os='iosxr')
        dev2 = Device(testbed=testbed, name='PE2', os='iosxr')
        intf1 = Interface(name='GigabitEthernet0/0/1', device=dev1)
        intf2 = Interface(name='GigabitEthernet0/0/2', device=dev2)
        intf3 = Interface(name='GigabitEthernet0/0/3', device=dev1)
        link = Link(name='1_2_1', testbed=testbed)
        link.connect_interface(interface=intf1)
        link.connect_interface(interface=intf2)
        vlan = Vlan()
        link.add_feature(vlan)

        vlan.device_attr[dev1]
        vlan.device_attr[dev2]
        vlan.device_attr[dev1].interface_attr[intf1]
        vlan.device_attr[dev1].interface_attr[intf1].eth_encap_type1 = 'dot1q'
        vlan.device_attr[dev1].interface_attr[intf1].eth_encap_val1 = 2
        vlan.device_attr[dev1].interface_attr[
            intf1].eth_encap_type2 = 'second-dot1q'
        vlan.device_attr[dev1].interface_attr[intf1].eth_encap_val2 = 5

        cfg1 = vlan.build_config(apply=False)
        self.assertCountEqual(cfg1.keys(), ['PE1', 'PE2'])

        self.assertMultiLineEqual(
            str(cfg1['PE1']), '\n'.join([
                'interface GigabitEthernet0/0/1',
                ' encapsulation dot1q 2 second-dot1q 5',
                ' exit',
            ]))
Пример #4
0
    def test_basic_cfg(self):
        testbed = Genie.testbed = Testbed()
        dev1 = Device(testbed=testbed, name='PE1', os='iosxe', context='yang')
        dev2 = Device(testbed=testbed, name='PE2', os='iosxe', context='yang')
        intf1 = Interface(name='GigabitEthernet0/0/1', device=dev1)
        intf2 = Interface(name='GigabitEthernet0/0/2', device=dev2)
        intf3 = Interface(name='Vlan100', device=dev1)
        link = Link(name='1_2_1', testbed=testbed)
        link.connect_interface(interface=intf1)
        link.connect_interface(interface=intf2)
        vlan = Vlan()

        for dev in testbed.devices:
            dev.connections = Mock()
            dev.connections = {'netconf': NetconfConnectionInfo()}

        link.add_feature(vlan)
        vlan.vlan_id = 100

        cfg1 = vlan.build_config(apply=False)
        self.assertCountEqual(cfg1.keys(), ['PE1', 'PE2'])
        compare = ""
        for i in cfg1['PE1']:
            compare += str(i)

        self.assertMultiLineEqual(
            compare, '\n'.join([
                '<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">\n'
                '  <target>\n'
                '    <running></running>\n'
                '  </target>\n'
                '  <config>\n'
                '    <vlan xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">\n'
                '      <vlan-list xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-vlan">\n'
                '        <id>100</id>\n'
                '      </vlan-list>\n'
                '    </vlan>\n'
                '  </config>\n'
                '</edit-config>\n'
            ]))

        compare = ""
        for i in cfg1['PE2']:
            compare += str(i)

        self.assertMultiLineEqual(
            compare, '\n'.join([
                '<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">\n'
                '  <target>\n'
                '    <running></running>\n'
                '  </target>\n'
                '  <config>\n'
                '    <vlan xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">\n'
                '      <vlan-list xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-vlan">\n'
                '        <id>100</id>\n'
                '      </vlan-list>\n'
                '    </vlan>\n'
                '  </config>\n'
                '</edit-config>\n'
            ]))
Пример #5
0
def vlans_configure(netbox_vlans):
    results = []
    for vlan in netbox_vlans:
        print(f"Creating {vlan.display_name}")
        new_vlan = Vlan(vlan_id=str(vlan.vid), name=vlan.name)
        device.add_feature(new_vlan)
        output = new_vlan.build_config()
        results.append({vlan.name: output})

    # output = testbed.build_config()
    # return output

    return results
Пример #6
0
    def test_new_vlan_unshut(self):
        Genie.testbed = testbed = Testbed()
        dev1 = Device(testbed=testbed, name='PE1', os='iosxe')
        with self.assertNoWarnings():
            vlan = Vlan(vlan='100')
            vlan.device_attr[dev1].vlan_attr['100']
            vlan.device_attr[dev1].vlan_attr['100'].shutdown = False
            self.assertIs(vlan.testbed, testbed)

            dev1.add_feature(vlan)

            partial_uncfg = vlan.build_config(apply=False)
            self.assertCountEqual(partial_uncfg.keys(), [dev1.name])
            self.assertMultiLineEqual(str(partial_uncfg[dev1.name]), '\n'.join([
                'vlan 100',
                ' no shutdown',
                ' exit',
            ]))
Пример #7
0
    def test_basic_cfg(self):
        testbed = Genie.testbed = Testbed()
        dev1 = Device(testbed=testbed, name='PE1', os='iosxe')
        dev2 = Device(testbed=testbed, name='PE2', os='iosxe')
        intf1 = Interface(name='GigabitEthernet0/0/1',device=dev1)
        intf2 = Interface(name='GigabitEthernet0/0/2',device=dev2)
        intf3 = Interface(name='Vlan100',device=dev1)
        link = Link(name='1_2_1',testbed=testbed)
        link.connect_interface(interface=intf1)
        link.connect_interface(interface=intf2)
        vlan = Vlan()
        link.add_feature(vlan)
        vlan.vlan_id = 100
        access_map_id = 'ed'
        vlan_configuration_id = '3'

        vlan.device_attr[dev1]
        vlan.device_attr[dev2]
        vlan.device_attr[dev1].interface_attr[intf1].switchport_mode = \
            'trunk'
        vlan.device_attr[dev1].interface_attr[intf1].sw_trunk_allowed_vlan = \
            '200-201'
        vlan.device_attr[dev1].access_map_attr[access_map_id]
        vlan.device_attr[dev2].access_map_attr[access_map_id]
        vlan.device_attr[dev1].vlan_configuration_attr[vlan_configuration_id]
        vlan.device_attr[dev2].vlan_configuration_attr[vlan_configuration_id]

        # Defining attributes section
        vlan.shutdown = False
        with self.assertRaises(ValueError):
            vlan.media = 'invalid'
        vlan.media = 'enet'
        self.assertIs(type(vlan.media), Vlan.Media)
        vlan.accounting_type = 'input'
        vlan.device_attr[dev1].access_map_action = 'drop'
        vlan.datalink_flow_monitor = True
        vlan.private_vlan_type = 'association'
        vlan.private_vlan_association_action = 'add'
        vlan.private_vlan_association_ids = '201,205'

        cfg1 = vlan.build_config(apply=False)

        self.assertCountEqual(cfg1.keys(), ['PE1', 'PE2'])

        self.assertMultiLineEqual(
            str(cfg1['PE1']),
            '\n'.join([
                'vlan 100',
                ' media enet',
                ' no shutdown',
                ' private-vlan association add 201,205',
                ' exit',
                'vlan accounting input',
                'vlan access-map ed',
                ' action drop',
                ' exit',
                'vlan configuration 3',
                ' datalink flow monitor',
                ' exit',
                'interface GigabitEthernet0/0/1',
                ' switchport mode trunk',
                ' switchport trunk allowed vlan 200-201',
                ' exit',
            ]))

        self.assertMultiLineEqual(
            str(cfg1['PE2']),
            '\n'.join([
                'vlan 100',
                ' media enet',
                ' no shutdown',
                ' private-vlan association add 201,205',
                ' exit',
                'vlan accounting input',
                'vlan access-map ed',
                ' exit',
                'vlan configuration 3',
                ' datalink flow monitor',
                ' exit',
            ]))
Пример #8
0
    def test_enable_disable(self):

        # For failures
        self.maxDiff = None

        # Set testbed
        Genie.testbed = testbed = Testbed()
        dev1 = Device(testbed=testbed, name='PE1', os='nxos')

        # Create Vlan object
        vlan1 = Vlan()
        dev1.add_feature(vlan1)
        vlan1.device_attr[dev1].enabled = True

        # Check config strings built correctly
        cfgs = vlan1.build_config(apply=False)
        self.assertMultiLineEqual(
            str(cfgs[dev1.name]),
            '\n'.join([
                'feature interface-vlan',
                'feature vn-segment-vlan-based',
            ]))

        # Unconfigure
        uncfgs = vlan1.build_unconfig(apply=False)
        self.assertMultiLineEqual(
            str(uncfgs[dev1.name]),
            '\n'.join([
                'no feature interface-vlan',
                'no feature vn-segment-vlan-based',
            ]))

        dev1.remove_feature(vlan1)

        # Create Vlan object
        vlan2 = Vlan()
        dev1.add_feature(vlan2)
        vlan2.device_attr[dev1].enabled_interface_vlan = True

        # Check config strings built correctly
        cfgs = vlan2.build_config(apply=False)
        self.assertMultiLineEqual(
            str(cfgs[dev1.name]),
            '\n'.join([
                'feature interface-vlan',
            ]))

        # Unconfigure
        uncfgs = vlan2.build_unconfig(apply=False)
        self.assertMultiLineEqual(
            str(uncfgs[dev1.name]),
            '\n'.join([
                'no feature interface-vlan',
            ]))

        # Remove feature
        dev1.remove_feature(vlan2)

        # Create Vlan object
        vlan3 = Vlan()
        dev1.add_feature(vlan3)
        vlan3.device_attr[dev1].enabled_vn_segment_vlan_based = True

        # Build config
        cfgs = vlan3.build_config(apply=False)
        self.assertMultiLineEqual(
            str(cfgs[dev1.name]),
            '\n'.join([
                'feature vn-segment-vlan-based',
            ]))

        # Unconfigure
        uncfgs = vlan3.build_unconfig(apply=False)
        self.assertMultiLineEqual(
            str(uncfgs[dev1.name]),
            '\n'.join([
                'no feature vn-segment-vlan-based',
            ]))
Пример #9
0
    def test_basic_cfg(self):
        testbed = Genie.testbed = Testbed()
        dev1 = Device(testbed=testbed, name='PE1', os='nxos')
        dev2 = Device(testbed=testbed, name='PE2', os='nxos')
        intf1 = Interface(name='Ethernet0/0/1', device=dev1, layer=Layer.L3)
        intf2 = Interface(name='Ethernet0/0/2', device=dev2, layer=Layer.L2)
        link = Link(name='1_2_1', testbed=testbed)
        link.connect_interface(interface=intf1)
        link.connect_interface(interface=intf2)
        vlan = Vlan()
        link.add_feature(vlan)
        vlan.vlan_id = 100
        access_map_id = 'ed'
        vlan_configuration_id = '3'

        vlan.device_attr[dev1]
        vlan.device_attr[dev2]
        vlan.device_attr[dev1].interface_attr[intf1]
        vlan.device_attr[dev2].interface_attr[intf2]
        vlan.device_attr[dev2].interface_attr[intf2].switchport_mode = \
            L2_type.TRUNK
        vlan.device_attr[dev2].interface_attr[intf2].sw_trunk_allowed_vlan = \
            '200-201'
        vlan.device_attr[dev1].access_map_attr[access_map_id]
        vlan.device_attr[dev2].access_map_attr[access_map_id]
        vlan.device_attr[dev1].vlan_configuration_attr[vlan_configuration_id]
        vlan.device_attr[dev2].vlan_configuration_attr[vlan_configuration_id]

        # Defining attributes section
        vlan.shutdown = False
        with self.assertRaises(ValueError):
            vlan.media = 'invalid'
        vlan.media = 'enet'
        self.assertIs(type(vlan.media), Vlan.Media)
        vlan.egress_load_balance = True
        vlan.device_attr[dev1].access_map_action = 'drop'
        vlan.datalink_flow_monitor = True

        intf1.ipv4 = '201.0.12.1'
        intf1.ipv4.netmask = '255.255.255.0'
        intf1.speed = 1000
        intf1.mtu = 500
        intf1.ipv6 = '2001::12:1'

        cfg1 = vlan.build_config(apply=False)
        cfg2 = intf1.build_config(apply=False)
        self.assertCountEqual(cfg1.keys(), ['PE1', 'PE2'])

        self.assertMultiLineEqual(
            str(cfg1['PE1']),
            '\n'.join([
                'vlan 100',
                ' media enet',
                ' no shutdown',
                ' exit',
                'vlan access-map ed',
                ' action drop',
                ' exit',
                'vlan configuration 3',
                ' egress port-channel load-balance random',
                ' exit',
                'interface Ethernet0/0/1',
                ' mtu 500',
                ' ip address 201.0.12.1 255.255.255.0',
                ' ipv6 address 2001::12:1/128',
                ' speed 1000',
                ' exit',
            ]))

        self.assertMultiLineEqual(
            str(cfg1['PE2']),
            '\n'.join([
                'vlan 100',
                ' media enet',
                ' no shutdown',
                ' exit',
                'vlan access-map ed',
                ' exit',
                'vlan configuration 3',
                ' egress port-channel load-balance random',
                ' exit',
                'interface Ethernet0/0/2',
                ' switchport mode trunk',
                ' switchport trunk allowed vlan 200-201',
                ' exit',
            ]))

        self.assertMultiLineEqual(
            str(cfg2),
            '\n'.join([
                'interface Ethernet0/0/1',
                ' mtu 500',
                ' ip address 201.0.12.1 255.255.255.0',
                ' ipv6 address 2001::12:1/128',
                ' speed 1000',
                ' exit',
            ]))
Пример #10
0
    def test_cfg_with_igmp(self):
        Genie.testbed = testbed = Testbed()
        dev1 = Device(testbed=testbed, name='PE1', os='nxos')

        with self.assertNoWarnings():
            Genie.testbed = None
            with self.assertRaises(TypeError):
                vlan = Vlan()
            Genie.testbed = testbed

            vlan = Vlan(vlan='102')
            vlan.device_attr[dev1].vlan_attr['102'].name = 'vlan2'
            vlan.device_attr[dev1].vlan_attr['102'].state = 'active'
            vlan.device_attr[dev1].vlan_attr['102'].mode = 'ce'

            vlan.device_attr[dev1].config_vlan_attr['102'].config_vlan_id = '102'
            vlan.device_attr[dev1].config_vlan_attr['102'].ip_igmp_snooping = True

            self.assertIs(vlan.testbed, testbed)

            dev1.add_feature(vlan)

            cfgs = vlan.build_config(apply=False)
            self.assertCountEqual(cfgs.keys(), [dev1.name])
            self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.join([
                'vlan 102',
                ' name vlan2',
                ' state active',
                ' mode ce',
                ' exit',
                'vlan configuration 102',
                ' ip igmp snooping',
                ' exit'
            ]))

            un_cfgs = vlan.build_unconfig(apply=False)
            self.assertMultiLineEqual(str(un_cfgs[dev1.name]), '\n'.join([
                'no vlan 102',
                'no vlan configuration 102',
            ]))

            un_cfgs = vlan.build_unconfig(apply=False,
                                          attributes={'device_attr': {
                                                        dev1: {
                                                            'vlan_attr': {
                                                                '102': {"mode": None}
                                                            },
                                                            'config_vlan_attr': {
                                                                '102': {"ip_igmp_snooping": None}
                                                            }
                                                        }
                                                    }
                                                })
            self.assertCountEqual(un_cfgs.keys(), [dev1.name])
            self.assertMultiLineEqual(str(un_cfgs[dev1.name]), '\n'.join([
                'vlan 102',
                ' no mode ce',
                ' exit',
                'vlan configuration 102',
                ' no ip igmp snooping',
                ' exit',
            ]))
Пример #11
0
    def test_basic_uncfg(self):
        testbed = Genie.testbed = Testbed()
        dev1 = Device(testbed=testbed, name='PE1', os='nxos')
        dev2 = Device(testbed=testbed, name='PE2', os='nxos')
        intf1 = Interface(name='Ethernet0/0/1', device=dev1, layer=Layer.L3)
        intf2 = Interface(name='Ethernet0/0/2', device=dev2, layer=Layer.L2)
        link = Link(name='1_2_1', testbed=testbed)
        link.connect_interface(interface=intf1)
        link.connect_interface(interface=intf2)
        vlan = Vlan()
        link.add_feature(vlan)
        vlan.vlan_id = 100
        access_map_id = 'ed'
        vlan_configuration_id = '3'

        vlan.device_attr[dev1]
        vlan.device_attr[dev2]
        vlan.device_attr[dev1].access_map_attr[access_map_id]
        vlan.device_attr[dev2].access_map_attr[access_map_id]
        vlan.device_attr[dev1].interface_attr[intf1]
        vlan.device_attr[dev2].interface_attr[intf2]
        vlan.device_attr[dev2].interface_attr[intf2].switchport_mode = \
            L2_type.TRUNK
        vlan.device_attr[dev2].interface_attr[intf2].sw_trunk_allowed_vlan = \
            '200-201'
        vlan.device_attr[dev1].vlan_configuration_attr[vlan_configuration_id]
        vlan.device_attr[dev2].vlan_configuration_attr[vlan_configuration_id]

        # Defining attributes section
        vlan.shutdown = False
        with self.assertRaises(ValueError):
            vlan.media = 'invalid'
        vlan.media = 'enet'
        self.assertIs(type(vlan.media), Vlan.Media)
        vlan.egress_port_channel_load_balance_random = True
        vlan.device_attr[dev1].access_map_action = 'drop'
        vlan.datalink_flow_monitor = True

        # Unconfig testing
        # Set a mock
        dev1.cli = Mock()
        dev1.configure = Mock()
        dev2.cli = Mock()
        dev2.configure = Mock()
        dev1.add_feature(vlan)
        dev2.add_feature(vlan)
        # Mock config

        output = vlan.build_config(apply=True)

        uncfg1 = vlan.build_unconfig(apply=False)
        self.assertCountEqual(uncfg1.keys(), ['PE1', 'PE2'])
        self.assertMultiLineEqual(
            str(uncfg1['PE1']),
            '\n'.join([
                'no vlan 100',
                'no vlan access-map ed',
                'no vlan configuration 3',
            ]))

        self.assertMultiLineEqual(
            str(uncfg1['PE2']),
            '\n'.join([
                'no vlan 100',
                'no vlan access-map ed',
                'no vlan configuration 3',
                'interface Ethernet0/0/2',
                ' no switchport mode trunk',
                ' no switchport trunk allowed vlan 200-201',
                ' exit',
            ]))

        partial_uncfg1 = vlan.build_unconfig(apply=False,
                                             attributes={'device_attr': \
                                                             {'*': "media"}})
        self.assertCountEqual(partial_uncfg1.keys(), ['PE1', 'PE2'])
        self.assertMultiLineEqual(
            str(partial_uncfg1['PE1']),
            '\n'.join([
                'vlan 100',
                ' no media enet',
                ' exit',
            ]))

        partial_unconfigure = vlan.build_unconfig(apply=False,
                                                  attributes={'device_attr': \
                                                                  {'*': {'access_map_attr': \
                                                                             {'*': "access_map_action"}}}})
        self.assertCountEqual(partial_unconfigure.keys(), ['PE1', 'PE2'])
        self.assertMultiLineEqual(
            str(partial_unconfigure['PE1']),
            '\n'.join([
                'vlan access-map ed',
                ' no action drop',
                ' exit',
            ]))

        all_vlan_interface_uncfg = vlan.build_unconfig(apply=False,
                                                       attributes={ \
                                                           'device_attr': {'*': { \
                                                               'interface_attr': '*'}}})
        self.assertCountEqual(all_vlan_interface_uncfg.keys(), ['PE1', 'PE2'])
        self.assertMultiLineEqual(
            str(all_vlan_interface_uncfg['PE2']),
            '\n'.join([
                'interface Ethernet0/0/2',
                ' no switchport mode trunk',
                ' no switchport trunk allowed vlan 200-201',
                ' exit',
            ]))

        partial_vlan_interface_uncfg = vlan.build_unconfig(apply=False,
                                                           attributes={ \
                                                               'device_attr': {'*': \
                                                                                   {'interface_attr': \
                                                                                        {
                                                                                            '*': "sw_trunk_allowed_vlan"}}}})
        self.assertCountEqual(partial_vlan_interface_uncfg.keys(), ['PE1', 'PE2'])
        self.assertMultiLineEqual(
            str(partial_vlan_interface_uncfg['PE2']),
            '\n'.join([
                'interface Ethernet0/0/2',
                ' no switchport trunk allowed vlan 200-201',
                ' exit',
            ]))
Пример #12
0
    def test_basic_uncfg(self):
        testbed = Genie.testbed = Testbed()
        dev1 = Device(testbed=testbed, name='PE1', os='iosxr')
        dev2 = Device(testbed=testbed, name='PE2', os='iosxr')
        intf1 = Interface(name='GigabitEthernet0/0/1', device=dev1)
        intf2 = Interface(name='GigabitEthernet0/0/2', device=dev2)
        intf3 = Interface(name='GigabitEthernet0/0/3', device=dev1)
        link = Link(name='1_2_1', testbed=testbed)
        link.connect_interface(interface=intf1)
        link.connect_interface(interface=intf2)
        vlan = Vlan()
        link.add_feature(vlan)

        # Defining attributes section
        vlan.device_attr[dev1]
        vlan.device_attr[dev2]
        vlan.device_attr[dev1].interface_attr[intf1]
        vlan.device_attr[dev1].interface_attr[intf1].eth_encap_type1 = 'dot1q'
        vlan.device_attr[dev1].interface_attr[intf1].eth_encap_val1 = 2
        vlan.device_attr[dev1].interface_attr[
            intf1].eth_encap_type2 = 'second-dot1q'
        vlan.device_attr[dev1].interface_attr[intf1].eth_encap_val2 = 5

        # Unconfig testing
        # Set a mock
        dev1.cli = Mock()
        dev1.configure = Mock()
        dev2.cli = Mock()
        dev2.configure = Mock()
        dev1.add_feature(vlan)
        dev2.add_feature(vlan)
        # Mock config

        output = vlan.build_config(apply=True)

        uncfg = vlan.build_unconfig(apply=False)
        self.assertMultiLineEqual(
            str(uncfg['PE1']), '\n'.join([
                'interface GigabitEthernet0/0/1',
                ' no encapsulation dot1q 2 second-dot1q 5',
                ' exit',
            ]))

        all_vlan_interface_uncfg = vlan.build_unconfig(apply=False,
                                                       attributes={'device_attr':\
                                                       {'*':{'interface_attr':'*'}}})
        self.assertCountEqual(all_vlan_interface_uncfg.keys(), ['PE1', 'PE2'])
        self.assertMultiLineEqual(
            str(all_vlan_interface_uncfg['PE1']), '\n'.join([
                'interface GigabitEthernet0/0/1',
                ' no encapsulation dot1q 2 second-dot1q 5',
                ' exit',
            ]))

        partial_vlan_interface_uncfg = vlan.build_unconfig(apply=False,
                                                           attributes={'device_attr':\
                                                           {'*':{'interface_attr':\
                                                           {'*':"eth_encap_type1"}}}})
        self.assertCountEqual(partial_vlan_interface_uncfg.keys(),
                              ['PE1', 'PE2'])
        self.assertMultiLineEqual(
            str(partial_vlan_interface_uncfg['PE1']), '\n'.join([
                'interface GigabitEthernet0/0/1',
                ' no encapsulation dot1q 2 second-dot1q 5',
                ' exit',
            ]))
Пример #13
0
interfaces["Ethernet1/3"]["switchport_mode"]
interfaces["Ethernet1/3"]["access_vlan"]

# Demo: Using genie.conf to configure vlans and interfaces
from genie.libs.conf.vlan import Vlan
from genie.libs.conf.interface import Interface

# Create new Vlan object
new_vlan = Vlan(vlan_id="3001", name="GenieConfigured")

# Add new vlan to device as a feature
device.add_feature(new_vlan)
new_vlan.devices

# Build the configuration for the vlan, but don't send to device
output = new_vlan.build_config(apply=False)
output
print(output["sbx-n9kv-ao"])

# Build and send the configuration to devices
output = new_vlan.build_config(apply=True)

# Build and print out the configuraiton to REMOVE the Vlan from the devices
output = new_vlan.build_unconfig(apply=False)
print(output["sbx-n9kv-ao"])

# Build and send the configuration to remove the Vlan from the device
output = new_vlan.build_unconfig()

# Create a new Interface object for the device
new_interface = Interface(name="Ethernet1/10", device=device)