コード例 #1
0
def management_interface(device_name):
    'Return the name of the interface that is used to manage the specified network device.'
    control = device_control(device_name)
    if (not control):
        return None
    url_suffix = _configuration_multi_url_template % quote_plus(device_name)
    response = odl_http_get(url_suffix,
                            'application/xml',
                            expected_status_code=[200, 400])
    if response.status_code == 400:
        return None  # The specified device does not have interfaces.
    if device_name in _network_device_config.keys():
        device_address = _network_device_config[device_name]['address']
    else:
        device_address = None  # Discovered or configured independently.
    tree = etree.parse(StringIO(response.text))
    for ifc in tree.xpath(
            "/ifc:interface-configurations/ifc:interface-configuration",
            namespaces=_interface_namespaces):
        for ipv4 in ifc.xpath('ipv4c:ipv4-network/ipv4c:addresses/*',
                              namespaces=_interface_namespaces):
            address = ipv4.findtext('ipv4c:address',
                                    namespaces=_interface_namespaces)
            netmask = ipv4.findtext('ipv4c:netmask',
                                    namespaces=_interface_namespaces)
            if address == control.address:
                return ifc.findtext('ifc:interface-name',
                                    namespaces=_interface_namespaces)
    return None
コード例 #2
0
def demonstrate(device_name):
    """
    Apply function 'static_route_create' to the specified device.
    
    Choose a destination that does not already exist. 
    Choose a next-hop on the same sub-network as an existing interface.
    If the next-hop is unknown then use any valid ip-address.
    """
    
    print('Select a destination network for which a static route does not exist.')
    destination_network_iterator = destination_network_generator()
    while True: 
        destination_network = next(destination_network_iterator)
        print('static_route_exists(%s, %s)' % (device_name, destination_network))
        exists = static_route_exists(device_name, destination_network)
        print(exists)
        print()
        if not exists:
            break
    
    print('Determine which interface is on the management plane (to avoid it).')     
    print('device_control(%s)' % device_name)
    device_mgmt = device_control(device_name)
    print_table(device_mgmt)
    print()

    print('Determine ip-address and network-mask of every interface.')     
    print('interface_configuration_tuple(%s)' % device_name)
    interface_config_list = interface_configuration_tuple(device_name)
    print_table(interface_config_list)
    print()
    
    for interface_config in interface_config_list:
        if interface_config.address is None:
            # Skip network interface with unassigned IP address.             
            continue
        if interface_config.address == device_mgmt.address:
            # Do not configure static routes on the 'management plane'.             
            continue
        if 'Loopback' in interface_config.name:
            # Do not configure static routes on the 'control plane'.             
            continue
        
        print('Determine next-hop for a network interface.')
        interface_network = interface_config.ip_network
        next_hop_address = match(device_name, interface_network)
        if next_hop_address is None:
            print('Next-hop for %s/%s %s/%s is outside the known topology.' % (device_name, interface_config.name, interface_config.address, interface_config.netmask))
            next_hop_address = interface_network.network_address
            if next_hop_address == interface_config.ip_interface:
                next_hop_address += 1
            print('Assume that next-hop for %s/%s %s/%s is %s.' % (device_name, interface_config.name, interface_config.address, interface_config.netmask, next_hop_address))
        else:
            print('Next-hop for %s/%s %s/%s is %s.' % (device_name, interface_config.name, interface_config.address, interface_config.netmask, next_hop_address))
        print()

        print('static_route_create(%s, %s, %s)' % (device_name, destination_network, next_hop_address))
        static_route_create(device_name, destination_network, next_hop_address)
        return True
    return False
