def draw():
    """ Select a device/interface and demonstrate."""
    print(plain(doc(interface_configuration)))
    foundInterface = False

    G = nx.Graph()

    for device_name in sorted(inventory_connected()):
        G.add_node(device_name)
        print("%s:" % device_name)
        mgmt_name = management_interface(device_name)
        for interface_name in sorted(interface_names(device_name)):
            # Choose interface on 'data plane' not 'control plane'.
            if interface_name == mgmt_name:
                continue
            else:
                match(device_name, interface_name)
                foundInterface = True
                demonstrate(device_name, interface_name)
                to_interface = interface_configuration(device_name, interface_name)[1].split(" ")[1]
                print("interface:%s" % to_interface)
                G.add_edge(device_name, to_interface)
        if not foundInterface:
            print("There are no suitable network interfaces for this device.")

    print(G.nodes())
    print(G.edges())
    # nx.draw(G)
    nx.draw_networkx(G, with_labels=True)
    plt.show()
Beispiel #2
0
 def test_interface_names(self):
     for device_name in inventory_connected():
         print('test: interface_names(' + device_name, end=')')
         interfaces = interface_names(device_name)
         print(', got:', *interfaces)
         self.assertGreater(
             len(interfaces), 1,
             'Expected multiple interfaces, got %d' % len(interfaces))
 def test_interface_configuration(self):
     for device_name in config['network_device']:
         interface_name_list = interface_names(device_name)
         for interface_name in interface_name_list:
             info = interface_configuration(device_name, interface_name)
             self.assertEqual(info.name, interface_name)
             self.assertIsNotNone(info.description)
             self.assertIsNotNone(info.address)
             self.assertIsNotNone(info.netmask)
 def test_interface_configuration(self):
     for device_name in config['network_device']:
         interface_name_list = interface_names(device_name)
         for interface_name in interface_name_list:
             info = interface_configuration(device_name, interface_name)
             self.assertEqual(info.name, interface_name)
             self.assertIsNotNone(info.description)
             self.assertIsNotNone(info.address)
             self.assertIsNotNone(info.netmask)
def main():
    ''' Select a device/interface and demonstrate.'''
    print(plain(doc(interface_configuration)))
    for device_name in inventory_connected():
        mgmt_name = management_interface(device_name)
        for interface_name in interface_names(device_name):
            # Choose interface on 'data plane' not 'control plane'.
            if interface_name == mgmt_name:
                continue
            return demonstrate(device_name, interface_name)
    print("There are no suitable network devices. Demonstration cancelled.")
def main():
    print(plain(doc(interface_configuration_update)))
    for device_name in inventory_connected():
        mgmt_name = management_interface(device_name)
        for interface_name in interface_names(device_name):
            # Avoid modifying the management interface.
            if interface_name == mgmt_name:
                continue
            interface_config = interface_configuration(device_name, interface_name)
            if not interface_config.address:
                continue
            demonstrate(device_name, interface_config)
            return os.EX_OK
    print("There are no suitable network devices. Demonstration cancelled.")
    return os.EX_TEMPFAIL
def main():
    print(plain(doc(interface_configuration_update)))
    for device_name in inventory_connected():
        mgmt_name = management_interface(device_name)
        for interface_name in interface_names(device_name):
            # Avoid modifying the management interface.
            if interface_name == mgmt_name:
                continue
            interface_config = interface_configuration(device_name,
                                                       interface_name)
            if not interface_config.address:
                continue
            demonstrate(device_name, interface_config)
            return os.EX_OK
    print("There are no suitable network devices. Demonstration cancelled.")
    return os.EX_TEMPFAIL
Beispiel #8
0
def main():
    ''' Select a device/interface and demonstrate.'''
    print(plain(doc(interface_configuration)))
    foundInterface = False
    for device_name in sorted(inventory_connected()):
        print("%s:" % device_name)
        mgmt_name = management_interface(device_name)
        for interface_name in sorted(interface_names(device_name)):
            # Choose interface on 'data plane' not 'control plane'.
            if interface_name == mgmt_name:
                continue
            else:
                foundInterface = True
                demonstrate(device_name, interface_name)
        if not foundInterface:
            print("There are no suitable network interfaces for this device.")
def main():
    print(plain(doc(interface_configuration_update)))
    for device_name in inventory_connected():
        mgmt_name = management_interface(device_name)
        for interface_name in interface_names(device_name):
            # Choose interface on 'data plane' not 'control plane'.
            if interface_name == mgmt_name:
                continue
            interface_config = interface_configuration(device_name, interface_name)
            if not interface_config.address:
                continue
            if not interface_config.shutdown:
                continue
            demonstrate(device_name, interface_config)
            return os.EX_OK
    print("There are no suitable network devices/interfaces. Demonstration cancelled.")
    return os.EX_TEMPFAIL
def match(device_name, interface_network):
    """ Discover matching interface on a different device."""
    for other_device in inventory_connected():
        if other_device == device_name:
            continue
        for interface_name in interface_names(other_device):
            interface_config = interface_configuration_tuple(other_device, interface_name)
            if interface_config.address is None:
                # Skip network interface with unassigned IP address.
                continue
            other_network = to_ip_network(interface_config.address, interface_config.netmask)
            if other_network == interface_network:
                print(
                    "Match %s/%s/%s to %s/%s"
                    % (device_name, interface_config.address, interface_config.netmask, other_device, interface_network)
                )
                #                return (other_device,interface_config.name)
                return other_device
    return None
def demonstrate(device_name):
    ''' Apply function 'interface_names' to the specified device.'''
    print('interface_names(' + device_name, end=')\n')
    print(interface_names(device_name))
def demonstrate(device_name):
    ''' Apply function 'interface_names' to the specified device.'''
    print('interface_names(' + device_name, end=')\n')
    print(interface_names(device_name))
 def test_interface_names(self):
     for device_name in inventory_connected():
         print('test: interface_names(' + device_name, end=')')
         interfaces = interface_names(device_name)
         print(', got:', *interfaces)
         self.assertGreater(len(interfaces), 1, 'Expected multiple interfaces, got %d' % len(interfaces))