コード例 #1
0
def main():
    """ 
    Print the documentation then perform the demonstration(s).
    """
    print(plain(doc(static_route_delete)))

    print('Determine which devices are capable.')
    print('inventory_static_route()')
    inventory = inventory_static_route()
    print_table(inventory, headers='device-name')
    if not inventory:
        print(
            "There are no 'static route' capable devices. Demonstration cancelled."
        )
    else:
        print()
        for device_name in inventory:
            print('static_route_list(%s)' % device_name)
            route_list = static_route_list(device_name)
            print_table(route_list, headers='destination-network')
            print()
            if route_list:
                demonstrate_one(device_name, route_list[0])
                if len(route_list) > 1:
                    demonstrate_all(device_name)
                return EX_OK
        print(
            "There are no devices with a 'static route' configured. Demonstration cancelled."
        )
    return EX_TEMPFAIL
コード例 #2
0
def main():
    """ 
    Print the function documentation then demonstrate the function usage on a selected device.
     
    Repeat for another device if no 'static route' is configured.
    """
    print(plain(doc(static_route_list)))

    print('Determine which devices are capable.')
    print('inventory_static_route()')
    device_names = inventory_static_route()
    if not device_names:
        print(
            "There are no 'static route' capable devices to examine. Demonstration cancelled."
        )
    else:
        print_table(device_names, headers='device-name')
        print()
        for device_name in device_names:
            if demonstrate(device_name):
                return EX_OK
        print(
            "There are no devices with a 'static route' configured. Demonstration cancelled."
        )
    return EX_TEMPFAIL
コード例 #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 main():
    if not settings:
        print('Settings must be configured', file=stderr)
    
    render.print_table(odl_http.coordinates)
    print()
    
    config = {"config:module" : [
                        {
                        "type": "lldp-speaker:lldp-speaker",
                        "name": "lldp-speaker",
                        "lldp-speaker:address-destination": "01:23:00:00:00:00",
                        "lldp-speaker:rpc-registry":{
                                                        "name": "binding-rpc-broker",
                                                        "type": "opendaylight-md-sal-binding:binding-rpc-registry"
                                                    },
                        "lldp-speaker:data-broker": {
                                                        "name": "binding-data-broker",
                                                        "type": "opendaylight-md-sal-binding:binding-async-data-broker"
                                                    }
                        }
                        ]
    }
    
    config_str = json.dumps(config)
    try:
        response = odl_http_post(
                      url_suffix='operational/opendaylight-inventory:nodes/node/openflow:1',
                      url_params={},
                      contentType='application/json',
                      content=config_str)
        print(response)
    except Exception as e:
        print(e, file=stderr)
コード例 #5
0
def main():
    print(plain(doc(inventory_summary)))
    print('InventorySummary fields:',
          *InventorySummary._fields,
          sep='\n\t',
          end='\n\n')
    print_table(inventory_summary())
コード例 #6
0
def main():
    if not settings:
        print('Settings must be configured', file=stderr)

    render.print_table(odl_http.coordinates)
    print()

    config = {
        "config:module": [{
            "type": "lldp-speaker:lldp-speaker",
            "name": "lldp-speaker",
            "lldp-speaker:address-destination": "01:23:00:00:00:00",
            "lldp-speaker:rpc-registry": {
                "name": "binding-rpc-broker",
                "type": "opendaylight-md-sal-binding:binding-rpc-registry"
            },
            "lldp-speaker:data-broker": {
                "name": "binding-data-broker",
                "type": "opendaylight-md-sal-binding:binding-async-data-broker"
            }
        }]
    }

    config_str = json.dumps(config)
    try:
        response = odl_http_post(
            url_suffix=
            'operational/opendaylight-inventory:nodes/node/openflow:1',
            url_params={},
            contentType='application/json',
            content=config_str)
        print(response)
    except Exception as e:
        print(e, file=stderr)
コード例 #7
0
def main():
    """ 
    Print the documentation then perform the demonstration(s).
    """
    print(plain(doc(static_route_json)))

    print('Determine which devices are capable.')
    print('inventory_static_route()')
    inventory = inventory_static_route()
    if not inventory:
        print(None)
        print(
            "There are no 'static route' capable devices. Demonstration cancelled."
        )
    else:
        print_table(inventory)
        print()
        for device_name in inventory:
            route_list = demonstrate_all(device_name)
            if route_list:
                return EX_OK if demonstrate_one(device_name,
                                                route_list[0]) else EX_TEMPFAIL
            else:
                print()
        print(
            "There are no devices with a 'static route' configured. Demonstration cancelled."
        )
    return EX_TEMPFAIL
コード例 #8
0
def main():
    """ 
    Print the documentation then perform the demonstration(s).
    """
    print(plain(doc(static_route_delete)))

    print('Determine which devices are capable.')
    print('inventory_static_route()')
    inventory = inventory_static_route()
    print_table(inventory, headers='device-name')
    if not inventory:
        print("There are no 'static route' capable devices. Demonstration cancelled.")
    else:
        print()
        for device_name in inventory:
            print('static_route_list(%s)' % device_name)
            route_list = static_route_list(device_name)
            print_table(route_list, headers='destination-network')
            print()
            if route_list:
                demonstrate_one(device_name, route_list[0])
                if len(route_list) > 1:
                    demonstrate_all(device_name)
                return EX_OK
        print("There are no devices with a 'static route' configured. Demonstration cancelled.")
    return EX_TEMPFAIL
