aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve McIntyre <steve.mcintyre@linaro.org>2014-12-23 16:08:19 +0000
committerSteve McIntyre <steve.mcintyre@linaro.org>2014-12-23 16:08:19 +0000
commit48dc6ae660c0eb5eb7bc555bcdb8c16a173f0d3d (patch)
tree77697480125102943c1015d89f248ee65ed4dfd3
parentda040a7daad04c34c23fbea9766a7e7a1e7db5e7 (diff)
downloadvland-48dc6ae660c0eb5eb7bc555bcdb8c16a173f0d3d.tar.gz
Improve debug for the switch drivers
When running the built-in test code, turn on debug to stdout by default Change-Id: Iefcba473a0cbfc99ab9bd8b3a878a8f0713989ad
-rw-r--r--drivers/CiscoCatalyst.py23
-rw-r--r--drivers/CiscoSX300.py23
2 files changed, 40 insertions, 6 deletions
diff --git a/drivers/CiscoCatalyst.py b/drivers/CiscoCatalyst.py
index ae9c13e..4e89efe 100644
--- a/drivers/CiscoCatalyst.py
+++ b/drivers/CiscoCatalyst.py
@@ -38,10 +38,11 @@ class CiscoCatalyst(SwitchDriver):
# this
_expected_descr_re = re.compile('WS-C\S+-\d+P')
- logfile = sys.stderr
logfile = None
- def __init__(self, switch_hostname, switch_telnetport=23):
+ def __init__(self, switch_hostname, switch_telnetport=23, debug = False):
+ if debug:
+ logfile = sys.stderr
self.exec_string = "/usr/bin/telnet %s %d" % (switch_hostname, switch_telnetport)
################################
@@ -480,7 +481,23 @@ class CiscoCatalyst(SwitchDriver):
self.connection.expect(text)
if __name__ == "__main__":
- p = CiscoCatalyst('vlandswitch01', 23)
+
+ import optparse
+
+ switch = 'vlandswitch01'
+ parser = optparse.OptionParser()
+ parser.add_option("--switch",
+ dest = "switch",
+ action = "store",
+ nargs = 1,
+ type = "string",
+ help = "specify switch to connect to for testing",
+ metavar = "<switch>")
+ (opts, args) = parser.parse_args()
+ if opts.switch:
+ switch = opts.switch
+
+ p = CiscoCatalyst(switch, 23, debug=True)
p.switch_connect(None, 'lngvirtual', 'lngenable')
print "VLANs are:"
diff --git a/drivers/CiscoSX300.py b/drivers/CiscoSX300.py
index bb43de0..d551bbb 100644
--- a/drivers/CiscoSX300.py
+++ b/drivers/CiscoSX300.py
@@ -36,10 +36,11 @@ class CiscoSX300(SwitchDriver):
# this
_expected_descr_re = re.compile('S.300-\d+')
- logfile = sys.stderr
logfile = None
- def __init__(self, switch_hostname, switch_telnetport=23):
+ def __init__(self, switch_hostname, switch_telnetport=23, debug = False):
+ if debug:
+ logfile = sys.stderr
self.exec_string = "/usr/bin/telnet %s %d" % (switch_hostname, switch_telnetport)
################################
@@ -424,7 +425,23 @@ class CiscoSX300(SwitchDriver):
if __name__ == "__main__":
# p = CiscoSX300('10.172.2.52', 23)
- p = CiscoSX300('vlandswitch02', 23)
+
+ import optparse
+
+ switch = 'vlandswitch02'
+ parser = optparse.OptionParser()
+ parser.add_option("--switch",
+ dest = "switch",
+ action = "store",
+ nargs = 1,
+ type = "string",
+ help = "specify switch to connect to for testing",
+ metavar = "<switch>")
+ (opts, args) = parser.parse_args()
+ if opts.switch:
+ switch = opts.switch
+
+ p = CiscoSX300(switch, 23, debug = True)
p.switch_connect('cisco', 'cisco', None)
#buf = p._show_clock()
#print "%s" % buf