Print the function output. One device that is mounted will be selected for the demonstration. ''' from __future__ import print_function as _print_function from pydoc import plain from pydoc import render_doc as doc from basics.interface import management_interface from basics.inventory import inventory_mounted from basics.context import sys_exit, EX_OK, EX_TEMPFAIL def demonstrate(device_name): ''' Apply function 'management_interface' to the specified device.''' print('management_interface(' + device_name, end='): ') print(management_interface(device_name)) def main(): ''' Select a device and demonstrate.''' print(plain(doc(management_interface))) for device_name in inventory_mounted(): demonstrate(device_name) return EX_OK print("There are no suitable network devices. Demonstration cancelled.") return EX_TEMPFAIL if __name__ == "__main__": sys_exit(main())
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)' if response.status_code == 503 else 'OK' if response.status_code == 200 else 'Unknown', "method": response.request.method, "url": response.url } print_table(outcome) exit_code = EX_OK except Exception as e: exit_code = EX_CONFIG print(e, file=stderr) finally: sys_exit(exit_code)
''' from __future__ import print_function as _print_function from pydoc import plain from pydoc import render_doc as doc from basics.context import sys_exit, EX_OK, EX_TEMPFAIL from basics.acl import acl_exists, inventory_acl from importlib import import_module acl_fixture = import_module('learning_lab.05_acl_fixture') def demonstrate(device_name, acl_name): ''' Apply function 'acl_exists' to the specified device/ACL.''' print('\nacl_exists(' + device_name, acl_name, sep=', ', end=')\n') print('\t', acl_exists(device_name, acl_name)) def main(): ''' Select a device and demonstrate for each acl_sample ACL.''' print(plain(doc(acl_exists))) inventory = inventory_acl() if not inventory: print('There are no ACL capable devices to examine. Demonstration cancelled.') else: for device_name in inventory: for acl_sample in acl_fixture.fixtures: demonstrate(device_name, acl_sample.name) return EX_OK return EX_TEMPFAIL if __name__ == "__main__": sys_exit(main())
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)' if response.status_code == 503 else 'OK' if response.status_code == 200 else 'Unknown', "method":response.request.method, "url":response.url} print_table(outcome) exit_code = EX_OK except Exception as e: exit_code = EX_CONFIG print(e, file=stderr) finally: sys_exit(exit_code)