コード例 #3
0
def demonstrate(device_name):
    """
    Apply function 'static_route_create' to the specified device.
    
    Choose a destination that does not already exist. 
    Choose a next-hop on the same sub-network as an existing interface.
    If the next-hop is unknown then use any valid ip-address.
    """
    
    print('Select a destination network for which a static route does not exist.')
    destination_network_iterator = destination_network_generator()
    while True: 
        destination_network = next(destination_network_iterator)
        print('static_route_exists(%s, %s)' % (device_name, destination_network))
        exists = static_route_exists(device_name, destination_network)
        print(exists)
        print()
        if not exists:
            break
    
    print('Determine which interface is on the management plane (to avoid it).')     
    print('device_control(%s)' % device_name)
    device_mgmt = device_control(device_name)
    print_table(device_mgmt)
    print()

    print('Determine ip-address and network-mask of every interface.')     
    print('interface_configuration_tuple(%s)' % device_name)
    interface_config_list = interface_configuration_tuple(device_name)
    print_table(interface_config_list)
    print()
    
    for interface_config in interface_config_list:
        if interface_config.address is None:
            # Skip network interface with unassigned IP address.             
            continue
        if interface_config.address == device_mgmt.address:
            # Do not configure static routes on the 'management plane'.             
            continue
        if 'Loopback' in interface_config.name:
            # Do not configure static routes on the 'control plane'.             
            continue
        
        print('Determine next-hop for a network interface.')
        interface_network = interface_config.ip_network
        next_hop_address = match(device_name, interface_network)
        if next_hop_address is None:
            print('Next-hop for %s/%s %s/%s is outside the known topology.' % (device_name, interface_config.name, interface_config.address, interface_config.netmask))
            next_hop_address = interface_network.network_address
            if next_hop_address == interface_config.ip_interface:
                next_hop_address += 1
            print('Assume that next-hop for %s/%s %s/%s is %s.' % (device_name, interface_config.name, interface_config.address, interface_config.netmask, next_hop_address))
        else:
            print('Next-hop for %s/%s %s/%s is %s.' % (device_name, interface_config.name, interface_config.address, interface_config.netmask, next_hop_address))
        print()

        print('static_route_create(%s, %s, %s)' % (device_name, destination_network, next_hop_address))
        static_route_create(device_name, destination_network, next_hop_address)
        return True
    return False
コード例 #4
0
 def test_device_mount(self):
     device_names = inventory_unmounted()
     self.assertTrue(device_names, "One or more devices must be configured.")
     for device_name in device_names:
         expected = mount_from_settings(device_name)
         self.assertTrue(mounted(device_name), "Expected mounted: " + device_name)
         actual = device_control(device_name)
         self.assertEqual(device_name, actual.device_name)
         self.assertEqual(expected.device_name, actual.device_name)
         self.assertEqual(expected.address, actual.address)
         self.assertEqual(expected.port, actual.port)
         self.assertEqual(expected.username, actual.username)
         self.assertEqual(expected.password, actual.password)
コード例 #5
0
 def test_device_mount(self):
     device_names = inventory_unmounted()
     self.assertTrue(device_names,
                     'One or more devices must be configured.')
     for device_name in device_names:
         expected = mount_from_settings(device_name)
         self.assertTrue(mounted(device_name),
                         'Expected mounted: ' + device_name)
         actual = device_control(device_name)
         self.assertEqual(device_name, actual.device_name)
         self.assertEqual(expected.device_name, actual.device_name)
         self.assertEqual(expected.address, actual.address)
         self.assertEqual(expected.port, actual.port)
         self.assertEqual(expected.username, actual.username)
         self.assertEqual(expected.password, actual.password)
コード例 #6
0
def management_interface(device_name):
    'Return the name of the interface that is used to manage the specified network device.'
    control = device_control(device_name)
    if(not control):
        return None
    response = odl_http_get(_configuration_multi_url_template, {'node-id' : device_name}, 'application/xml', expected_status_code=[200, 400])
    if response.status_code == 400:
        return None  # The specified device does not have interfaces.
    if device_name in _network_device_config.keys():
        device_address = _network_device_config[device_name]['address']
    else:
        device_address = None  # Discovered or configured independently.
    tree = etree.parse(StringIO(response.text))
    for ifc in tree.xpath("/ifc:interface-configurations/ifc:interface-configuration", namespaces=_interface_namespaces):
        for ipv4 in ifc.xpath('ipv4c:ipv4-network/ipv4c:addresses/*', namespaces=_interface_namespaces):
            address = ipv4.findtext('ipv4c:address', namespaces=_interface_namespaces)
            netmask = ipv4.findtext('ipv4c:netmask', namespaces=_interface_namespaces)
            if address == control.address:
                return ifc.findtext('ifc:interface-name', namespaces=_interface_namespaces)
    return None
コード例 #7
0
def demonstrate(device_name):
    ''' Apply function 'device_control' to the specified device.'''
    print('device_control(' + device_name, end=')\n')
    print_table(device_control(device_name))
コード例 #8
0
def demonstrate(device_name):
    ''' Apply function 'device_control' to the specified device.'''
    print('device_control(' + device_name, end=')\n')
    print_rich(device_control(device_name))
コード例 #9
0
def demonstrate(device_name):
    """ Apply function 'device_control' to the specified device."""
    print("device_control(" + device_name, end=")\n")
    print_table(device_control(device_name))