COSC Learning Lab

05_create_acl_port_grant.py

Related Scripts:

Table of Contents

Documentation


In [1]:
help('learning_lab.05_create_acl_port_grant')


Help on module learning_lab.05_create_acl_port_grant in learning_lab:

NAME
    learning_lab.05_create_acl_port_grant - Sample usage of function 'create_acl_port_grant'.

DESCRIPTION
    Print the function's documentation.
    Apply the function to a network device.
    Print the list of ACLs.
    If no ACL found then retry with a different network device.

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

DATA
    EX_OK = 0
    EX_TEMPFAIL = 75

FILE
    /home/virl/git/cosc-learning-labs/src/learning_lab/05_create_acl_port_grant.py


Implementation


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


def main():
    ''' Select a device and demonstrate.'''
    print(plain(doc(create_acl_port_grant)))
    mounted_list = inventory_mounted()
    if not mounted_list:
        print('There are no mounted devices to examine. Demonstration cancelled.')
    else:
        for device_name in mounted_list:
            try:
                demonstrate(device_name)
                return EX_OK
            except Exception as e:
                print(e)
                return EX_TEMPFAIL
    return EX_TEMPFAIL


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


def demonstrate(device_name):
    ''' Apply function 'create_acl_port_grant' to the specified device.'''
    print('create_acl_port_grant(' + device_name, acl_globals.acl_name, acl_globals.port, acl_globals.grant, acl_globals.protocol, sep=', ', end=')\n')
    create_acl_port_grant(device_name, acl_globals.acl_name, acl_globals.port, acl_globals.grant, acl_globals.protocol)

Execution


In [4]:
run ../learning_lab/05_create_acl_port_grant.py


Python Library Documentation: function create_acl_port_grant in module basics.acl

create_acl_port_grant(device_name, acl_name, port, grant, protocol)

create_acl_port_grant(xrvr-511-53U, portdenyechoudp, echo, deny, udp)
Data already exists for path: /(http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-acl-cfg?revision=2013-07-22)ipv4-acl-and-prefix-list/accesses
exit code 75

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
User-Agent python-requests/2.2.1 CPython/3.4.0 Linux/3.13.0-45-generic
Accept application/xml
Authorization Basic YWRtaW46YWRtaW4=
Accept-Encoding gzip, deflate, compress
Content
Response
Status Code 200
Headers
content-type application/xml
server Jetty(8.1.14.v20131031)
transfer-encoding chunked
Content
<?xml version='1.0' encoding='ASCII'?>
<nodes xmlns="urn:opendaylight:inventory">
  <node>
    <id>xrvr-511-53U</id>
  </node>
  <node>
    <id>controller-config</id>
  </node>
</nodes>
HTTP request/response: 1 2 
Request
Method POST
URL http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/xrvr-511-53U/yang-ext:mount/Cisco-IOS-XR-ipv4-acl-cfg:ipv4-acl-and-prefix-list
Headers
Accept */*
Accept-Encoding gzip, deflate, compress
User-Agent python-requests/2.2.1 CPython/3.4.0 Linux/3.13.0-45-generic
Content-Type application/json
Authorization Basic YWRtaW46YWRtaW4=
Content-Length 321
Content
{
  "Cisco-IOS-XR-ipv4-acl-cfg:accesses": [
    {
      "access": [
        {
          "access-list-name": "portdenyechoudp",
          "access-list-entries": {
            "access-list-entry": [
              {
                "sequence-number": 20,
                "grant": "permit"
              },
              {
                "destination-port": {
                  "destination-operator": "equal",
                  "first-destination-port": "echo"
                },
                "protocol": "udp",
                "sequence-number": 10,
                "grant": "deny"
              }
            ]
          }
        }
      ]
    }
  ]
}
Response
Status Code 409
Headers
content-type application/json
server Jetty(8.1.14.v20131031)
transfer-encoding chunked
Content
{
  "errors": {
    "error": [
      {
        "error-tag": "data-exists",
        "error-type": "protocol",
        "error-message": "Data already exists for path: /(http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-acl-cfg?revision=2013-07-22)ipv4-acl-and-prefix-list/accesses"
      }
    ]
  }
}

In [ ]: