COSC Learning Lab

01_device_control.py

Related Scripts:

Table of Contents

Documentation


In [1]:
help('learning_lab.01_device_control')


Help on module learning_lab.01_device_control in learning_lab:

NAME
    learning_lab.01_device_control - Sample usage of function 'device_control'.

DESCRIPTION
    Print the function's documentation.
    Apply the function to one device.
    Print the output.
    
    This demonstration requires a device that is mounted.
    It is not necessary for the device to be connected.

FUNCTIONS
    demonstrate(device_name)
        Apply function 'device_control' to the specified device.
    
    main()
        Select a device and demonstrate.

FILE
    /home/virl/git/cosc-learning-labs/src/learning_lab/01_device_control.py


Implementation


In [2]:
from importlib import import_module
script = import_module('learning_lab.01_device_control')
from inspect import getsource
print(getsource(script.main))


def main():
    ''' Select a device and demonstrate.'''
    print(plain(doc(device_control)))
    print('DeviceControl fields:', *DeviceControl._fields, sep='\n\t', end='\n\n')
    for device_name in inventory_mounted():
        demonstrate(device_name)
        return 0
    print("There are no suitable network devices. Demonstration cancelled.")
    return 1


In [3]:
print(getsource(script.demonstrate))


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))

Execution


In [4]:
run ../learning_lab/01_device_control.py


Python Library Documentation: function device_control in module basics.inventory

device_control(device_name)
    A DeviceControl if the specified device is mounted, otherwise None

DeviceControl fields:
	address
	port
	username
	password

device_control(xrvr-511-53U)

HTTP


In [5]:
from basics.odl_http import http_history
from basics.http import http_history_to_html
from IPython.core.display import HTML
HTML(http_history_to_html(http_history()))


Out[5]:
HTTP request/response: 1 2 
Request
Method GET
URL http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes
Headers
Accept-Encoding gzip, deflate, compress
Accept application/xml
User-Agent python-requests/2.2.1 CPython/3.4.0 Linux/3.13.0-45-generic
Authorization Basic YWRtaW46YWRtaW4=
Content
Response
Status Code 200
Headers
server Jetty(8.1.14.v20131031)
transfer-encoding chunked
content-type application/xml
Content
<?xml version='1.0' encoding='ASCII'?>
<nodes xmlns="urn:opendaylight:inventory">
  <node>
    <id>xrvr-511-53U</id>
  </node>
  <node>
    <id>xrvr-531</id>
  </node>
  <node>
    <id>controller-config</id>
  </node>
</nodes>
HTTP request/response: 1 2 
Request
Method GET
URL http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/controller-config/yang-ext:mount/config:modules/module/odl-sal-netconf-connector-cfg:sal-netconf-connector/xrvr-511-53U
Headers
Accept-Encoding gzip, deflate, compress
Accept application/xml
User-Agent python-requests/2.2.1 CPython/3.4.0 Linux/3.13.0-45-generic
Authorization Basic YWRtaW46YWRtaW4=
Content
Response
Status Code 200
Headers
server Jetty(8.1.14.v20131031)
transfer-encoding chunked
content-type application/xml
Content
<?xml version='1.0' encoding='ASCII'?>
<module xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
  <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">x:sal-netconf-connector</type>
  <name>xrvr-511-53U</name>
  <address xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">172.16.1.90</address>
  <dom-registry xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
    <name>dom-broker</name>
    <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom">x:dom-broker-osgi-registry</type>
  </dom-registry>
  <processing-executor xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
    <name>global-netconf-processing-executor</name>
    <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:threadpool">x:threadpool</type>
  </processing-executor>
  <binding-registry xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
    <name>binding-osgi-broker</name>
    <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">x:binding-broker-osgi-registry</type>
  </binding-registry>
  <client-dispatcher xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
    <name>global-netconf-dispatcher</name>
    <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:config:netconf">x:netconf-client-dispatcher</type>
  </client-dispatcher>
  <between-attempts-timeout-millis xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">2000</between-attempts-timeout-millis>
  <sleep-factor xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">1.5</sleep-factor>
  <connection-timeout-millis xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">20000</connection-timeout-millis>
  <tcp-only xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">false</tcp-only>
  <port xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">830</port>
  <event-executor xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
    <name>global-event-executor</name>
    <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:netty">x:netty-event-executor</type>
  </event-executor>
  <max-connection-attempts xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">0</max-connection-attempts>
  <password xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">cisco</password>
  <username xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">cisco</username>
</module>