/[shmookey]/portconf/index.py


UCC Code Repository

Contents of /portconf/index.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 86 - (show annotations) (download) (as text)
Fri May 2 07:24:33 2008 UTC (12 years, 8 months ago) by shmookey
File MIME type: text/x-python
File size: 5677 byte(s)
error checking

1 #!/usr/bin/python
2
3 import sys, re, pexpect
4 import Log
5
6 try:
7 from Config import libPaths, dbName, dbUser, dbPass, dbHost, dbPort
8 except:
9 Log.Message ("Error occured in finding basic configuration paramaters. Reverting to installer.", "index.py", "ERROR")
10 import install
11 sys.exit ()
12
13 sys.path += ":" + ":".join(libPaths)
14
15 try:
16 import pycisco, pyaaa
17 except:
18 Log.Message ("Couldn't import pycisco or pyaaa. Reverting to installer.", "index.py", "ERROR")
19 import install
20 sys.exit ()
21
22 import cgi, cgitb
23 cgitb.enable ()
24 print "Content-Type: text/html"
25 print
26
27 import pycisco
28
29 print "<h2>Port Administration Configuration Tool</h2>"
30
31 form = cgi.FieldStorage ()
32
33
34 def ShowDefaultPage ():
35 print "<p>Select a switch to get started!</p>"
36 print "<form action='index.html' method='get'>"
37 print "<select name='switch'>"
38 switches = pycisco.GetSwitches ()
39 for switch in switches:
40 print "<option value='" + switch + "'>" + switch + "</option>"
41 print "</select>"
42 print "<input type='hidden' name='action' value='status' />"
43 print "<input type='submit' value='View Port Summary' />"
44 print "</form>"
45
46 def ShowSwitchStatus (switchName):
47 print "<h3>Port summary for " + switchName + "</h3>"
48
49 print "<script type='text/javascript'>"
50 print """
51 $(document).ready (function () {
52 $("a.portfast").click (function () {
53 // Change the appearance and class so that it's no longer a "reveal"-style link
54 $(this).attr ("class", "portfastload");
55 $(this).text ("Wait...");
56
57 portName = $(this).parents("tr").attr ('id');
58 $(this).load ("update.py?action=getportfast&switch=""" + switchName + """&port=" + portName);
59 $(this).unbind ();
60 $(this).click (togglePortfast);
61 });
62 $("a.errors").click (function () {
63 $(this).attr ("class", "errorsload");
64 $(this).text ("Wait...");
65 td = $(this).parents ("td");
66 portName = $(this).parents("tr").attr ('id');
67 td.load ("update.py?action=geterrors&switch=""" + switchName + """&port=" + portName);
68 });
69 $("a.status").click (function () {
70 $(this).attr ("class", "statusload");
71 $(this).text ("Wait...");
72 td = $(this).parents ("td");
73 portName = $(this).parents("tr").attr ('id');
74 $(this).load ("update.py?action=toggleshutdown&switch=""" + switchName + """&port=" + portName);
75 });
76 togglePortfast = function () {
77 $(this).text ("Wait...");
78 portName = $(this).parents("tr").attr ('id');
79 $(this).load ("update.py?action=toggleportfast&switch=""" + switchName + """&port=" + portName);
80 };
81 toggleShutdown = function () {
82 $(this).text ("Wait...");
83 portName = $(this).parents("tr").attr ('id');
84 $(this).load ("update.py?action=toggleshutdown&switch=""" + switchName + """&port=" + portName);
85 };
86 descClick = function () {
87 $(this).attr ("class", "descinput");
88 portName = $(this).parents("tr").attr ('id');
89 td = $(this).parents ("td");
90 td.html ("<input type='text' value='" + $(this).text() + "' />");
91 td.children ().focus ().blur (function () {
92 portName = $(this).parents("tr").attr ('id');
93 portDesc = $(this).attr ("value");
94 td = $(this).parents ("td");
95 td.html ("<a style='cursor:pointer'>Saving...</a>");
96 td.children ().click (descClick);
97 td.children().load ("update.py?action=setdescription&switch=""" + switchName + """&port=" + portName + "&desc=" + escape (portDesc));
98 });
99 //td.load ("update.py?action=geterrors&switch=""" + switchName + """&port=" + portName);
100 };
101 vlanClick = function () {
102 $(this).attr ("class", "vlaninput");
103 portName = $(this).parents("tr").attr ('id');
104 td = $(this).parents ("td");
105 td.html ("<input type='text' value='" + $(this).text() + "' />");
106 td.children ().focus ().blur (function () {
107 portName = $(this).parents("tr").attr ('id');
108 vlan = $(this).attr ("value");
109 td = $(this).parents ("td");
110 td.html ("<a style='cursor:pointer'>Saving...</a>");
111 td.children ().click (vlanClick);
112 td.children().load ("update.py?action=setvlan&switch=""" + switchName + """&port=" + escape(portName) + "&vlan=" + escape (vlan));
113 });
114 };
115 $("a.desc").click (descClick);
116 $("a.vlan").click (vlanClick);
117 });
118 """
119 print "</script>"
120
121 try:
122 ports = pycisco.GetPortSummary (switchName)
123 except pexpect.TIMEOUT:
124 print "<h3 style='color:rgb(255,0,0)'>Switch appears to be down.</h3>"
125 return
126 print "<table border='0' cellpadding='2' cellspacing='0' class='rowset' >"
127 print "<tr>"
128 print "<th>Number</th>"
129 print "<th>Description</th>"
130 print "<th>Connected</th>"
131 print "<th>VLAN</th>"
132 print "<th>Duplex</th>"
133 print "<th>Speed</th>"
134 print "<th>Media</th>"
135 print "<th>Portfast</th>"
136 print "<th>Errors</th>"
137 print "</tr>"
138 even = True
139 for port in ports:
140 print "<tr class='" + (even and "even" or "odd") + "' id='" + port["name"] + "'>"
141 print "<td>" + port["name"] + "</td>"
142 print "<td><a style='cursor:pointer' class='desc'>" + (port["description"] or "(not set)") + "</a></td>"
143 print "<td><a style='cursor:pointer' class='status'>" + port["connectstate"] + "</a></td>"
144 print "<td><a style='cursor:pointer' class='vlan'>" + port["vlan"] + "</a></td>"
145 print "<td>" + port["duplex"] + "</td>"
146 print "<td>" + port["speed"] + "</td>"
147 print "<td>" + port["media"] + "</td>"
148 print "<td><a style='cursor:pointer' class='portfast'>" + port["portfast"] + "</a></td>"
149 print "<td><a style='cursor:pointer' class='errors'>" + port["errors"] + "</td>"
150 print "</tr>"
151 even = not even
152 print "</table>"
153
154
155 if not form.has_key ("action"):
156 ShowDefaultPage ()
157 elif form["action"].value == "status":
158 if not form.has_key ("switch"):
159 print "Missing switch argument, please stop trying to craft your own URLs!"
160 else:
161 ShowSwitchStatus (form["switch"].value)
162
163

Properties

Name Value
svn:executable *

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26