コード例 #9
0
def demonstrate(device_name, interface_name):
    ''' Apply function 'interface_configuration_tuple' to the specified device/interface.'''
    print('interface_configuration(' + device_name,
          interface_name,
          sep=', ',
          end=')\n')
    print_table(interface_configuration_tuple(device_name, interface_name))
コード例 #10
0
def main():
    # It is essential to import module 'settings' because it injects the
    # Controller settings into attribute 'odl_http.coordinates'.
    # The code below references module 'settings' to prevent it from
    # being auto-removed due to an 'unused import' warning.
    if not settings:
        print('Settings must be configured', file=stderr)

    render.print_table(odl_http.coordinates)
    print()

    try:
        print('Connecting...')
        response = odl_http.odl_http_head(
            # Use any URL that is likely to succeed.
            url_suffix='operational/opendaylight-inventory:nodes',
            accept='application/json',
            expected_status_code=[200, 404, 503])
        outcome = {
            "status code":
            response.status_code,
            "status":
            'Not found (either the URL is incorrect or the controller is starting).'
            if response.status_code == 404 else
            'Service unavailable (allow 5 or 10 minutes for controller to become ready)'
            if response.status_code == 503 else
            'OK' if response.status_code == 200 else 'Unknown',
            "method":
            response.request.method,
            "url":
            response.url
        }
        render.print_table(outcome)
    except Exception as e:
        print(e, file=stderr)
コード例 #11
0
def main():
    # It is essential to import module 'settings' because it injects the
    # Controller settings into attribute 'odl_http.coordinates'.     
    # The code below references module 'settings' to prevent it from
    # being auto-removed due to an 'unused import' warning.
    if not settings:
        print('Settings must be configured', file=stderr)
    
    render.print_table(odl_http.coordinates)
    print()
        
    try:
        print('Connecting...')
        response = odl_http.odl_http_head(
            # Use any URL that is likely to succeed.                                   
            url_suffix='operational/opendaylight-inventory:nodes',
            accept='application/json',
            expected_status_code=[200, 404, 503])
        outcome = {
            "status code":response.status_code,
            "status":
                'Not found (either the URL is incorrect or the controller is starting).'
                if response.status_code == 404 else
                'Service unavailable (allow 5 or 10 minutes for controller to become ready)'
                if response.status_code == 503 else
                'OK'
                if response.status_code == 200 else
                'Unknown',
            "method":response.request.method,
            "url":response.url}
        render.print_table(outcome)
    except Exception as e:
        print(e, file=stderr)
コード例 #12
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
コード例 #13
0
def demonstrate_all(device_name):
    """
    Apply function 'static_route_json' to the specified device without 
    specifying a static route destination.

    Return a list of static route destination networks (may be empty).
    """
    print('Request all static routes.')
    print('static_route_json(%s)' % device_name)
    route_list = static_route_json(device_name)
    if not route_list:
        print(None)
        print()
        return []

    print_table([
        OrderedDict([("device", device_name),
                     ("destination",
                      "%s/%s" % (route['prefix'], route['prefix-length'])),
                     ("next-hop", next_hop_address(route))])
        for route in route_list
    ])
    print()
    return [
        ip_network("%s/%s" % (route['prefix'], route['prefix-length']))
        for route in route_list
    ]
コード例 #14
0
def demonstrate_all(device_name):
    """ Obtain, print and return the properties of all network interfaces on the specified device."""
    print("Apply function 'interface_properties' to a network device.")
    print('interface_properties(%s)' % device_name)
    interface_properties_list = interface_properties(device_name)
    print_table(interface_properties_list)
    print()
    return [properties.name for properties in interface_properties_list]
コード例 #15
0
def demonstrate():
    """
    Apply function 'inventory_static_route' to the inventory of network devices.
    """
    print('inventory_static_route()')
    device_names = inventory_static_route()
    print_table(device_names, headers=('device-name',))
    return device_names
コード例 #16
0
def demonstrate_all(device_name):
    """ Obtain, print and return the properties of all network interfaces on the specified device."""
    print("Apply function 'interface_properties' to a network device.")
    print('interface_properties(%s)' % device_name)
    interface_properties_list = interface_properties(device_name)
    print_table(interface_properties_list)
    print()
    return [properties.name for properties in interface_properties_list]
コード例 #17
0
def demonstrate_one(device_name, interface_name):
    """ Obtain, print and return the properties of the specified interface on the specified device."""
    print("Apply function 'interface_properties' to both a network interface and a network device.")
    print('interface_properties(%s, %s)' % (device_name, interface_name))
    properties = interface_properties(device_name, interface_name)
    print_table(properties)
    print()
    return 
コード例 #18
0
def demonstrate():
    """ Apply function 'capability_discovery' to the specified device for required capability. """
    print("capability_discovery(capability_name=%s, capability_ns=%s)" % (capability_name, capability_ns))
    discoveries = capability_discovery(capability_name=capability_name, capability_ns=capability_ns)
    print_table(
        [(discovered.device_name, discovered.capability.revision) for discovered in discoveries],
        headers=("device-name", "revision"),
    )
    return discoveries
コード例 #19
0
def demonstrate():
    ''' Apply function 'capability_discovery' to the specified device for required capability. '''
    print('capability_discovery(capability_name=%s, capability_ns=%s)' %
          (capability_name, capability_ns))
    discoveries = capability_discovery(capability_name=capability_name,
                                       capability_ns=capability_ns)
    print_table([(discovered.device_name, discovered.capability.revision)
                 for discovered in discoveries],
                headers=('device-name', 'revision'))
    return discoveries
コード例 #20
0
def demonstrate_by_capability(capability_name, capability_namespace):
    print()
    print('2. Discover which network devices are capable of a specific task.')
    print('For each task that will be performed by an application, the appropriate \ncapability must be determined.')
    print('For convenience, this demonstration chooses any one capability \nand searches for devices that are capable.')
    print()
    print('capability_discovery(%s, %s)' % (capability_name, capability_namespace))
    discoveries = capability_discovery(capability_name, capability_namespace)
    print_table([(discovered.device_name, discovered.capability.revision) for discovered in discoveries], 
                headers=('device-name', 'capability-revision'))
コード例 #21
0
def demonstrate_one(device_name, destination_network):
    """
    Apply function 'static_route_delete' to the specified device and destination.
    """
    print('static_route_delete(%s, %s)' % (device_name, destination_network))
    static_route_delete(device_name, destination_network)
    print()

    print('static_route_list(%s)' % device_name)
    print_table(static_route_list(device_name), headers='destination-network')
コード例 #22
0
def demonstrate_one(device_name, interface_name):
    """ Obtain, print and return the properties of the specified interface on the specified device."""
    print(
        "Apply function 'interface_properties' to both a network interface and a network device."
    )
    print('interface_properties(%s, %s)' % (device_name, interface_name))
    properties = interface_properties(device_name, interface_name)
    print_table(properties)
    print()
    return
コード例 #23
0
def demonstrate_one(device_name, destination_network):
    """
    Apply function 'static_route_delete' to the specified device and destination.
    """
    print('static_route_delete(%s, %s)' % (device_name, destination_network))
    static_route_delete(device_name, destination_network)
    print()

    print('static_route_list(%s)' % device_name)
    print_table(static_route_list(device_name), headers='destination-network')
コード例 #24
0
def demonstrate_all(device_name):
    """
    Apply function 'static_route_delete' to all routes on the specified device.
    """
    print()
    print('static_route_delete(%s)' % device_name)
    static_route_delete(device_name)

    print()
    print('static_route_list(%s)' % device_name)
    print_table(static_route_list(device_name), headers='destination-network')
コード例 #25
0
def demonstrate_all(device_name):
    """
    Apply function 'static_route_delete' to all routes on the specified device.
    """
    print()
    print('static_route_delete(%s)' % device_name)
    static_route_delete(device_name)

    print()
    print('static_route_list(%s)' % device_name)
    print_table(static_route_list(device_name), headers='destination-network')
コード例 #26
0
def demonstrate(device_name):
    """
    Apply function 'static_route_list' to the specified device.
    
    Return True when one or more routes are found.
    """
    print('static_route_list(%s)' % device_name)
    routes = static_route_list(device_name)
    print_table(routes, headers='destination-network')
    print()
    return bool(routes)
コード例 #27
0
def demonstrate(device_name):
    """
    Apply function 'static_route_list' to the specified device.
    
    Return True when one or more routes are found.
    """
    print('static_route_list(%s)' % device_name)
    routes = static_route_list(device_name)
    print_table(routes, headers='destination-network')
    print()
    return bool(routes)
コード例 #28
0
def demonstrate_not_found():
    print()
    print('3. Attempt discovery of a capability that is unavailable.')
    print('If there are no capable devices then an empty list is returned.')
    print('This is demonstrated using a capability that is known to be unavailable.')
    print()
    capability_name = 'teleport'
    capability_namespace = 'http://startrek.com/ns/yang/'
    print('capability_discovery(%s, %s)' % (capability_name, capability_namespace))
    discoveries = capability_discovery(capability_name, capability_namespace)
    print_table([(discovered.device_name, discovered.capability.revision) for discovered in discoveries], 
                headers=('device-name', 'capability-revision'))
コード例 #29
0
def demonstrate(device_name):
    """ Discover, print and return the capabilities of the specified network device."""
    print()
    print("2. Discover all capabilities of the chosen network device.")
    print('capability_discovery(device_name=%s)' % device_name)
    discoveries = capability_discovery(device_name=device_name)
    
    # Discard the outer tuples because they are redundant.     
    capabilities = [discovered.capability for discovered in discoveries]
    capabilities.sort()
    print_table(capabilities)
    return capabilities
コード例 #30
0
def demonstrate(device_name):
    """ Discover, print and return the capabilities of the specified network device."""
    print()
    print("2. Discover all capabilities of the chosen network device.")
    print('capability_discovery(device_name=%s)' % device_name)
    discoveries = capability_discovery(device_name=device_name)
    
    # Discard the outer tuples because they are redundant.     
    capabilities = [discovered.capability for discovered in discoveries]
    capabilities.sort()
    print_table(capabilities)
    return capabilities
