コード例 #1
0
    def test_basic_parsing(self, tftp_reader_mock):
        tftp_reader_mock.return_value = """
!
vlan 1000
name VLAN_1_0_0_0
!
!
vlan 2000
name VLAN_2_0_0_0
!
"""
        config = SwitchConfiguration("127.0.0.1", name="my_switch", ports=[
            Port("GigabitEthernet0/1")
        ])

        parser = SwitchTftpParser(config)

        parser.parse("hostname", "filename", ConfigCommandProcessor)

        tftp_reader_mock.assert_called_with("hostname", "filename")

        vlan1000 = config.get_vlan(1000)
        assert_that(vlan1000.name, equal_to("VLAN_1_0_0_0"))

        vlan2000 = config.get_vlan(2000)
        assert_that(vlan2000.name, equal_to("VLAN_2_0_0_0"))
コード例 #2
0
    def test_basic_parsing(self, tftp_reader_mock):
        tftp_reader_mock.return_value = """
!
vlan 1000
name VLAN_1_0_0_0
!
!
vlan 2000
name VLAN_2_0_0_0
!
"""
        config = SwitchConfiguration("127.0.0.1",
                                     name="my_switch",
                                     ports=[Port("GigabitEthernet0/1")])

        parser = SwitchTftpParser(config)
        config_processor = ConfigCommandProcessor(
            config_vlan=ConfigVlanCommandProcessor(),
            config_vrf=None,
            config_interface=None)
        parser.parse("hostname", "filename", config_processor)

        tftp_reader_mock.assert_called_with("hostname", "filename")

        vlan1000 = config.get_vlan(1000)
        assert_that(vlan1000.name, equal_to("VLAN_1_0_0_0"))

        vlan2000 = config.get_vlan(2000)
        assert_that(vlan2000.name, equal_to("VLAN_2_0_0_0"))
コード例 #3
0
ファイル: global_reactor.py プロジェクト: simon-begin/netman
    def start_reactor(cls, models, reactor_hook_callbacks):
        cls._threaded_reactor = ThreadedReactor()

        for callback in reactor_hook_callbacks:
            callback(cls._threaded_reactor.reactor)

        for specs in models:
            switch_descriptor = specs["switch_descriptor"]

            hostname = switch_descriptor.hostname
            m = re.match('^https?:\/\/(.*)$',
                         switch_descriptor.hostname.lower())
            if m:
                hostname = m.group(1)

            switch_config = SwitchConfiguration(
                ip=hostname,
                name="my_switch",
                privileged_passwords=[switch_descriptor.password],
                ports=specs["ports"])

            specs["service_class"](
                hostname,
                port=switch_descriptor.port,
                switch_core=specs["core_class"](switch_config),
                users={
                    switch_descriptor.username: switch_descriptor.password
                }).hook_to_reactor(cls._threaded_reactor.reactor)

        cls._threaded_reactor.start()
コード例 #4
0
ファイル: global_reactor.py プロジェクト: rjshaver/netman
    def start_reactor(cls, models, reactor_hook_callbacks):
        cls._threaded_reactor = ThreadedReactor()

        for callback in reactor_hook_callbacks:
            callback(cls._threaded_reactor.reactor)

        for specs in models:
            switch_descriptor = specs["switch_descriptor"]

            switch_config = SwitchConfiguration(
                ip=switch_descriptor.hostname,
                name="my_switch",
                privileged_passwords=[switch_descriptor.password],
                ports=specs["ports"])

            specs["service_class"](
                switch_descriptor.hostname,
                ssh_port=switch_descriptor.port,
                telnet_port=switch_descriptor.port,
                switch_core=specs["core_class"](switch_config),
                users={
                    switch_descriptor.username: switch_descriptor.password
                }).hook_to_reactor(cls._threaded_reactor.reactor)

        cls._threaded_reactor.start()
コード例 #5
0
    def test_longer_parsing(self, tftp_reader_mock):
        tftp_reader_mock.return_value = """
!
vlan 1000
name VLAN_1_0_0_0
!
!
interface GigabitEthernet0/1
no switchport access vlan 1
switchport access vlan 1000
!
!
interface GigabitEthernet0/1
description "Gigabit Ethernet 1 desc"
switchport
load-interval 30
switchport mode access
switchport access vlan 1000
switchport nonegotiate
spanning-tree portfast
spanning-tree bpdufilter enable
spanning-tree bpduguard enable
no loopback
no keepalive
!
"""

        config = SwitchConfiguration("127.0.0.1",
                                     name="my_switch",
                                     ports=[Port("GigabitEthernet0/1")])

        parser = SwitchTftpParser(config)
        config_processor = ConfigCommandProcessor(
            config_vlan=ConfigVlanCommandProcessor(),
            config_vrf=None,
            config_interface=ConfigInterfaceCommandProcessor())
        parser.parse("hostname", "filename", config_processor)

        vlan1000 = config.get_vlan(1000)
        assert_that(vlan1000.name, equal_to("VLAN_1_0_0_0"))

        eth01 = config.get_port("GigabitEthernet0/1")
        assert_that(eth01.description, equal_to("Gigabit Ethernet 1 desc"))
        assert_that(eth01.mode, equal_to("access"))
        assert_that(eth01.access_vlan, equal_to(1000))
