def demonstrate(device_name, interface_config):
    print("Initial configuration:")
    initial = interface_config
    print(initial)

    try:
        print()
        print("Modify configuration:")
        print('interface_configuration_update(' + device_name,
              initial.name,
              temp_description,
              temp_address,
              temp_netmask,
              not initial.shutdown,
              sep=', ',
              end=')\n')
        interface_configuration_update(device_name,
                                       initial.name,
                                       description=temp_description,
                                       address=temp_address,
                                       netmask=temp_netmask,
                                       shutdown=not initial.shutdown)
        print()
        print("Modified configuration:")
        modified = interface_configuration(device_name, initial.name)
        print(modified)
        assert modified.name == initial.name
        assert modified.description != initial.description
        assert modified.address != initial.address
        assert modified.netmask != initial.netmask
        assert modified.shutdown != initial.shutdown

    finally:
        print()
        print("Restore configuration:")
        print('interface_configuration_update(' + device_name,
              initial.name,
              initial.description,
              initial.address,
              initial.netmask,
              initial.shutdown,
              sep=', ',
              end=')\n')
        interface_configuration_update(device_name,
                                       initial.name,
                                       description=initial.description,
                                       address=initial.address,
                                       netmask=initial.netmask,
                                       shutdown=initial.shutdown)

        print()
        print("Restored configuration:")
        restored = interface_configuration(device_name, initial.name)
        print(restored)
        assert restored.name == initial.name
        assert restored.description == initial.description, (
            "got " % initial.description)
        assert restored.address == initial.address
        assert restored.netmask == initial.netmask
        assert restored.shutdown == initial.shutdown
Exemplo n.º 2
0
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()
 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():
    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 demonstrate(device_name, interface_config):
    print("Initial configuration:")
    initial = interface_config
    print(initial)
    
    try:
        print()
        print("Modify configuration:")
        print('interface_configuration_update(' + device_name, initial.name, temp_description, temp_address, temp_netmask, not initial.shutdown, sep=', ', end=')\n')
        interface_configuration_update(device_name, initial.name, description=temp_description,
                               address=temp_address, netmask=temp_netmask, shutdown=not initial.shutdown)
        print()
        print("Modified configuration:")
        modified = interface_configuration(device_name, initial.name)
        print(modified)
        assert modified.name == initial.name
        assert modified.description != initial.description
        assert modified.address != initial.address
        assert modified.netmask != initial.netmask
        assert modified.shutdown != initial.shutdown
        
    finally:
        print()
        print("Restore configuration:")
        print('interface_configuration_update(' + device_name, initial.name, initial.description, initial.address, initial.netmask, initial.shutdown, sep=', ', end=')\n')
        interface_configuration_update(device_name, initial.name, description=initial.description, address=initial.address, netmask=initial.netmask, shutdown=initial.shutdown)
    
        print()
        print("Restored configuration:")
        restored = interface_configuration(device_name, initial.name)
        print(restored)
        assert restored.name == initial.name
        assert restored.description == initial.description, ("got " % initial.description)
        assert restored.address == initial.address
        assert restored.netmask == initial.netmask
        assert restored.shutdown == initial.shutdown
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 demonstrate(device_name, interface_config):
    print("Initial configuration:")
    initial = interface_config
    print(initial)
    assert initial.shutdown
    
    print()
    print("Startup interface %s on %s:" % (initial.name, device_name))
    print('interface_configuration_update(' + device_name, initial.name, initial.description, initial.address, initial.netmask, shutdown, sep=', ', end=')\n')
    interface_configuration_update(device_name, initial.name, description=initial.description,
                           address=initial.address, netmask=initial.netmask, shutdown=shutdown)
    print()
    print("Modified configuration:")
    modified = interface_configuration(device_name, initial.name)
    print(modified)
    assert not modified.shutdown
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 demonstrate(device_name, interface_name):
    ''' Apply function 'interface_configuration' to the specified device/interface.'''
    print('interface_configuration(' + device_name, interface_name, sep=', ', end=')\n')
    print_rich(interface_configuration(device_name, interface_name))
