Skip to content

Commit

Permalink
Fix stray string in network_cli (ansible#51142)
Browse files Browse the repository at this point in the history
* Replace loose string that should be a byte string

* Replace byte string literals with string literals

* These, on the other hand, need to be byte strings
  • Loading branch information
Qalthos authored Jan 22, 2019
1 parent 335ee59 commit 8d4f7f5
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 61 deletions.
10 changes: 5 additions & 5 deletions lib/ansible/plugins/cliconf/aireos.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_device_info(self):
device_info = {}

device_info['network_os'] = 'aireos'
reply = self.get(b'show sysinfo')
reply = self.get('show sysinfo')
data = to_text(reply, errors='surrogate_or_strict').strip()

match = re.search(r'Product Version\.* (.*)', data)
Expand All @@ -46,7 +46,7 @@ def get_device_info(self):
if match:
device_info['network_os_hostname'] = match.group(1)

reply = self.get(b'show inventory')
reply = self.get('show inventory')
data = to_text(reply, errors='surrogate_or_strict').strip()

match = re.search(r'DESCR: \"(.*)\"', data, re.M)
Expand All @@ -59,14 +59,14 @@ def get_config(self, source='running', format='text'):
if source not in ('running', 'startup'):
return self.invalid_params("fetching configuration from %s is not supported" % source)
if source == 'running':
cmd = b'show run-config commands'
cmd = 'show run-config commands'
else:
cmd = b'show run-config startup-commands'
cmd = 'show run-config startup-commands'
return self.send_command(cmd)

@enable_mode
def edit_config(self, command):
for cmd in chain([b'config'], to_list(command), [b'end']):
for cmd in chain(['config'], to_list(command), ['end']):
self.send_command(cmd)

def get(self, command, prompt=None, answer=None, sendonly=False, check_all=False):
Expand Down
10 changes: 5 additions & 5 deletions lib/ansible/plugins/cliconf/aruba.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_device_info(self):
device_info = {}

device_info['network_os'] = 'aruba'
reply = self.get(b'show version')
reply = self.get('show version')
data = to_text(reply, errors='surrogate_or_strict').strip()

match = re.search(r'Version (\S+)', data)
Expand All @@ -46,7 +46,7 @@ def get_device_info(self):
if match:
device_info['network_os_model'] = match.group(1)

reply = self.get(b'show hostname')
reply = self.get('show hostname')
data = to_text(reply, errors='surrogate_or_strict').strip()

match = re.search(r'^Hostname is (.+)', data, re.M)
Expand All @@ -60,14 +60,14 @@ def get_config(self, source='running', format='text'):
if source not in ('running', 'startup'):
return self.invalid_params("fetching configuration from %s is not supported" % source)
if source == 'running':
cmd = b'show running-config all'
cmd = 'show running-config all'
else:
cmd = b'show startup-config'
cmd = 'show startup-config'
return self.send_command(cmd)

@enable_mode
def edit_config(self, command):
for cmd in chain([b'configure terminal'], to_list(command), [b'end']):
for cmd in chain(['configure terminal'], to_list(command), ['end']):
self.send_command(cmd)

def get(self, command, prompt=None, answer=None, sendonly=False, check_all=False):
Expand Down
8 changes: 4 additions & 4 deletions lib/ansible/plugins/cliconf/asa.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_device_info(self):
device_info = {}

device_info['network_os'] = 'asa'
reply = self.get(b'show version')
reply = self.get('show version')
data = to_text(reply, errors='surrogate_or_strict').strip()

match = re.search(r'Version (\S+),', data)
Expand All @@ -57,14 +57,14 @@ def get_config(self, source='running', format='text'):
if source not in ('running', 'startup'):
return self.invalid_params("fetching configuration from %s is not supported" % source)
if source == 'running':
cmd = b'show running-config all'
cmd = 'show running-config all'
else:
cmd = b'show startup-config'
cmd = 'show startup-config'
return self.send_command(cmd)

@enable_mode
def edit_config(self, command):
for cmd in chain([b'configure terminal'], to_list(command), [b'end']):
for cmd in chain(['configure terminal'], to_list(command), ['end']):
self.send_command(cmd)

def get(self, command, prompt=None, answer=None, sendonly=False, check_all=False):
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/plugins/cliconf/ce.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_device_info(self):
device_info = {}

device_info['network_os'] = 'ce'
reply = self.get(b'display version')
reply = self.get('display version')
data = to_text(reply, errors='surrogate_or_strict').strip()

match = re.search(r'^Huawei.+\n.+\Version\s+(\S+)', data)
Expand Down
10 changes: 5 additions & 5 deletions lib/ansible/plugins/cliconf/cnos.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def get_device_info(self):
device_info = {}

device_info['network_os'] = 'cnos'
reply = self.get(b'show sys-info')
reply = self.get('show sys-info')
data = to_text(reply, errors='surrogate_or_strict').strip()
host = self.get(b'show hostname')
host = self.get('show hostname')
hostname = to_text(host, errors='surrogate_or_strict').strip()
if data:
device_info['network_os_version'] = self.parse_version(data)
Expand Down Expand Up @@ -70,14 +70,14 @@ def get_config(self, source='running', format='text'):
msg = "fetching configuration from %s is not supported"
return self.invalid_params(msg % source)
if source == 'running':
cmd = b'show running-config'
cmd = 'show running-config'
else:
cmd = b'show startup-config'
cmd = 'show startup-config'
return self.send_command(cmd)

@enable_mode
def edit_config(self, command):
for cmd in chain([b'configure terminal'], to_list(command), [b'end']):
for cmd in chain(['configure terminal'], to_list(command), ['end']):
self.send_command(cmd)

def get(self, command, prompt=None, answer=None, sendonly=False, check_all=False):
Expand Down
8 changes: 4 additions & 4 deletions lib/ansible/plugins/cliconf/dellos10.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_device_info(self):
device_info = {}

device_info['network_os'] = 'dellos10'
reply = self.get(b'show version')
reply = self.get('show version')
data = to_text(reply, errors='surrogate_or_strict').strip()

match = re.search(r'OS Version (\S+)', data)
Expand All @@ -48,7 +48,7 @@ def get_device_info(self):
if match:
device_info['network_os_model'] = match.group(1)

reply = self.get(b'show running-configuration | grep hostname')
reply = self.get('show running-configuration | grep hostname')
data = to_text(reply, errors='surrogate_or_strict').strip()
match = re.search(r'^hostname (.+)', data, re.M)
if match:
Expand All @@ -61,9 +61,9 @@ def get_config(self, source='running', format='text'):
if source not in ('running', 'startup'):
return self.invalid_params("fetching configuration from %s is not supported" % source)
if source == 'running':
cmd = b'show running-config all'
cmd = 'show running-config all'
else:
cmd = b'show startup-config'
cmd = 'show startup-config'
return self.send_command(cmd)

@enable_mode
Expand Down
10 changes: 5 additions & 5 deletions lib/ansible/plugins/cliconf/dellos6.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_device_info(self):
device_info = {}

device_info['network_os'] = 'dellos6'
reply = self.get(b'show version')
reply = self.get('show version')
data = to_text(reply, errors='surrogate_or_strict').strip()

match = re.search(r'Software Version (\S+)', data)
Expand All @@ -48,7 +48,7 @@ def get_device_info(self):
if match:
device_info['network_os_model'] = match.group(1)

reply = self.get(b'show running-config | grep hostname')
reply = self.get('show running-config | grep hostname')
data = to_text(reply, errors='surrogate_or_strict').strip()
match = re.search(r'^hostname (.+)', data, re.M)
if match:
Expand All @@ -61,14 +61,14 @@ def get_config(self, source='running', format='text'):
if source not in ('running', 'startup'):
return self.invalid_params("fetching configuration from %s is not supported" % source)
# if source == 'running':
# cmd = b'show running-config all'
# cmd = 'show running-config all'
else:
cmd = b'show startup-config'
cmd = 'show startup-config'
return self.send_command(cmd)

@enable_mode
def edit_config(self, command):
for cmd in chain([b'configure terminal'], to_list(command), [b'end']):
for cmd in chain(['configure terminal'], to_list(command), ['end']):
self.send_command(cmd)

def get(self, command, prompt=None, answer=None, sendonly=False, check_all=False):
Expand Down
10 changes: 5 additions & 5 deletions lib/ansible/plugins/cliconf/dellos9.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_device_info(self):
device_info = {}

device_info['network_os'] = 'dellos9'
reply = self.get(b'show version')
reply = self.get('show version')
data = to_text(reply, errors='surrogate_or_strict').strip()

match = re.search(r'Software Version (\S+)', data)
Expand All @@ -48,7 +48,7 @@ def get_device_info(self):
if match:
device_info['network_os_model'] = match.group(1)

reply = self.get(b'show running-config | grep hostname')
reply = self.get('show running-config | grep hostname')
data = to_text(reply, errors='surrogate_or_strict').strip()
match = re.search(r'^hostname (.+)', data, re.M)
if match:
Expand All @@ -61,14 +61,14 @@ def get_config(self, source='running', format='text'):
if source not in ('running', 'startup'):
return self.invalid_params("fetching configuration from %s is not supported" % source)
# if source == 'running':
# cmd = b'show running-config all'
# cmd = 'show running-config all'
else:
cmd = b'show startup-config'
cmd = 'show startup-config'
return self.send_command(cmd)

@enable_mode
def edit_config(self, command):
for cmd in chain([b'configure terminal'], to_list(command), [b'end']):
for cmd in chain(['configure terminal'], to_list(command), ['end']):
self.send_command(cmd)

def get(self, command, prompt=None, answer=None, sendonly=False, check_all=False):
Expand Down
8 changes: 4 additions & 4 deletions lib/ansible/plugins/cliconf/enos.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_device_info(self):
device_info = {}

device_info['network_os'] = 'enos'
reply = self.get(b'show version')
reply = self.get('show version')
data = to_text(reply, errors='surrogate_or_strict').strip()

match = re.search(r'^Software Version (.*?) ', data, re.M | re.I)
Expand All @@ -57,14 +57,14 @@ def get_config(self, source='running', format='text'):
msg = "fetching configuration from %s is not supported"
return self.invalid_params(msg % source)
if source == 'running':
cmd = b'show running-config'
cmd = 'show running-config'
else:
cmd = b'show startup-config'
cmd = 'show startup-config'
return self.send_command(cmd)

@enable_mode
def edit_config(self, command):
for cmd in chain([b'configure terminal'], to_list(command), [b'end']):
for cmd in chain(['configure terminal'], to_list(command), ['end']):
self.send_command(cmd)

def get(self, command, prompt=None, answer=None, sendonly=False, check_all=False):
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/plugins/cliconf/exos.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_device_info(self):
device_info = {}
device_info['network_os'] = 'exos'

reply = self.get(b'show switch detail')
reply = self.get('show switch detail')
data = to_text(reply, errors='surrogate_or_strict').strip()

match = re.search(r'ExtremeXOS version (\S+)', data)
Expand All @@ -59,7 +59,7 @@ def get_config(self, source='running', flags=None):
cmd = 'show configuration'
else:
cmd = 'debug cfgmgr show configuration file'
reply = self.get(b'show switch | include "Config Selected"')
reply = self.get('show switch | include "Config Selected"')
data = to_text(reply, errors='surrogate_or_strict').strip()
match = re.search(r': +(\S+)\.cfg', data)
if match:
Expand Down
8 changes: 4 additions & 4 deletions lib/ansible/plugins/cliconf/ironware.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_device_info(self):
device_info = {}

device_info['network_os'] = 'ironware'
reply = self.send_command(b'show version')
reply = self.send_command('show version')
data = to_text(reply, errors='surrogate_or_strict').strip()

match = re.search(r'IronWare : Version (\S+),', data)
Expand All @@ -54,20 +54,20 @@ def get_config(self, source='running', format='text', flags=None):
raise ValueError("fetching configuration from %s is not supported" % source)

if source == 'running':
cmd = b'show running-config'
cmd = 'show running-config'
if flags is not None:
cmd += ' ' + ' '.join(flags)

else:
cmd = b'show configuration'
cmd = 'show configuration'
if flags is not None:
raise ValueError("flags are only supported with running-config")

return self.send_command(cmd)

@enable_mode
def edit_config(self, command):
for cmd in chain([b'configure terminal'], to_list(command), [b'end']):
for cmd in chain(['configure terminal'], to_list(command), ['end']):
self.send_command(cmd)

def get(self, command, prompt=None, answer=None, sendonly=False, check_all=False):
Expand Down
6 changes: 3 additions & 3 deletions lib/ansible/plugins/cliconf/nos.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ def get_device_info(self):
device_info = {}

device_info['network_os'] = 'nos'
reply = self.get(b'show version')
reply = self.get('show version')
data = to_text(reply, errors='surrogate_or_strict').strip()

match = re.search(r'Network Operating System Version: (\S+)', data)
if match:
device_info['network_os_version'] = match.group(1)

reply = self.get(b'show chassis')
reply = self.get('show chassis')
data = to_text(reply, errors='surrogate_or_strict').strip()

match = re.search(r'^Chassis Name:(\s+)(\S+)', data, re.M)
if match:
device_info['network_os_model'] = match.group(2)

reply = self.get(b'show running-config | inc "switch-attributes host-name"')
reply = self.get('show running-config | inc "switch-attributes host-name"')
data = to_text(reply, errors='surrogate_or_strict').strip()

match = re.search(r'switch-attributes host-name (\S+)', data, re.M)
Expand Down
8 changes: 4 additions & 4 deletions lib/ansible/plugins/cliconf/onyx.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ class Cliconf(CliconfBase):
def get_device_info(self):
device_info = {}

reply = self.get(b'show version | json-print')
reply = self.get('show version | json-print')
data = json.loads(reply)
device_info['network_os'] = data['Product name']
device_info['network_os_version'] = data['Product release']
device_info['network_os_version_summary'] = data['Version summary']
device_info['network_os_model'] = data['Product model']

reply = self.get(b'show hosts | include Hostname')
reply = self.get('show hosts | include Hostname')
data = to_text(reply, errors='surrogate_or_strict').strip()
hostname = data.split(':')[1]
hostname = hostname.strip()
Expand All @@ -52,12 +52,12 @@ def get_device_info(self):
def get_config(self, source='running', format='text'):
if source not in ('running',):
return self.invalid_params("fetching configuration from %s is not supported" % source)
cmd = b'show running-config'
cmd = 'show running-config'
return self.send_command(cmd)

@enable_mode
def edit_config(self, command):
for cmd in chain([b'configure terminal'], to_list(command), [b'exit']):
for cmd in chain(['configure terminal'], to_list(command), ['exit']):
self.send_command(cmd)

def get(self, command, prompt=None, answer=None, sendonly=False, check_all=False):
Expand Down
6 changes: 3 additions & 3 deletions lib/ansible/plugins/cliconf/routeros.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ def get_device_info(self):
device_info = {}
device_info['network_os'] = 'RouterOS'

resource = self.get(b'/system resource print')
resource = self.get('/system resource print')
data = to_text(resource, errors='surrogate_or_strict').strip()
match = re.search(r'version: (\S+)', data)
if match:
device_info['network_os_version'] = match.group(1)

routerboard = self.get(b'/system routerboard print')
routerboard = self.get('/system routerboard print')
data = to_text(routerboard, errors='surrogate_or_strict').strip()
match = re.search(r'model: (.+)$', data, re.M)
if match:
device_info['network_os_model'] = match.group(1)

identity = self.get(b'/system identity print')
identity = self.get('/system identity print')
data = to_text(identity, errors='surrogate_or_strict').strip()
match = re.search(r'name: (.+)$', data, re.M)
if match:
Expand Down
Loading

0 comments on commit 8d4f7f5

Please sign in to comment.