コード例 #6
0
    def test_longer_parsing(self, tftp_reader_mock):
        tftp_reader_mock.return_value = """
!
vlan 1000
name VLAN_1_0_0_0
!
!
interface GigabitEthernet0/1
no switchport access vlan 1
switchport access vlan 1000
!
!
interface GigabitEthernet0/1
description "Gigabit Ethernet 1 desc"
switchport
load-interval 30
switchport mode access
switchport access vlan 1000
switchport nonegotiate
spanning-tree portfast
spanning-tree bpdufilter enable
spanning-tree bpduguard enable
no loopback
no keepalive
!
"""

        config = SwitchConfiguration("127.0.0.1", name="my_switch", ports=[
            Port("GigabitEthernet0/1")
        ])

        parser = SwitchTftpParser(config)

        parser.parse("hostname", "filename", ConfigCommandProcessor)

        vlan1000 = config.get_vlan(1000)
        assert_that(vlan1000.name, equal_to("VLAN_1_0_0_0"))

        eth01 = config.get_port("GigabitEthernet0/1")
        assert_that(eth01.description, equal_to("Gigabit Ethernet 1 desc"))
        assert_that(eth01.mode, equal_to("access"))
        assert_that(eth01.access_vlan, equal_to(1000))
コード例 #7
0
    def start_reactor(cls):
        cls._threaded_reactor = ThreadedReactor()

        switch_core = CiscoSwitchCore(
            SwitchConfiguration(cisco_switch_ip, name="my_switch", privileged_passwords=[cisco_privileged_password],
                                ports=[
                                    Port("FastEthernet0/1"),
                                    Port("FastEthernet0/2"),
                                    Port("FastEthernet0/3"),
                                    Port("FastEthernet0/4"),
                                ]))
        SwitchTelnetService(cisco_switch_ip, telnet_port=cisco_switch_telnet_port, switch_core=switch_core,
                            users={'root': 'root'}).hook_to_reactor(cls._threaded_reactor.reactor)
        SwitchSshService(cisco_switch_ip, ssh_port=cisco_switch_ssh_port, switch_core=switch_core,
                         users={'root': 'root'}).hook_to_reactor(cls._threaded_reactor.reactor)

        auto_enabled_switch_core = CiscoSwitchCore(
            SwitchConfiguration(cisco_switch_ip, name="my_switch", auto_enabled=True))
        SwitchTelnetService(cisco_switch_ip, telnet_port=cisco_auto_enabled_switch_telnet_port,
                            switch_core=auto_enabled_switch_core, users={'root': 'root'}).hook_to_reactor(
            cls._threaded_reactor.reactor)
        SwitchSshService(cisco_switch_ip, ssh_port=cisco_auto_enabled_switch_ssh_port,
                         switch_core=auto_enabled_switch_core, users={'root': 'root'}).hook_to_reactor(
            cls._threaded_reactor.reactor)

        switch_core = BrocadeSwitchCore(
            SwitchConfiguration(brocade_switch_ip, name="my_switch", privileged_passwords=[brocade_privileged_password],
                                ports=[
                                    Port("ethernet 1/1"),
                                    Port("ethernet 1/2"),
                                    Port("ethernet 1/3"),
                                    Port("ethernet 1/4")
                                ]))
        SwitchSshService(brocade_switch_ip, ssh_port=brocade_switch_ssh_port, switch_core=switch_core,
                         users={'root': 'root'}).hook_to_reactor(cls._threaded_reactor.reactor)

        switch_core = JuniperSwitchCore(SwitchConfiguration(juniper_switch_ip, name="ju_ju_ju_juniper", ports=[
            Port("ge-0/0/1"),
            Port("ge-0/0/2"),
            Port("ge-0/0/3"),
            Port("ge-0/0/4")
        ]))
        SwitchSshService(juniper_switch_ip, ssh_port=juniper_switch_netconf_port, switch_core=switch_core,
                         users={'root': 'root'}).hook_to_reactor(cls._threaded_reactor.reactor)

        switch_core = JuniperQfxCopperSwitchCore(
            SwitchConfiguration(juniper_qfx_copper_switch_ip, name="ju_ju_ju_juniper_qfx_copper", ports=[
                Port("ge-0/0/1"),
                Port("ge-0/0/2"),
                Port("ge-0/0/3"),
                Port("ge-0/0/4")
            ]))
        SwitchSshService(juniper_qfx_copper_switch_ip, ssh_port=juniper_qfx_copper_switch_netconf_port,
                         switch_core=switch_core, users={'root': 'root'}).hook_to_reactor(cls._threaded_reactor.reactor)

        switch_core = DellSwitchCore(
            SwitchConfiguration(dell_switch_ip, name="my_switch", privileged_passwords=[dell_privileged_password],
                                ports=[
                                    Port("ethernet 1/g1"),
                                    Port("ethernet 1/g2"),
                                    Port("ethernet 2/g1"),
                                    Port("ethernet 2/g2"),
                                    Port("ethernet 1/xg1"),
                                    Port("ethernet 2/xg1")
                                ]))
        SwitchTelnetService(dell_switch_ip, telnet_port=dell_switch_telnet_port, switch_core=switch_core,
                            users={'root': 'root'}).hook_to_reactor(cls._threaded_reactor.reactor)
        SwitchSshService(dell_switch_ip, ssh_port=dell_switch_ssh_port, switch_core=switch_core,
                         users={'root': 'root'}).hook_to_reactor(cls._threaded_reactor.reactor)

        switch_core = Dell10GSwitchCore(
            SwitchConfiguration(dell10g_switch_ip, name="my_switch", privileged_passwords=[dell10g_privileged_password],
                                ports=[
                                    Port("tengigabitethernet 0/0/1"),
                                    Port("tengigabitethernet 0/0/2"),
                                    Port("tengigabitethernet 1/0/1"),
                                    Port("tengigabitethernet 1/0/2")
                                ]))
        SwitchTelnetService(dell10g_switch_ip, telnet_port=dell10g_switch_telnet_port, switch_core=switch_core,
                            users={'root': 'root'}).hook_to_reactor(cls._threaded_reactor.reactor)
        SwitchSshService(dell10g_switch_ip, ssh_port=dell10g_switch_ssh_port, switch_core=switch_core,
                         users={'root': 'root'}).hook_to_reactor(cls._threaded_reactor.reactor)

        switch_core = Dell10GSwitchCore(
            SwitchConfiguration(dell10g_switch_ip, name="my_switch", privileged_passwords=[dell10g_privileged_password],
                                ports=[
                                    Port("tengigabitethernet 0/0/1"),
                                    Port("tengigabitethernet 0/0/2"),
                                    Port("tengigabitethernet 1/0/1"),
                                    Port("tengigabitethernet 1/0/2")
                                ], commit_delay=COMMIT_DELAY))
        SwitchSshService(dell10g_switch_ip, ssh_port=dell10g_switch_with_commit_delay_ssh_port, switch_core=switch_core,
                         users={'root': 'root'}).hook_to_reactor(cls._threaded_reactor.reactor)





        # SWITCHES WITH COMMIT DELAYS

        switch_core = CiscoSwitchCore(
            SwitchConfiguration(cisco_switch_ip, name="my_switch", privileged_passwords=[cisco_privileged_password],
                                ports=[
                                    Port("FastEthernet0/1"),
                                    Port("FastEthernet0/2"),
                                    Port("FastEthernet0/3"),
                                    Port("FastEthernet0/4"),
                                    ], commit_delay=COMMIT_DELAY))
        SwitchSshService(cisco_switch_ip, ssh_port=cisco_switch_ssh_with_commit_delay_port, switch_core=switch_core,
                         users={'root': 'root'}).hook_to_reactor(cls._threaded_reactor.reactor)

        switch_core = BrocadeSwitchCore(
            SwitchConfiguration(brocade_switch_ip, name="my_switch", privileged_passwords=[brocade_privileged_password],
                                ports=[
                                    Port("ethernet 1/1"),
                                    Port("ethernet 1/2"),
                                    Port("ethernet 1/3"),
                                    Port("ethernet 1/4")
                                ], commit_delay=COMMIT_DELAY))
        SwitchSshService(brocade_switch_ip, ssh_port=brocade_switch_with_commit_delay_ssh_port, switch_core=switch_core,
                         users={'root': 'root'}).hook_to_reactor(cls._threaded_reactor.reactor)

        switch_core = JuniperSwitchCore(SwitchConfiguration(juniper_switch_ip, name="ju_ju_ju_juniper", ports=[
            Port("ge-0/0/1"),
            Port("ge-0/0/2"),
            Port("ge-0/0/3"),
            Port("ge-0/0/4")
        ], commit_delay=COMMIT_DELAY))
        SwitchSshService(juniper_switch_ip, ssh_port=juniper_switch_netconf_with_commit_delay_port, switch_core=switch_core,
                         users={'root': 'root'}).hook_to_reactor(cls._threaded_reactor.reactor)

        switch_core = DellSwitchCore(
            SwitchConfiguration(dell_switch_ip, name="my_switch", privileged_passwords=[dell_privileged_password],
                                ports=[
                                    Port("ethernet 1/g1"),
                                    Port("ethernet 1/g2"),
                                    Port("ethernet 2/g1"),
                                    Port("ethernet 2/g2"),
                                    Port("ethernet 1/xg1"),
                                    Port("ethernet 2/xg1")
                                ], commit_delay=COMMIT_DELAY))
        SwitchSshService(dell_switch_ip, ssh_port=dell_switch_with_commit_delay_ssh_port, switch_core=switch_core,
                         users={'root': 'root'}).hook_to_reactor(cls._threaded_reactor.reactor)

        cls._threaded_reactor.start()