print("Gather and print Ethernet1/1 Data")
print("-" * 20)
intf_output = device.show("show interface Ethernet1/1")
print(
    "Interface: {}; State: {}; MTU: {}".format(
        intf_output.find(".//interface").text,
        intf_output.find(".//state").text,
        intf_output.find(".//eth_mtu").text,
    )
)

# Exercise 7b
print("\n\n")
print("Capture and print XML output from multiple show commands")
print("-" * 20)
show_output = device.show_list(["show system uptime", "show system resources"])
for output in show_output:
    print(etree.tostring(output, encoding="unicode"))
    print("-" * 20)
print("\n\n")

# Exercise 7c
print()
print("Create two new loopbacks with descriptions")
print("-" * 20)
commands = [
    "interface loopback101",
    "description loopback101",
    "no shutdown",
    "interface loopback102",
    "description loopback102",
Example #2
0
from nxapi_plumbing import Device

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

device = Device(
    api_format="xml",
    host="nxos1.lasthop.io",
    username="******",
    password=getpass(),
    transport="https",
    port=8443,
    verify=False,
)

cmds = ["show hostname", "show version", "show lldp neighbors"]
output = device.show_list(cmds)
for entry in output:
    print(etree.tostring(entry).decode())
    input("Hit enter to continue: ")

cmds = ["show version"]
output = device.show_list(cmds, raw_text=True)
print(etree.tostring(output[0]).decode())

cfg_cmd = ["logging history size 200"]
output = device.config_list(cfg_cmd)
print(etree.tostring(output[0]).decode())

output = device.save()
print(output)
Example #3
0
               host="nxos1.lasthop.io",
               username="******",
               password=getpass(),
               transport="https",
               port=8443,
               verify=False)

output = nxos1.show("show interface Ethernet1/1")

# Exercise 7a
print("Interface: {}; State: {}; MTU: {}".format(
    output.find(".//interface").text,
    output.find(".//state").text,
    output.find(".//eth_mtu").text,
))

# Exercise 7b
cmds = ["show system uptime", "show system resources"]
output = nxos1.show_list(cmds)
for entry in output:
    print(etree.tostring(entry).decode())

# Exercise 7c

cfg_cmds = [
    "interface Loopback120", "description My loopback",
    "interface Loopback121", "description My loopback again"
]

output = nxos1.config_list(cfg_cmds)
Example #4
0
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
from pprint import pprint
from nxapi_plumbing import Device

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

device = Device(
    api_format="xml",
    host="nxos1.lasthop.io",
    username="******",
    password="******",
    transport="https",
    port=8443,
    verify=False,
)

cmds = ["show interface Ethernet1/1"]
output = device.show_list(cmds)

#outputdata = output[0].getchildren()[0].getchildren()[0].getchildren()[0].getchildren()
#outputdata = output[0][0][0][0].findall('.//')
data_int = output[0][0][0][0].findall('.//interface')[0].text
data_state = output[0][0][0][0].findall('.//state')[0].text
eth_mtu = output[0][0][0][0].findall('.//state')[0].text

print(f"Interface: {data_int}; " f"State: {data_state}; " f"MTU: {eth_mtu} ")
Example #5
0
)

if __name__ == "__main__":
    output = device.show("show interface Ethernet2/1")

    # Task a
    print("-" * 20)
    print("Interface Report : ")
    print("Interface : {0}, State : {1}, MTU : {2}".format(
        output.find(".//interface").text,
        output.find(".//admin_state").text,
        output.find(".//eth_mtu").text))

    # Task b
    list_cmds = ["show system uptime", "show system resources"]
    output = device.show_list(list_cmds)
    print("")
    print("-" * 20)
    print("System Report :")
    for element in output:
        bstring = etree.tostring(element)
        print(bstring.decode())

    # Task c
    list_cmds = [
        "interface loopback151", "description dev01",
        "ip address 10.111.222.254/32"
    ]
    output = device.config_list(list_cmds)
    bstring = etree.tostring(element)
    print(bstring.decode())
Example #6
0
# The CODE

if __name__ == "__main__":
    nxos1_conn = Device(**NXOS1)
    interface_show = nxos1_conn.show("show interface Ethernet1/1")
    eth1_1 = interface_show.find(".//ROW_interface")
    print("+=" * 30)
    # Nice exaple python's indentation feature and readability
    print("Interface: {}; State: {}; MTU: {}".format(
        interface_show.find(".//interface").text,
        interface_show.find(".//state").text,
        interface_show.find(".//eth_mtu").text))
    print("+=" * 30)

    # 7b
    show_commands_result = nxos1_conn.show_list(SHOW_COMMANDS)
    # print resut
    print("Result of show commands:")
    for command_result in show_commands_result:
        print(etree.tostring(command_result, encoding="unicode"))
    print("+=" * 30)

    # 7c
    print("Configuring Loopback interfaces")
    result = nxos1_conn.config_list(CONFIG_LOOPBACK)
    # print XML output of each command
    for output_message in result:
        print(etree.tostring(output_message, encoding="unicode"))
'''
In [11]: pprint(etree.tostring(interface_show).decode())
('<output>\n'
Example #7
0
INT = my_xml.findall(".//interface")[0].text
STATE = my_xml.findall(".//state")[0].text
MTU = my_xml.findall(".//eth_mtu")[0].text

print("\n")
pprint("Interface: {}; State: {}; MTU: {}".format(INT, STATE, MTU))
print("\n")

print("Exercise 7b - Run the following two show commands on the nxos1 device")
print("-" * 40)
cmd = ["show system uptime", "show system resources"]
for i in cmd:

    print(i)
    print("-" * 20)
    my_xml1 = device.show_list(i)
    print(my_xml1)
    STRING = etree.tostring(my_xml1[0]).decode()
    print(STRING)

print("Exercise 7c - Configure Loopbacks on the nxos1 device")
print("-" * 30)

cmd = [
    'interface Loopback 187', 'description Loopback187',
    'interface Loopback 189', 'description Loopback188'
]

my_xml2 = device.config_list(cmd)
print(my_xml2)
CONFIG = etree.tostring(my_xml2[0]).decode()
Example #8
0
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
from nxapi_plumbing import Device

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

device = Device(
    api_format="jsonrpc",  #This format could also be xml instead of jsonrpc
    host="192.168.1.4",
    username="******",
    password="******",
    transport="https",
    port=8443,
    verify=False,
)

output = device.show("show ver")
print(output)

cmd = ["show hostname", "show version"]

output1 = device.show_list(cmd, raw_text=True)

for entry in output1:
    print(entry)
    input("Hit Enter to continue: ")

cfg_cmd = ["logging history size 400"]
output2 = device.config_list(cfg_cmd)
print(output2)
Example #9
0
#!/usr/bin/python

import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
from pprint import pprint
from getpass import getpass
from nxapi_plumbing import Device
from lxml import etree

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

nxos1 = Device(
    api_format='xml',
    host='nxos1.lasthop.io',
    username='******',
    password=getpass(),
    transport='https',
    port=8443,
    verify=False,
)

commands = ['show system uptime', 'show system resources']

output = nxos1.show_list(commands)
for out in output:
    pprint(etree.tostring(out).decode())