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
def test_discover_none(self): self.assertFalse(mounted(unmounted_device_name)) discoveries = capability_discovery(device_name=unmounted_device_name) self.assertFalse(discoveries, "Expected no capabilities for unmounted device.") discoveries = capability_discovery(capability_name=fictional_capability_name) self.assertFalse(discoveries, "Expected to find zero fictional capabilities.") discoveries = capability_discovery(capability_ns=fictional_capability_namespace) self.assertFalse(discoveries, "Expected to find no capabilities for fictional name-space.") discoveries = capability_discovery(capability_revision=fictional_capability_revision) self.assertFalse(discoveries, "Expected to find no capabilities for fictional revision.") device_names = inventory_connected() self.assertTrue(device_names, "Expected at least one connected device.") device_name = device_names[0] discoveries = capability_discovery(device_name=device_name, capability_name=fictional_capability_name) self.assertFalse(discoveries, "Expected to find zero fictional capabilities.") discoveries = capability_discovery(device_name=device_name, capability_ns=fictional_capability_namespace) self.assertFalse(discoveries, "Expected to find no capabilities for fictional name-space.") discoveries = capability_discovery(device_name=device_name, capability_revision=fictional_capability_revision) self.assertFalse(discoveries, "Expected to find no capabilities for fictional revision.")
def demonstrate(capability_name, capability_namespace): print() print('capability_discovery(%s, %s)' % (capability_name, capability_namespace), end=':\n') capable_list = capability_discovery(capability_name, capability_namespace) if not capable_list: print('\t',None) else: for capable in capable_list: print('\t', capable[0], capable[1][2])
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
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'))
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
def demonstrate(device_name): ''' Apply function 'capability_discovery' to the specified device for required capability. ''' print('\ncapability_discovery(device_name=%s, capability_name=%s, capability_ns=%s)' % (device_name, capability_name, capability_ns)) discovered = capability_discovery(device_name=device_name, capability_name=capability_name, capability_ns=capability_ns) if discovered: print(*discovered) return True else: print(None) return False
def main(): print(cleandoc(__doc__)) print() print('capability_discovery()') discoveries = capability_discovery() if not discoveries: print("There are no capable network devices. Demonstration cancelled.") return EX_TEMPFAIL demonstrate(discoveries) return EX_OK
def demonstrate(capability_name, capability_namespace): print() print('capability_discovery(%s, %s)' % (capability_name, capability_namespace), end=':\n') capable_list = capability_discovery(capability_name, capability_namespace) if not capable_list: print('\t', None) else: for capable in capable_list: print('\t', capable[0], capable[1][2])
def demonstrate(device_name): ''' Apply function 'capability_discovery' to the specified device for required capability. ''' print() print('capability_discovery(device_name=%s, capability_name=%s, capability_ns=%s)' % (device_name, capability_name, capability_ns)) discovered = capability_discovery(device_name=device_name, capability_name=capability_name, capability_ns=capability_ns) if discovered: print('\t', *discovered) return True else: print(None) return False
def inventory_acl(capability_revision=None, device_name=None): """ Determine which devices have ACL capability. A specific revision of the capability is optional. The discovery process can be scoped to a single device. Returns a list of device names. """ discovered = capability_discovery(capability_name=capability_name, capability_ns=capability_ns, capability_revision=capability_revision, device_name=device_name) return [device_capability[0] for device_capability in discovered]
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'))
def inventory_static_route(capability_revision=None, device_name=None): """ Determine which devices have 'static route' capability. A specific revision of the capability is optional. The discovery process can be scoped to a single device. Returns a list of device names. """ discoveries = capability_discovery(capability_name=capability_name, capability_ns=capability_ns, capability_revision=capability_revision, device_name=device_name) return [discovered.device_name for discovered in discoveries]
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
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
def inventory_acl(capability_revision=None, device_name=None): """ Determine which devices have ACL capability. A specific revision of the capability is optional. The discovery process can be scoped to a single device. Returns a list of device names. """ discovered= capability_discovery( capability_name=capability_name, capability_ns=capability_ns, capability_revision=capability_revision, device_name=device_name) return [device_capability[0] for device_capability in discovered]
def inventory_static_route(capability_revision=None, device_name=None): """ Determine which devices have 'static route' capability. A specific revision of the capability is optional. The discovery process can be scoped to a single device. Returns a list of device names. """ discoveries = capability_discovery( capability_name=capability_name, capability_ns=capability_ns, capability_revision=capability_revision, device_name=device_name, ) return [discovered.device_name for discovered in discoveries]
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'))
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'))
def test_discover_all(self): discoveries = capability_discovery() self.assertTrue(discoveries, "Expected one or more capable devices.") device_names = set([discovered.device_name for discovered in discoveries]) capability_names = set([discovered.capability.name for discovered in discoveries]) capability_namespaces = set([discovered.capability.namespace for discovered in discoveries]) capability_revisions = set([discovered.capability.revision for discovered in discoveries]) capabilities = set([discovered.capability for discovered in discoveries]) for discovered in discoveries[0:10]: rediscover = capability_discovery( device_name=discovered.device_name, capability_name=discovered.capability.name, capability_ns=discovered.capability.namespace, capability_revision=discovered.capability.revision, ) self.assertEqual(1, len(rediscover), "Expected discovery of %s" % str(discovered)) self.assertEqual(discovered, rediscover[0]) for device_name in sorted(device_names)[0:10]: rediscover = capability_discovery(device_name=device_name) self.assertTrue(rediscover, "Expected device to have capabilities: %s" % device_name) for capability_name in sorted(capability_names)[0:10]: rediscover = capability_discovery(capability_name=capability_name) self.assertTrue(rediscover, "Expected discovery of capability by name %s" % capability_name) for capability_namespace in sorted(capability_namespaces)[0:10]: rediscover = capability_discovery(capability_ns=capability_namespace) self.assertTrue(rediscover, "Expected discovery of capability by name-space %s" % capability_namespace) for capability_revision in sorted(capability_revisions)[0:10]: rediscover = capability_discovery(capability_revision=capability_revision) self.assertTrue(rediscover, "Expected discovery of capability by revision %s" % capability_revision) for capability in sorted(capabilities)[0:10]: rediscover = capability_discovery( capability_name=capability.name, capability_ns=capability.namespace, capability_revision=capability.revision, ) self.assertTrue(rediscover, "Expected discovery of capability %s" % str(capability)) self.assertEqual(capability, rediscover[0].capability)
def test_discover_all(self): discoveries = capability_discovery() self.assertTrue(discoveries, "Expected one or more capable devices.") device_names = set([discovered.device_name for discovered in discoveries]) capability_names = set([discovered.capability.name for discovered in discoveries]) capability_namespaces = set([discovered.capability.namespace for discovered in discoveries]) capability_revisions = set([discovered.capability.revision for discovered in discoveries]) capabilities = set([discovered.capability for discovered in discoveries]) for discovered in discoveries[0:10]: rediscover = capability_discovery( device_name=discovered.device_name, capability_name=discovered.capability.name, capability_ns=discovered.capability.namespace, capability_revision=discovered.capability.revision) self.assertEqual(1, len(rediscover), "Expected discovery of %s" % str(discovered)) self.assertEqual(discovered, rediscover[0]) for device_name in sorted(device_names)[0:10]: rediscover = capability_discovery(device_name=device_name) self.assertTrue(rediscover, "Expected device to have capabilities: %s" % device_name) for capability_name in sorted(capability_names)[0:10]: rediscover = capability_discovery(capability_name=capability_name) self.assertTrue(rediscover, "Expected discovery of capability by name %s" % capability_name) for capability_namespace in sorted(capability_namespaces)[0:10]: rediscover = capability_discovery(capability_ns=capability_namespace) self.assertTrue(rediscover, "Expected discovery of capability by name-space %s" % capability_namespace) for capability_revision in sorted(capability_revisions)[0:10]: rediscover = capability_discovery(capability_revision=capability_revision) self.assertTrue(rediscover, "Expected discovery of capability by revision %s" % capability_revision) for capability in sorted(capabilities)[0:10]: rediscover = capability_discovery(capability_name=capability.name,capability_ns=capability.namespace,capability_revision=capability.revision) self.assertTrue(rediscover, "Expected discovery of capability %s" % str(capability)) self.assertEqual(capability, rediscover[0].capability)
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
def is_acl_supported(device_name): returnValue = False; discovered = capability_discovery(device_name=device_name, capability_name=capability_name, capability_ns=capability_ns) if (discovered): returnValue = True return returnValue