aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve McIntyre <steve.mcintyre@linaro.org>2014-12-24 00:23:36 +0000
committerSteve McIntyre <steve.mcintyre@linaro.org>2014-12-24 00:23:36 +0000
commitc68d6d70f28034ae148ac901e2cf13f011a1509c (patch)
tree9de3c9f65e591caf897b9068d5e593b9a3d130f8
parentdd0c0011fd70eac723d52feefab1cc918fade991 (diff)
downloadvland-c68d6d70f28034ae148ac901e2cf13f011a1509c.tar.gz
Simplify and rename_read_paged_output()
Now I've worked out how to disable paging/pausing altogether, remove all the complexity here. Change-Id: Ia903932f262fc1d7b4ea97a35d1fa8fb22beab3c
-rw-r--r--drivers/CiscoCatalyst.py30
-rw-r--r--drivers/CiscoSX300.py38
2 files changed, 21 insertions, 47 deletions
diff --git a/drivers/CiscoCatalyst.py b/drivers/CiscoCatalyst.py
index 8eb01e6..a9294b0 100644
--- a/drivers/CiscoCatalyst.py
+++ b/drivers/CiscoCatalyst.py
@@ -177,7 +177,7 @@ class CiscoCatalyst(SwitchDriver):
regex = re.compile('^ *(\d+).*(active)')
self._cli("show vlan brief")
- for line in self._read_paged_output():
+ for line in self._read_long_output():
match = regex.match(line)
if match:
vlans.append(int(match.group(1)))
@@ -189,7 +189,7 @@ class CiscoCatalyst(SwitchDriver):
name = None
regex = re.compile('^ *\d+\s+(\S+).*(active)')
self._cli("show vlan id %d" % tag)
- for line in self._read_paged_output():
+ for line in self._read_long_output():
match = regex.match(line)
if match:
name = match.group(1)
@@ -230,7 +230,7 @@ class CiscoCatalyst(SwitchDriver):
raise IndexError("Port name %s not recognised" % port)
regex = re.compile('Administrative Mode: (.*)')
self._cli("show interfaces %s switchport" % port)
- for line in self._read_paged_output():
+ for line in self._read_long_output():
match = regex.match(line)
if match:
mode = match.group(1)
@@ -307,7 +307,7 @@ class CiscoCatalyst(SwitchDriver):
raise IndexError("Port %s not in access mode" % port)
regex = re.compile('Access Mode VLAN: (\d+)')
self._cli("show interfaces %s switchport" % port)
- for line in self._read_paged_output():
+ for line in self._read_long_output():
match = regex.match(line)
if match:
vlan = match.group(1)
@@ -329,7 +329,7 @@ class CiscoCatalyst(SwitchDriver):
in_match = False
vlan_text = ''
- for line in self._read_paged_output():
+ for line in self._read_long_output():
if in_match:
match = regex_continue.match(line)
if match:
@@ -392,24 +392,10 @@ class CiscoCatalyst(SwitchDriver):
def _end_configure(self):
self._cli("end")
- def _read_paged_output(self):
- buf = []
+ def _read_long_output(self):
prompt = self._prompt_name + '#'
- while True:
- index = self.connection.expect([' -*More-*', prompt])
- if index == 0: # More: <space>
- for line in self.connection.before.split('\r\n'):
- line1 = re.sub('(\x08|\x0D)*', '', line.strip())
- buf.append(line1)
- self._cli(' ', False)
- elif index == 1: # Back to a prompt, says output is finished
- break
-
- for line in self.connection.before.split('\r\n'):
- line1 = re.sub('(\x08|\x0D)*', '', line.strip())
- buf.append(line1)
-
- return buf
+ self.connection.expect(prompt)
+ return self.connection.before.split('\r\n')
def _get_port_names(self):
logging.debug("Grabbing list of ports")
diff --git a/drivers/CiscoSX300.py b/drivers/CiscoSX300.py
index 579c034..64998cd 100644
--- a/drivers/CiscoSX300.py
+++ b/drivers/CiscoSX300.py
@@ -170,7 +170,7 @@ class CiscoSX300(SwitchDriver):
regex = re.compile('^ *(\d+).*(D|S|G|R)')
self._cli("show vlan")
- for line in self._read_paged_output():
+ for line in self._read_long_output():
match = regex.match(line)
if match:
vlans.append(int(match.group(1)))
@@ -182,7 +182,7 @@ class CiscoSX300(SwitchDriver):
name = None
regex = re.compile('^ *\d+\s+(\S+).*(D|S|G|R)')
self._cli("show vlan tag %d" % tag)
- for line in self._read_paged_output():
+ for line in self._read_long_output():
match = regex.match(line)
if match:
name = match.group(1)
@@ -220,7 +220,7 @@ class CiscoSX300(SwitchDriver):
raise IndexError("Port name %s not recognised" % port)
regex = re.compile('Port Mode: (\S+)')
self._cli("show interfaces switchport %s" % port)
- for line in self._read_paged_output():
+ for line in self._read_long_output():
match = regex.match(line)
if match:
mode = match.group(1)
@@ -292,7 +292,7 @@ class CiscoSX300(SwitchDriver):
raise IndexError("Port %s not in access mode" % port)
regex = re.compile('(\d+)\s+\S+\s+Untagged\s+Static')
self._cli("show interfaces switchport %s" % port)
- for line in self._read_paged_output():
+ for line in self._read_long_output():
match = regex.match(line)
if match:
vlan = match.group(1)
@@ -308,7 +308,7 @@ class CiscoSX300(SwitchDriver):
raise IndexError("Port %s not in trunk mode" % port)
regex = re.compile('(\d+)\s+\S+\s+(Tagged|Untagged)\s+Static')
self._cli("show interfaces switchport %s" % port)
- for line in self._read_paged_output():
+ for line in self._read_long_output():
match = regex.match(line)
if match:
vlans.append (int(match.group(1)))
@@ -348,22 +348,10 @@ class CiscoSX300(SwitchDriver):
def _end_configure(self):
self._cli("end")
- def _read_paged_output(self):
- buf = []
+ def _read_long_output(self):
prompt = self._prompt_name + '#'
- while True:
- index = self.connection.expect(['More:.*<return>.*$', prompt])
- if index == 0: # More: <space>
- for line in self.connection.before.split('\r\n'):
- buf.append(line.strip())
- self._cli(' ', False)
- elif index == 1: # Back to a prompt, says output is finished
- break
-
- for line in self.connection.before.split('\r\n'):
- buf.append(line.strip())
-
- return buf
+ self.connection.expect(prompt)
+ return self.connection.before.split('\r\n')
def _get_port_names(self):
logging.debug("Grabbing list of ports")
@@ -374,7 +362,7 @@ class CiscoSX300(SwitchDriver):
regex = re.compile('^(\w+).*(Up|Down)')
self._cli("show interfaces status detailed")
- for line in self._read_paged_output():
+ for line in self._read_long_output():
match = regex.match(line)
if match:
interfaces.append(match.group(1))
@@ -383,12 +371,12 @@ class CiscoSX300(SwitchDriver):
def _show_config(self):
logging.debug("Grabbing config")
self._cli("show running-config")
- return self._read_paged_output()
+ return self._read_long_output()
def _show_clock(self):
logging.debug("Grabbing time")
self._cli("show clock")
- return self._read_paged_output()
+ return self._read_long_output()
def _get_systemdata(self):
@@ -396,12 +384,12 @@ class CiscoSX300(SwitchDriver):
logging.debug("Grabbing system data")
self._cli("show system")
- for line in self._read_paged_output():
+ for line in self._read_long_output():
self._systemdata.append(line)
logging.debug("Grabbing system sw and hw versions")
self._cli("show version")
- for line in self._read_paged_output():
+ for line in self._read_long_output():
self._systemdata.append(line)
######################################