Commits

Michael Tharp committed 517d231

Refactor into a single script

Comments (0)

Files changed (6)

dump.py

-#!/usr/bin/python
-import pickle
-import sys
-from pc2700 import switch
-
-
-def main(args):
-    hostname, username, password = args
-    cfg = switch.SwitchConfig(hostname)
-    cfg.loadAll(username, password)
-    pickle.dump(cfg, open(hostname + '.pickle', 'w'), 2)
-
-
-if __name__ == '__main__':
-    sys.exit(main(sys.argv[1:]))

grid.py

-#!/usr/bin/python
-import pickle
-import sys
-from pc2700 import switch
-cfg = pickle.load(open(sys.argv[1]))
-vlanIds = sorted(cfg.vlanIds)
-print 'ST=%(serviceTag)s Product="%(productName)s" MAC=%(macAddr)s' % cfg.systemInfo
-print 'Name=%(systemName)s Firmware=%(fwVer)s Bootloader=%(bootVer)s' % cfg.systemInfo
-print 'Port\t', '\t'.join('%4d' % x for x in vlanIds), '\tstate\tflags\tproblems'
-for port in cfg.ports:
-    chunks = ['%-6s' % port.name]
-    problems = set()
-    flags = set()
-    if port.inLag:
-        chunks.append('(in %s)' % port.inLag.name)
-        chunks.extend('' for x in range(len(vlanIds)-2))
-    else:
-        if port.flowControl == switch.AUTO:
-            flags.add('f')
-        elif port.flowControl == switch.ENABLED:
-            flags.add('F')
-        if port.backPressure:
-            flags.add('b')
-        if not port.autoNegotiation:
-            flags.add('m')
-        if port.vlanFrameType == switch.ADMIT_TAGGED:
-            flags.add('t')
-        for vlanId in vlanIds:
-            if vlanId in port.untagged:
-                state = 'U'
-            elif vlanId in port.tagged:
-                state = 'T'
-            else:
-                state = ' '
-            if vlanId == port.pvid:
-                desc = ' [%s]' % state
-                if state == 'T' and port.vlanFrameType == switch.ADMIT_ALL:
-                    problems.add('PVID is tagged but untagged frames are accepted')
-            else:
-                desc = '  %s ' % state
-                if state == 'U':
-                    problems.add('untagged vlan != PVID')
-            chunks.append(desc)
-    chunks.append(' up ' if port.link else 'down')
-    chunks.append(''.join(sorted(flags)))
-    chunks.append(', '.join(sorted(problems)))
-    print '\t'.join(chunks)
-print 'Flags: (F)low on, (f)low auto, (b)ackpressure, (m)anual negotiation,'
-print '       (t)agged frames only'
+#
+# Copyright (c) rPath, Inc.
+#
+# This program is distributed under the terms of the MIT License as found
+# in a file called LICENSE. If it is not present, the license
+# is always available at http://www.opensource.org/licenses/mit-license.php.
+#
+# This program is distributed in the hope that it will be useful, but
+# without any waranty; without even the implied warranty of merchantability
+# or fitness for a particular purpose. See the MIT License for full details.
+#
+
+from pc2700 import switch
+
+
+def show(cfg):
+    vlanIds = sorted(cfg.vlanIds)
+    print 'ST=%(serviceTag)s Product="%(productName)s" MAC=%(macAddr)s' % cfg.systemInfo
+    print 'Name=%(systemName)s Firmware=%(fwVer)s Bootloader=%(bootVer)s' % cfg.systemInfo
+    print 'Port\t', '\t'.join('%4d' % x for x in vlanIds), '\tstate\tflags\tproblems'
+    for port in cfg.ports:
+        chunks = ['%-6s' % port.name]
+        problems = set()
+        flags = set()
+        if port.inLag:
+            chunks.append('(in %s)' % port.inLag.name)
+            chunks.extend('' for x in range(len(vlanIds)-2))
+        else:
+            if port.flowControl == switch.AUTO:
+                flags.add('f')
+            elif port.flowControl == switch.ENABLED:
+                flags.add('F')
+            if port.backPressure:
+                flags.add('b')
+            if not port.autoNegotiation:
+                flags.add('m')
+            if port.vlanFrameType == switch.ADMIT_TAGGED:
+                flags.add('t')
+            for vlanId in vlanIds:
+                if vlanId in port.untagged:
+                    state = 'U'
+                elif vlanId in port.tagged:
+                    state = 'T'
+                else:
+                    state = ' '
+                if vlanId == port.pvid:
+                    desc = ' [%s]' % state
+                    if state == 'T' and port.vlanFrameType == switch.ADMIT_ALL:
+                        problems.add('PVID is tagged but untagged frames are accepted')
+                else:
+                    desc = '  %s ' % state
+                    if state == 'U':
+                        problems.add('untagged vlan != PVID')
+                chunks.append(desc)
+        chunks.append(' up ' if port.link else 'down')
+        chunks.append(''.join(sorted(flags)))
+        chunks.append(', '.join(sorted(problems)))
+        print '\t'.join(chunks)
+    print 'Flags: (F)low on, (f)low auto, (b)ackpressure, (m)anual negotiation,'
+    print '       (t)agged frames only'

pc2700/jsparse.py

 #
-# Copyright (c) Michael Tharp <gxti@partiallystapled.com>
+# Copyright (c) rPath, Inc.
 #
-# Permission to use, copy, modify, and/or distribute this software for any
-# purpose with or without fee is hereby granted, provided that the above
-# copyright notice and this permission notice appear in all copies.
+# This program is distributed under the terms of the MIT License as found
+# in a file called LICENSE. If it is not present, the license
+# is always available at http://www.opensource.org/licenses/mit-license.php.
 #
-# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+# This program is distributed in the hope that it will be useful, but
+# without any waranty; without even the implied warranty of merchantability
+# or fitness for a particular purpose. See the MIT License for full details.
+#
 
 import json
 import re
 #
-# Copyright (c) Michael Tharp <gxti@partiallystapled.com>
+# Copyright (c) rPath, Inc.
 #
-# Permission to use, copy, modify, and/or distribute this software for any
-# purpose with or without fee is hereby granted, provided that the above
-# copyright notice and this permission notice appear in all copies.
+# This program is distributed under the terms of the MIT License as found
+# in a file called LICENSE. If it is not present, the license
+# is always available at http://www.opensource.org/licenses/mit-license.php.
 #
-# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+# This program is distributed in the hope that it will be useful, but
+# without any waranty; without even the implied warranty of merchantability
+# or fitness for a particular purpose. See the MIT License for full details.
+#
 
 
 import cookielib
+#!/usr/bin/python
+#
+# Copyright (c) rPath, Inc.
+#
+# This program is distributed under the terms of the MIT License as found
+# in a file called LICENSE. If it is not present, the license
+# is always available at http://www.opensource.org/licenses/mit-license.php.
+#
+# This program is distributed in the hope that it will be useful, but
+# without any waranty; without even the implied warranty of merchantability
+# or fitness for a particular purpose. See the MIT License for full details.
+#
+
+import pickle
+import sys
+from pc2700 import dgrid
+from pc2700 import switch
+
+
+def main(args):
+    if len(args) != 3:
+        sys.exit("usage: %s <hostname> <username> <password" % sys.argv[0])
+    hostname, username, password = args
+    cfg = switch.SwitchConfig(hostname)
+    cfg.loadAll(username, password)
+    pickle.dump(cfg, open(hostname + '.pickle', 'w'), 2)
+    dgrid.show(cfg)
+
+
+if __name__ == '__main__':
+    sys.exit(main(sys.argv[1:]))