コード例 #31
0
def demonstrate():
    ''' Apply function 'capability_discovery' to the specified device for required capability. '''
    print('capability_discovery(capability_name=%s, capability_ns=%s)' % (capability_name, capability_ns))
    discoveries = capability_discovery(capability_name=capability_name, capability_ns=capability_ns)
    print_table([(
            discovered.device_name, 
            discovered.capability.revision
        ) for discovered in discoveries], headers=(
            'device-name',
            'revision'
        ))
    return discoveries
コード例 #32
0
def main():
    # It is essential to import module 'settings' because it injects the
    # Controller settings into attribute 'odl_http.coordinates'.
    # The code below references module 'settings' to prevent it from
    # being auto-removed due to an 'unused import' warning.
    if not settings:
        print('Settings must be configured', file=stderr)

    render.print_table(odl_http.coordinates)
    print()

    try:
        print('Connecting...')
        url = 'http://localhost:8181/restconf/operational/opendaylight-inventory:nodes/node/openflow:1'

        my_response = requests.get(url, auth=HTTPBasicAuth('admin', 'admin'))
        """
        values = {'username':'******', 'password':'******'}
        data = urllib.urlencode(values)
        req = urllib2.Request(url,data)
        web_content = urllib2.urlopen(req).read()
        print(web_content)
        """
        print(my_response)

        response = odl_http.odl_http_head(
            # Use any URL that is likely to succeed.
            url_suffix=
            'operational/opendaylight-inventory:nodes/node/openflow:1',
            accept='application/json',
            expected_status_code=[200, 404, 503])
        print(response)

        outcome = {
            "status code":
            response.status_code,
            "status":
            'Not found (either the URL is incorrect or the controller is starting).'
            if response.status_code == 404 else
            'Service unavailable (allow 5 or 10 minutes for controller to become ready)'
            if response.status_code == 503 else
            'OK' if response.status_code == 200 else 'Unknown',
            "method":
            response.request.method,
            "url":
            response.url
        }
        render.print_table(outcome)
    except Exception as e:
        print(e, file=stderr)
コード例 #33
0
def demonstrate_all():
    print()
    print('1. Discover all capabilities of all network devices.')
    print('Display summaries because the entire list is too long.')
    print('capability_discovery()')
    discoveries = capability_discovery()
    capabilities = set(discovered.capability for discovered in discoveries)
    device_names = set([discovered.device_name for discovered in discoveries])

    capability_by_device = lambda device_name: [discovered.capability for discovered in discoveries if discovered.device_name == device_name]
    device_by_capability_name = lambda capability_name: set([discovered.device_name for discovered in discoveries if discovered.capability.name == capability_name])
    capability_revision_by_name = lambda capability_name: set([capability.revision for capability in capabilities if capability.name == capability_name])
    capability_name_by_revision = lambda capability_revision: set([capability.name for capability in capabilities if capability.revision == capability_revision])
    capability_namespace_by_name = lambda capability_name: set([capability.namespace for capability in capabilities if capability.name == capability_name])
    capability_name_by_namespace = lambda capability_namespace: set([capability.name for capability in capabilities if capability.namespace == capability_namespace])
    capability_revision_by_namespace = lambda capability_namespace: set([capability.revision for capability in capabilities if capability.namespace == capability_namespace])
    
    summary = [(device_name, len(capability_by_device(device_name))) for device_name in device_names]
    summary.sort()
    print()
    print_table(summary, headers=('device name', '# capabilities'))
    
    capability_names = set([capability.name for capability in capabilities])
    summary = [(
            capability_name, 
            len(device_by_capability_name(capability_name)), 
            len(capability_revision_by_name(capability_name)),
            len(capability_namespace_by_name(capability_name))
        ) for capability_name in capability_names]
    summary.sort()
    print()
    print_table(summary, headers=('capability name', '# devices', '# revisions', '# name-spaces'))

    print()
    print('The following summaries consider each capability only once, ')
    print('regardless of how many network devices have that capability.')

    capability_revisions = set([capability.revision for capability in capabilities])
    summary = [(revision, len(capability_name_by_revision(revision))) for revision in capability_revisions]
    summary.sort()
    print()
    print('Display revisions of capabilities in sorted order (often chronological).')
    print_table(summary, headers=('capability revision', '# capabilities'))

    capability_namespaces = set([capability.namespace for capability in capabilities])
    summary = [(
            namespace, 
            len(capability_name_by_namespace(namespace)),
            len(capability_revision_by_namespace(namespace))
        ) for namespace in capability_namespaces]
    summary.sort()
    print()
    print('Display name-spaces of capabilities in sorted order.')
    print()
    print_table(summary, headers=('capability name-space', '# capabilities', '# revisions'))

    print()
    print('Note that all the information contained in the multiple summaries, above, \nwas obtained with a single HTTP request (RPC) to the Controller.')
    return discoveries
コード例 #34
0
def demonstrate_not_found():
    print()
    print('3. Attempt discovery of a capability that is unavailable.')
    print('If there are no capable devices then an empty list is returned.')
    print(
        'This is demonstrated using a capability that is known to be unavailable.'
    )
    print()
    capability_name = 'teleport'
    capability_namespace = 'http://startrek.com/ns/yang/'
    print('capability_discovery(%s, %s)' %
          (capability_name, capability_namespace))
    discoveries = capability_discovery(capability_name, capability_namespace)
    print_table([(discovered.device_name, discovered.capability.revision)
                 for discovered in discoveries],
                headers=('device-name', 'capability-revision'))