Exemplo n.º 11
0
def findneighbor(device_name):
    '''
        Description : 
            This function retrieve the cdp information for the specific device through 
            restconf API. It then parse the data and store the information in global
            var like nodes and edges.
                
    '''
    #get the result from cdp url for device_name
    response = odl_http_get(
        url_neighbours.format(**{
            'node-id': quote_plus(device_name),
        }),
        'application/json',
        expected_status_code=(200, 404))
    if response.status_code == 400:
        print(_BUG_CHECK % 'This interface is not provided!')
        return None
    j = json_loads(response.text)
    #add the node into the nodes, we store the device_id
    nodes.append(dict(nodename=devname2devid(device_name)))
    container = j["cdp"]["nodes"]["node"][0]
    #print(json_dumps(container, indent=2))
    if "neighbors" in container:
        neighbors = container["neighbors"]
        if 'summaries' in neighbors:
            summaries = neighbors['summaries']['summary']
            #now we get the list of summarirs, each summary is a {} dict type
            for summary in summaries:
                #here we skip the mgt interface
                if 'MgmtEth' in summary['interface-name']:
                    continue
                #add the data of an edge
                dict_item = {'localnode':devname2devid(device_name),\
                             'remotenode':summary['device-id'],\
                             'localifname':summary['interface-name'],\
                             'remoteifname':summary['cdp-neighbor'][0]['port-id']
                             }
                #At first we have to set the interface's bandwidth to maxmium,
                #in our design, we use available_bandwidth to implement the
                #route calculate and bandwidth reserve.
                if initial_flag == True:
                    dict_item['maxbandwidth'] = _MAXMIUM_BANDWIDTH
                    dict_item['available_bandwidth'] = _MAXMIUM_BANDWIDTH
                # now we have to set the  local network address and networkmask
                netresult = interface_configuration(
                    devid2devname(dict_item['localnode']),
                    dict_item['localifname'])
                # !!-.-!! here i can only accees the element by index even if the debugger tell me the data in it is address=10.0xxx, but
                # it is not a dict. so can anyone help?
                if netresult is not None:
                    dict_item['localaddr'] = netresult[3]
                    dict_item['localmask'] = netresult[4]
                    netresult = None
                else:
                    print(
                        _BUG_CHECK %
                        'The interface of the local node is wrong, maybe the device is not mounted'
                    )
                # now it is the remote address and networkmask
                netresult = interface_configuration(
                    devid2devname(dict_item['remotenode']),
                    dict_item['remoteifname'])
                if netresult is not None:
                    dict_item['remoteaddr'] = netresult[3]
                    dict_item['remotemask'] = netresult[4]
                else:
                    print(
                        _BUG_CHECK %
                        'The interface of the remote node is wrong, maybe the device is not mounted'
                    )

                edges.append(dict_item)

    else:
        print(_BUG_CHECK %
              'The node has no neighbors or maybe the device is not mounted')
        return None
def findneighbor(device_name):
    '''
        Description : 
            This function retrieve the cdp information for the specific device through 
            restconf API. It then parse the data and store the information in global
            var like nodes and edges.
                
    '''
    #get the result from cdp url for device_name
    response = odl_http_get(url_neighbours.format(**{'node-id': quote_plus(device_name), }),
                            'application/json',
                            expected_status_code=(200, 404)
                            )
    if response.status_code == 400:
        print(_BUG_CHECK %'This interface is not provided!')
        return None
    j = json_loads(response.text)
    #add the node into the nodes, we store the device_id
    nodes.append(dict(nodename=devname2devid(device_name)))
    container = j["cdp"]["nodes"]["node"][0]
    #print(json_dumps(container, indent=2))
    if "neighbors" in container:
        neighbors = container["neighbors"]
        if 'summaries' in neighbors:
            summaries = neighbors['summaries']['summary']
            #now we get the list of summarirs, each summary is a {} dict type
            for summary in summaries:
                #here we skip the mgt interface
                if 'MgmtEth' in summary['interface-name']:
                    continue
                #add the data of an edge
                dict_item = {'localnode':devname2devid(device_name),\
                             'remotenode':summary['device-id'],\
                             'localifname':summary['interface-name'],\
                             'remoteifname':summary['cdp-neighbor'][0]['port-id']
                             }
                #At first we have to set the interface's bandwidth to maxmium,
                #in our design, we use available_bandwidth to implement the 
                #route calculate and bandwidth reserve.
                if initial_flag == True :              
                    dict_item['maxbandwidth'] = _MAXMIUM_BANDWIDTH
                    dict_item['available_bandwidth'] = _MAXMIUM_BANDWIDTH                   
                # now we have to set the  local network address and networkmask
                netresult = interface_configuration(devid2devname(dict_item['localnode']), dict_item['localifname'])
                # !!-.-!! here i can only accees the element by index even if the debugger tell me the data in it is address=10.0xxx, but
                # it is not a dict. so can anyone help?
                if netresult is not None :
                    dict_item['localaddr'] = netresult[3]
                    dict_item['localmask'] = netresult[4]
                    netresult = None
                else :
                    print(_BUG_CHECK %'The interface of the local node is wrong, maybe the device is not mounted')
                # now it is the remote address and networkmask
                netresult = interface_configuration(devid2devname(dict_item['remotenode']), dict_item['remoteifname']) 
                if netresult is not None :
                    dict_item['remoteaddr'] = netresult[3]
                    dict_item['remotemask'] = netresult[4]
                else :
                    print(_BUG_CHECK %'The interface of the remote node is wrong, maybe the device is not mounted')
                          
                edges.append(dict_item)              

    else :
        print(_BUG_CHECK %'The node has no neighbors or maybe the device is not mounted')
        return None
Exemplo n.º 13
0
def demonstrate(device_name, interface_name):
    """ Apply function 'interface_configuration' to the specified device/interface."""
    print_rich("  ", interface_configuration(device_name, interface_name))
Exemplo n.º 14
0
def demonstrate(device_name, interface_name):
    ''' Apply function 'interface_configuration' to the specified device/interface.'''
    print_rich('  ', interface_configuration(device_name, interface_name))