COSC Learning Lab: 01_device_mounted.py


In [3]:
###Table of Contents

Documentation


In [4]:
help('learning_lab.01_device_mounted')


Help on module learning_lab.01_device_mounted in learning_lab:

NAME
    learning_lab.01_device_mounted - Sample usage of function 'mounted'.

DESCRIPTION
    Print the function's documentation then invoke the function and print the output.

FUNCTIONS
    main()

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


Implementation


In [5]:
from importlib import import_module
script = import_module('learning_lab.03_interface_names')
from inspect import getsource
print(getsource(script.main))


def main():
    ''' Select a device and demonstrate.'''
    print(plain(doc(interface_names)))
    mounted_list = inventory_mounted()
    connected_list = inventory_connected()
    device_list = list(set(connected_list) & set(mounted_list))
    for device_name in device_list:
        return demonstrate(device_name)
    print('There are no mounted, connected devices to examine. Demonstration cancelled.')


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


def demonstrate(device_name):
    ''' Apply function 'interface_names' to the specified device.'''
    print('interface_names(' + device_name, end=')\n')
    print(interface_names(device_name))

Execution


In [7]:
run ../learning_lab/01_device_mounted.py


Python Library Documentation: function mounted in module basics.inventory

mounted(device_name)
    Determine whether a single device is mounted on the Controller.
    
    Return True if mounted.

is mounted(xrvr-2): False

HTTP


In [2]:
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[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-2
Headers
Authorization Basic YWRtaW46YWRtaW4=
Accept-Encoding gzip, deflate, compress
Accept text/xml
User-Agent python-requests/2.2.1 CPython/2.7.6 Linux/3.13.0-44-generic
Content
Response
Status Code 200
Headers
transfer-encoding chunked
content-type text/xml
server Jetty(8.1.14.v20131031)
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-2</name>
  <address xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">172.16.1.75</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>