コード例 #35
0
def demonstrate_by_capability(capability_name, capability_namespace):
    print()
    print('2. Discover which network devices are capable of a specific task.')
    print(
        'For each task that will be performed by an application, the appropriate \ncapability must be determined.'
    )
    print(
        'For convenience, this demonstration chooses any one capability \nand searches for devices that are capable.'
    )
    print()
    print('capability_discovery(%s, %s)' %
          (capability_name, capability_namespace))
    discoveries = capability_discovery(capability_name, capability_namespace)
    print_table([(discovered.device_name, discovered.capability.revision)
                 for discovered in discoveries],
                headers=('device-name', 'capability-revision'))
コード例 #36
0
def main():
    """ Select a device/interface and demonstrate."""
    print(cleandoc(__doc__))
    print()
    
    print('Determine which network devices are capable.')
    device_names = inventory_connected()
    print_table(device_names, headers='device-name')
    print()
    for device_name in device_names:
        interface_names = demonstrate_all(device_name)
        if interface_names:
            demonstrate_one(device_name, interface_names[0])
            return EX_OK
    print("There are no suitable network devices and interfaces. Demonstration cancelled.")
    return EX_TEMPFAIL
コード例 #37
0
def main():
    print(cleandoc(__doc__))
    print()
    print('1. Determine the inventory of network devices and choose one.')
    print('inventory_mounted()')
    device_names = inventory_mounted()
    if not device_names:
        print("There are no mounted network devices. Demonstration cancelled.")
        return EX_TEMPFAIL
    else:
        print_table(device_names, headers='device-name')
    for device_name in inventory_mounted():
        capabilities = demonstrate(device_name)
        if capabilities:
            return EX_OK
    print()
    print("No capabilities were discovered. Demonstration incomplete.")
    return EX_TEMPFAIL
コード例 #38
0
def main():
    print(cleandoc(__doc__))
    print()
    print('1. Determine the inventory of network devices and choose one.')
    print('inventory_mounted()')
    device_names = inventory_mounted()
    if not device_names:
        print("There are no mounted network devices. Demonstration cancelled.")
        return EX_TEMPFAIL
    else:
        print_table(device_names, headers='device-name')
    for device_name in inventory_mounted():
        capabilities = demonstrate(device_name)
        if capabilities:
            return EX_OK
    print()
    print("No capabilities were discovered. Demonstration incomplete.")
    return EX_TEMPFAIL
コード例 #39
0
def main():
    """ Select a device/interface and demonstrate."""
    print(cleandoc(__doc__))
    print()

    print('Determine which network devices are capable.')
    device_names = inventory_connected()
    print_table(device_names, headers='device-name')
    print()
    for device_name in device_names:
        interface_names = demonstrate_all(device_name)
        if interface_names:
            demonstrate_one(device_name, interface_names[0])
            return EX_OK
    print(
        "There are no suitable network devices and interfaces. Demonstration cancelled."
    )
    return EX_TEMPFAIL
コード例 #40
0
def main():
    if not settings:
        print('Settings must be configured', file=stderr)

    render.print_table(odl_http.coordinates)
    print()

    config = {
        "add-flow": {
            "input": {
                "flow-ref": "1",
                "transaction-uri": "1",
                "flow-table": "1",
                "container-name": "1",
                "cookie_mask": "1",
                "buffer_id": "1",
                "out_port": "1",
                "out_group": "1",
                "flags": "CHECK_OVERLAP",
                "flow-name": "1",
                "installHw": "true",
                "barrier": "true",
                "strict": "true",
                "priority": "1",
                "idle-timeout": "1",
                "hard-timeout": "1",
                "cookie": "1",
                "table_id": "1",
                "node": "1"
            }
        }
    }

    config_str = json.dumps(config)
    try:
        response = odl_http_put(
            url_suffix=
            'http://127.0.0.1:8181/restconf/operations/sal-flow:add-flow',
            url_params={},
            contentType='application/json',
            content=config_str)
        print(response)
    except Exception as e:
        print(e, file=stderr)
コード例 #41
0
def main():
    if not settings:
        print('Settings must be configured', file=stderr)
    
    render.print_table(odl_http.coordinates)
    print()
    
    config = {
    "add-flow": {
        "input": {
            "flow-ref": "1",
            "transaction-uri": "1",
            "flow-table": "1",
            "container-name": "1",
            "cookie_mask": "1",
            "buffer_id": "1",
            "out_port": "1",
            "out_group": "1",
            "flags": "CHECK_OVERLAP",
            "flow-name": "1",
            "installHw": "true",
            "barrier": "true",
            "strict": "true",
            "priority": "1",
            "idle-timeout": "1",
            "hard-timeout": "1",
            "cookie": "1",
            "table_id": "1",
            "node": "1"
             }
            }
     }
    
    config_str = json.dumps(config)
    try:
        response = odl_http_put(
                      url_suffix='http://127.0.0.1:8181/restconf/operations/sal-flow:add-flow',
                      url_params={},
                      contentType='application/json',
                      content=config_str)
        print(response)
    except Exception as e:
        print(e, file=stderr)
コード例 #42
0
def main():
    """
    Print the function's documentation then demonstrate the function multiple times on one device.
    """
    print(plain(doc(static_route_exists)))
    
    print('Determine which devices are capable.')
    print('inventory_static_route()')
    device_names = inventory_static_route()
    print_table(device_names, headers='device-name')
    print()

    if not device_names:
        print("There are no 'static route' capable devices to examine. Demonstration cancelled.")
    else:
        for device_name in device_names:
            if demonstrate(device_name):
                return EX_OK
    return EX_TEMPFAIL
コード例 #43
0
def main():
    """
    Print the function's documentation then demonstrate the function once.
    """
    print(cleandoc(__doc__))
    print()
    print(plain(doc(static_route_create)))

    print('Determine which network devices are capable.')
    print('inventory_static_route()')
    device_names = inventory_static_route()
    print_table(device_names, headers='device-name')
    print()
    if not device_names:
        print("There are no 'static route' capable devices to examine. Demonstration cancelled.")
    else:
        for device_name in device_names:
            if demonstrate(device_name):
                return EX_OK
    print("Unable to create a 'static route' on %s capable device(s). Demonstration cancelled." % len(device_names))
    return EX_TEMPFAIL
コード例 #44
0
def main():
    """ 
    Print the function documentation then demonstrate the function usage on a selected device.
     
    Repeat for another device if no 'static route' is configured.
    """
    print(plain(doc(static_route_list)))

    print('Determine which devices are capable.')
    print('inventory_static_route()')
    device_names = inventory_static_route()
    if not device_names:
        print("There are no 'static route' capable devices to examine. Demonstration cancelled.")
    else:
        print_table(device_names, headers='device-name')
        print()
        for device_name in device_names:
            if demonstrate(device_name):
                return EX_OK
        print("There are no devices with a 'static route' configured. Demonstration cancelled.")
    return EX_TEMPFAIL
コード例 #45
0
def main():
    """
    Print the function's documentation then demonstrate the function once.
    """
    print(cleandoc(__doc__))
    print()
    print(plain(doc(static_route_create)))

    print('Determine which network devices are capable.')
    print('inventory_static_route()')
    device_names = inventory_static_route()
    print_table(device_names, headers='device-name')
    print()
    if not device_names:
        print("There are no 'static route' capable devices to examine. Demonstration cancelled.")
    else:
        for device_name in device_names:
            if demonstrate(device_name):
                return EX_OK
    print("Unable to create a 'static route' on %s capable device(s). Demonstration cancelled." % len(device_names))
    return EX_TEMPFAIL
コード例 #46
0
def main():
    """
    Print the function's documentation then demonstrate the function multiple times on one device.
    """
    print(plain(doc(static_route_exists)))

    print('Determine which devices are capable.')
    print('inventory_static_route()')
    device_names = inventory_static_route()
    print_table(device_names, headers='device-name')
    print()

    if not device_names:
        print(
            "There are no 'static route' capable devices to examine. Demonstration cancelled."
        )
    else:
        for device_name in device_names:
            if demonstrate(device_name):
                return EX_OK
    return EX_TEMPFAIL
コード例 #47
0
def demonstrate_all(device_name):
    """
    Apply function 'static_route_json' to the specified device without 
    specifying a static route destination.

    Return a list of static route destination networks (may be empty).
    """
    print('Request all static routes.')
    print('static_route_json(%s)' % device_name)
    route_list = static_route_json(device_name)
    if not route_list:
        print(None)
        print()
        return []
    
    print_table([OrderedDict([
            ("device", device_name),
            ("destination", "%s/%s" % (route['prefix'], route['prefix-length'])),
            ("next-hop", next_hop_address(route))
        ]) for route in route_list
    ])
    print()
    return [ip_network("%s/%s" % (route['prefix'], route['prefix-length'])) for route in route_list]
コード例 #48
0
def main():
    """ 
    Print the documentation then perform the demonstration(s).
    """
    print(plain(doc(static_route_json)))

    print('Determine which devices are capable.')
    print('inventory_static_route()')
    inventory = inventory_static_route()
    if not inventory:
        print(None)
        print("There are no 'static route' capable devices. Demonstration cancelled.")
    else:
        print_table(inventory)
        print()
        for device_name in inventory:
            route_list = demonstrate_all(device_name)
            if route_list:
                return EX_OK if demonstrate_one(device_name, route_list[0]) else EX_TEMPFAIL
            else:
                print()
        print("There are no devices with a 'static route' configured. Demonstration cancelled.")
    return EX_TEMPFAIL
コード例 #49
0
def demonstrate(discoveries):
    # Structure of map is {capability-id : revision-by-device}
    # where capability-id is (capability-name, capability-namespace)
    # and revision-by-device is {device-name : capability-revision}.   
    revision_by_capability = {}
    device_names = set()
    
    # Visit each discovery once and collect the capability identifier as a key
    # and the capability revision as a (nested) value.
    # During this single pass of discoveries, collect device names too.
    for discovered in discoveries:
        capability_id = (discovered.capability.name, discovered.capability.namespace)
        revision_by_device = revision_by_capability.get(capability_id, {})
        if not revision_by_device:
            revision_by_capability[capability_id] = revision_by_device
        revision_by_device[discovered.device_name] = discovered.capability.revision
        device_names.add(discovered.device_name)
        
    # Order the devices alphabetically by name.
    # This makes the column order deterministic.              
    device_names = sorted(device_names)

    # Flatten the dict into a 2D table.     
    # Structure of table is [row, ...]
    # where row is (capability-name, capability-namespace, revision, ...)
    # where revision, ... is ordered list of one revision per device.               
    table = [
        tuple(chain(capability_id, [revision_by_device.get(device_name, '') for device_name in device_names]))             
        for (capability_id, revision_by_device) in revision_by_capability.items()
    ]
    
    # Order the table by capability name.     
    # This makes the row order deterministic.              
    table.sort()
    headers = tuple(chain(('capability-name', 'capability-namespace'), device_names))
    print_table(table, headers=headers)
コード例 #50
0
def main():
    device_list = settings.config['network_device']
    connected_list = topology.connected_nodes()

    if len(connected_list) != len(device_list):
        print('not all devices are connected!')
        return

    device_1 = 'iosxrv-1'
    device_2 = 'iosxrv-2'
    device_3 = 'iosxrv-3'
    device_4 = 'iosxrv-4'
    device_5 = 'iosxrv-5'
    device_6 = 'iosxrv-6'
    device_7 = 'iosxrv-7'
    device_8 = 'iosxrv-8'
    interface_0 = 'GigabitEthernet0/0/0/0'
    interface_1 = 'GigabitEthernet0/0/0/1'
    interface_2 = 'GigabitEthernet0/0/0/2'
    interface_3 = 'GigabitEthernet0/0/0/3'
    interface_4 = 'GigabitEthernet0/0/0/4'
    interface_5 = 'GigabitEthernet0/0/0/5'
    interface_6 = 'GigabitEthernet0/0/0/6'

    #add static route for flow 1
    destination_network = to_ip_network('100.0.0.0', '24')
    #device_1
    next_hop_address = '10.0.12.2'
    discription = 'for flow 1: to device_2'
    add_static_route(device_1, destination_network, next_hop_address,
                     discription, 0)
    #device_2
    next_hop_address = '198.18.1.34'
    discription = 'for flow 1: to device_5'
    add_static_route(device_2, destination_network, next_hop_address,
                     discription, 0)
    #device_8
    next_hop_address = '10.0.28.2'
    discription = 'for flow 1: to device_2'
    add_static_route(device_8, destination_network, next_hop_address,
                     discription, 0)
    #display
    print('add route for flow 1 (to 100.0.0.0/24): ', device_8, ' -> ',
          device_2)

    #add static route for flow 2
    destination_network = to_ip_network('200.0.0.0', '24')
    #device_1
    next_hop_address = '10.0.12.2'
    discription = 'for flow 2: to device_2'
    add_static_route(device_1, destination_network, next_hop_address,
                     discription, 0)
    #device_2
    next_hop_address = '198.18.1.34'
    discription = 'for flow 2: to device_5'
    add_static_route(device_2, destination_network, next_hop_address,
                     discription, 0)
    #device_8
    next_hop_address = '10.0.18.1'
    discription = 'for flow 2: to device_1'
    add_static_route(device_8, destination_network, next_hop_address,
                     discription, 0)
    #display
    print('add route for flow 2 (to 200.0.0.0/24): ', device_8, ' -> ',
          device_1, ' -> ', device_2)

    #add static route for flow 3
    destination_network = to_ip_network('50.0.0.0', '24')
    next_hop_address = '198.18.1.32'
    discription = 'for flow 3: to device_3'
    add_static_route(device_8, destination_network, next_hop_address,
                     discription, 0)
    #display
    print('add route for flow 3 (to 50.0.0.0/24): ', device_8,
          ' -> black_hole')

    #display static route
    print('\n')
    routes = static_route_list(device_8)
    print('static route table', device_8)
    print_table(routes)
コード例 #51
0
def main():
    print(plain(doc(inventory_not_connected)))
    print("inventory_not_connected()")
    print_table(inventory_not_connected())
コード例 #52
0
def main():
    print(plain(doc(inventory_not_connected)))
    print("inventory_not_connected()")
    print_table(inventory_not_connected(), headers='device-name')
コード例 #53
0
from __future__ import print_function as _print_function
import settings
from basics.odl_http import coordinates as odl_coordinates, odl_http_head
from sys import stderr
from basics.context import sys_exit, EX_OK, EX_CONFIG
from basics.render import print_table

if __name__ == "__main__":
    # It is essential to import module 'settings' because it injects the
    # Controller settings into attribute 'odl_http.coordinates'.
    # The code below references module 'settings' to prevent it from
    # being auto-removed due to an 'unused import' warning.
    if not settings:
        print('Settings must be configured', file=stderr)

    print_table(odl_coordinates)
    print()

    try:
        print('Connecting...')
        response = odl_http_head(
            # Use any URL that is likely to succeed.
            url_suffix='operational/opendaylight-inventory:nodes',
            accept='application/json',
            expected_status_code=[200, 404, 503])
        outcome = {
            "status code":
            response.status_code,
            "status":
            'Not found (either the URL is incorrect or the controller is starting).'
            if response.status_code == 404 else
コード例 #54
0
def main():   
    device_list=settings.config['network_device']
    connected_list = topology.connected_nodes()
    
    if len(connected_list) != len(device_list):
        print('not all devices are connected!')
        return
    
    device_1 = 'iosxrv-1'
    device_2 = 'iosxrv-2'
    device_3 = 'iosxrv-3'
    device_4 = 'iosxrv-4'
    device_5 = 'iosxrv-5'
    device_6 = 'iosxrv-6'
    device_7 = 'iosxrv-7'
    device_8 = 'iosxrv-8'
    interface_0 = 'GigabitEthernet0/0/0/0'
    interface_1 = 'GigabitEthernet0/0/0/1'
    interface_2 = 'GigabitEthernet0/0/0/2'
    interface_3 = 'GigabitEthernet0/0/0/3'
    interface_4 = 'GigabitEthernet0/0/0/4'
    interface_5 = 'GigabitEthernet0/0/0/5'
    interface_6 = 'GigabitEthernet0/0/0/6'
    
    #link device_1 to device_2
    initial = interface_configuration_tuple(device_1, interface_0)
    #print_table(initial)
    ip_address = '10.0.12.1'
    ip_netmask = '255.255.255.0'
    description = 'connect to device_2'
    interface_configuration_update(device_1, initial.name, description=description, address=ip_address, netmask=ip_netmask, shutdown=False)
    print_table(interface_configuration_tuple(device_1, interface_0))
    #link device_2 to device_1
    initial = interface_configuration_tuple(device_2, interface_0)
    #print_table(initial)
    ip_address = '10.0.12.2'
    ip_netmask = '255.255.255.0'
    description = 'connect to device_1'
    interface_configuration_update(device_2, initial.name, description=description, address=ip_address, netmask=ip_netmask, shutdown=False)
    print_table(interface_configuration_tuple(device_2, interface_0))
    #display
    print('set link device_1 <-> device_2')
    
    #link device_1 to device_8
    initial = interface_configuration_tuple(device_1, interface_5)
    #print_table(initial)
    ip_address = '10.0.18.1'
    ip_netmask = '255.255.255.0'
    description = 'connect to device_8'
    interface_configuration_update(device_1, initial.name, description=description, address=ip_address, netmask=ip_netmask, shutdown=False)
    print_table(interface_configuration_tuple(device_1, interface_5))
    #link device_8 to device_1
    initial = interface_configuration_tuple(device_8, interface_1)
    #print_table(initial)
    ip_address = '10.0.18.8'
    ip_netmask = '255.255.255.0'
    description = 'connect to device_1'
    interface_configuration_update(device_8, initial.name, description=description, address=ip_address, netmask=ip_netmask, shutdown=False)
    print_table(interface_configuration_tuple(device_8, interface_1))
    #display
    print('set link device_1 <-> device_8')
    
    #link device_2 to device_8
    initial = interface_configuration_tuple(device_2, interface_2)
    #print_table(initial)
    ip_address = '10.0.28.2'
    ip_netmask = '255.255.255.0'
    description = 'connect to device_8'
    interface_configuration_update(device_2, initial.name, description=description, address=ip_address, netmask=ip_netmask, shutdown=False)
    print_table(interface_configuration_tuple(device_2, interface_2))
    #link device_8 to device_2
    initial = interface_configuration_tuple(device_8, interface_2)
    #print_table(initial)
    ip_address = '10.0.28.8'
    ip_netmask = '255.255.255.0'
    description = 'connect to device_2'
    interface_configuration_update(device_8, initial.name, description=description, address=ip_address, netmask=ip_netmask, shutdown=False)
    print_table(interface_configuration_tuple(device_8, interface_2))
    #display
    print('set link device_2 <-> device_8')
コード例 #55
0
from __future__ import print_function as _print_function
import settings 
from basics.odl_http import coordinates as odl_coordinates, odl_http_head
from sys import stderr
from basics.interpreter import sys_exit, EX_OK, EX_CONFIG
from basics.render import print_table

if __name__ == "__main__":
    # It is essential to import module 'settings' because it injects the
    # Controller settings into attribute 'odl_http.coordinates'.     
    # The code below references module 'settings' to prevent it from
    # being auto-removed due to an 'unused import' warning.
    if not settings:
        print('Settings must be configured', file=stderr)
    
    print_table(odl_coordinates)
    print()
    
    try:
        print('Connecting...')
        response = odl_http_head(
            # Use any URL that is likely to succeed.                                   
            url_suffix='operational/opendaylight-inventory:nodes',
            accept='application/json',
            expected_status_code=[200, 404, 503])
        outcome = {
            "status code":response.status_code,
            "status":
                'Not found (either the URL is incorrect or the controller is starting).'
                if response.status_code == 404 else
                'Service unavailable (allow 5 or 10 minutes for controller to become ready)'
コード例 #56
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))
コード例 #57
0
def main():
    print(plain(doc(inventory_summary)))
    print('InventorySummary fields:', *InventorySummary._fields, sep='\n\t', end='\n\n')
    print_table(inventory_summary())
コード例 #58
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))