In the NX-OS 9K training, I created a sample Webportal (by modifying some code from Github) to demonstrate the usage of the NX-API, here I want to share it.
The purpose of the Webportal is just allow an user enter a list of Nexus 9K Management IP, then it display some version information of them. The user can then select one of the 9K to view the interfaces' information. Finally, can select the interface to view more detail.
The portal is quite straight forward. The first screen just a pure form to prompt user to enter the list of IP addresses. The form action will then call the python script WebMgr.py to process the form data (which is just the list of IP addresses).

Here's the HTML:
<h2>Nexus Web Manager</h2>
<form action="/cgi-bin/WebMgr.py" method="post">
Switch IP Address List: <input type="text" name="IP">
<input type="submit" value="Show">
</form>
The WebMgr.py python script get back the form data by form.getvalue('IP'), then connect to each of the IP address (username and password is HARD CODED inside the script, as an exercise, reader can modify the form to prompt user to enter them), use the Nexus API to do a "show version" and parse some of the information, then display them one by one in a table. Moreover, on the last table column, create a form button with action to call Intf.py by passing the corresponding Nexus 9K management IP to it.

Here is the WebMgr.py:
#!/usr/bin/env python
#
import cgi, cgitb
from xml.dom import minidom
from nxapi_utils import *
#################
# MAIN MODULE #
#################
# First things first: credentials. They should be parsed through sys.argv[] ideally ..
form = cgi.FieldStorage()
# Get data from fields
IP_STRING = form.getvalue('IP')
IP_LIST=IP_STRING.split(",")
user="admin"
password="dummy"
print("Content-type:text/html")
print """
<head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
</style>
</head>
<body>
<h2>Nexus Web Manager</h2>
<form action="/cgi-bin/WebMgr.py" method="post">
Switch IP Address List: <input type="text" name="IP" value=%s>
<input type="submit" value="Show">
</form>
<table>
<tr>
<th>IP Address</th>
<th>Hostname</th>
<th>Version</th>
<th>Show Interfaces</th>
</tr>
<tr>
"""%format(IP_STRING)
for IP in IP_LIST:
url = 'http://'+IP+'/ins/'
cookie=GetiAPICookie(url, user, password)
dom = minidom.parseString(ExecuteiAPICommand(url, cookie, user, password, "cli_show", "show version"))
host_name=GetNodeDataDom(dom,"host_name")
kickstart_ver_str=GetNodeDataDom(dom,"kickstart_ver_str")
print "<tr>"
print("<td>%s </td>" % (IP))
print("<td>%s </td>" % (host_name))
print("<td>%s </td>" % (kickstart_ver_str))
form_str="""<td>
<form action="/cgi-bin/Intf.py" method="post">
<input type="hidden" name="IP_LIST" value=%s>
<input type="hidden" name="IP" value=%s>
<input type="submit" value="Manager">
</form>
</td>
"""%(IP_STRING,IP)
print form_str
print("</tr>")
print "</table>"
Inside the Intf.py script, just like the WebMgr.py, after getting back the form data (IP address), it uses the Nexus API to do a "show interface" and "show interface switchport" commands, to get information such as the status, VLAN about the interfaces. Again, just display as a table, and in the last column, also create a form button to display the detail of that interface. This time the form action calls back the Intf.py script with an additional information which is the interface name.

Please follow this link to continue with next part.