COSC Learning Lab

03_management_interface.py

Table of Contents

Documentation


In [1]:
help('learning_lab.03_management_interface')


Help on module learning_lab.03_management_interface in learning_lab:

NAME
    learning_lab.03_management_interface - Sample usage of function 'management_interface'.

DESCRIPTION
    Print the function's documentation.
    Invoke the function.
    Print the function output.
    
    One device that is mounted will be selected for the demonstration.

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

FILE
    /home/virl/git/cosc-learning-labs/src/learning_lab/03_management_interface.py


Implementation


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


def main():
    ''' Select a device and demonstrate.'''
    print(plain(doc(management_interface)))
    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 'management_interface' to the specified device.'''
    print('management_interface(' + device_name, end='): ')
    print(management_interface(device_name))

Execution


In [4]:
run ../learning_lab/03_management_interface.py


Python Library Documentation: function management_interface in module basics.interface

management_interface(device_name)
    Return the name of the interface that is used to manage the specified network device.

management_interface(xrvr-511-53U): MgmtEth0/0/CPU0/0

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 3 
Request
Method GET
URL http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes
Headers
User-Agent python-requests/2.2.1 CPython/3.4.0 Linux/3.13.0-45-generic
Accept application/xml
Accept-Encoding gzip, deflate, compress
Authorization Basic YWRtaW46YWRtaW4=
Content
Response
Status Code 200
Headers
transfer-encoding chunked
server Jetty(8.1.14.v20131031)
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 3 
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
User-Agent python-requests/2.2.1 CPython/3.4.0 Linux/3.13.0-45-generic
Accept application/xml
Accept-Encoding gzip, deflate, compress
Authorization Basic YWRtaW46YWRtaW4=
Content
Response
Status Code 200
Headers
transfer-encoding chunked
server Jetty(8.1.14.v20131031)
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.95</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>
HTTP request/response: 1 2 3 
Request
Method GET
URL http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/xrvr-511-53U/yang-ext:mount/Cisco-IOS-XR-ifmgr-cfg:interface-configurations
Headers
User-Agent python-requests/2.2.1 CPython/3.4.0 Linux/3.13.0-45-generic
Accept application/xml
Accept-Encoding gzip, deflate, compress
Authorization Basic YWRtaW46YWRtaW4=
Content
Response
Status Code 200
Headers
transfer-encoding chunked
server Jetty(8.1.14.v20131031)
content-type application/xml
Content
<?xml version='1.0' encoding='ASCII'?>
<interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg">
  <interface-configuration>
    <active>act</active>
    <interface-name>MgmtEth0/0/CPU0/0</interface-name>
    <description>OOB Management</description>
    <ipv4-network xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-io-cfg">
      <addresses>
        <primary>
          <netmask>255.255.255.0</netmask>
          <address>172.16.1.95</address>
        </primary>
      </addresses>
    </ipv4-network>
  </interface-configuration>
  <interface-configuration>
    <active>act</active>
    <interface-name>GigabitEthernet0/0/0/0</interface-name>
    <description>to XRv-5-3-1</description>
    <ipv4-network xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-io-cfg">
      <addresses>
        <primary>
          <netmask>255.255.255.252</netmask>
          <address>10.0.128.6</address>
        </primary>
      </addresses>
    </ipv4-network>
  </interface-configuration>
  <interface-configuration>
    <active>act</active>
    <interface-name>GigabitEthernet0/0/0/4</interface-name>
    <description>GigabitEthernet0/0/0/4</description>
  </interface-configuration>
  <interface-configuration>
    <active>act</active>
    <interface-name>Loopback0</interface-name>
    <interface-virtual/>
    <description>Loopback</description>
    <ipv4-network xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-io-cfg">
      <addresses>
        <primary>
          <netmask>255.255.255.255</netmask>
          <address>192.168.0.3</address>
        </primary>
      </addresses>
    </ipv4-network>
  </interface-configuration>
  <interface-configuration>
    <active>act</active>
    <interface-name>GigabitEthernet0/0/0/3</interface-name>
    <description>GigabitEthernet0/0/0/3</description>
  </interface-configuration>
  <interface-configuration>
    <active>act</active>
    <interface-name>GigabitEthernet0/0/0/2</interface-name>
    <description>GigabitEthernet0/0/0/2</description>
  </interface-configuration>
  <interface-configuration>
    <active>act</active>
    <interface-name>GigabitEthernet0/0/0/1</interface-name>
    <description>GigabitEthernet0/0/0/1</description>
  </interface-configuration>
</interface-configurations>