mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-10 18:34:03 -07:00
Fix use of bytes in cliconf plugins for Python 3 (#37715)
* Remove raw byte-strings from cliconf plugins of supported platforms + edgeos Remove uses of to_bytes, too * Update CliConfBase docstring to reflect current position on byte strings
This commit is contained in:
parent
be6628cd3d
commit
3b3c72f3e5
9 changed files with 41 additions and 48 deletions
|
@ -10,7 +10,7 @@ import json
|
|||
|
||||
from itertools import chain
|
||||
|
||||
from ansible.module_utils._text import to_bytes, to_text
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible.module_utils.network.common.utils import to_list
|
||||
from ansible.plugins.cliconf import CliconfBase
|
||||
|
||||
|
@ -21,7 +21,7 @@ class Cliconf(CliconfBase):
|
|||
device_info = {}
|
||||
|
||||
device_info['network_os'] = 'edgeos'
|
||||
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*v?(\S+)', data)
|
||||
|
@ -32,24 +32,21 @@ class Cliconf(CliconfBase):
|
|||
if match:
|
||||
device_info['network_os_model'] = match.group(1)
|
||||
|
||||
reply = self.get(b'show host name')
|
||||
reply = self.get('show host name')
|
||||
reply = to_text(reply, errors='surrogate_or_strict').strip()
|
||||
device_info['network_os_hostname'] = reply
|
||||
|
||||
return device_info
|
||||
|
||||
def get_config(self, source='running', format='text'):
|
||||
return self.send_command(b'show configuration commands')
|
||||
return self.send_command('show configuration commands')
|
||||
|
||||
def edit_config(self, command):
|
||||
for cmd in chain([b'configure'], to_list(command)):
|
||||
for cmd in chain(['configure'], to_list(command)):
|
||||
self.send_command(cmd)
|
||||
|
||||
def get(self, command, prompt=None, answer=None, sendonly=False):
|
||||
return self.send_command(to_bytes(command),
|
||||
prompt=to_bytes(prompt),
|
||||
answer=to_bytes(answer),
|
||||
sendonly=sendonly)
|
||||
return self.send_command(command, prompt=prompt, answer=answer, sendonly=sendonly)
|
||||
|
||||
def commit(self, comment=None):
|
||||
if comment:
|
||||
|
@ -59,7 +56,7 @@ class Cliconf(CliconfBase):
|
|||
self.send_command(command)
|
||||
|
||||
def discard_changes(self, *args, **kwargs):
|
||||
self.send_command(b'discard')
|
||||
self.send_command('discard')
|
||||
|
||||
def get_capabilities(self):
|
||||
result = {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue