mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
parent
0bc35354ce
commit
4a067c3f50
3 changed files with 10 additions and 8 deletions
|
@ -35,6 +35,7 @@ from ansible.module_utils.network import add_argument, register_transport, to_li
|
|||
from ansible.module_utils.netcli import Command
|
||||
from ansible.module_utils.shell import CliBase
|
||||
from ansible.module_utils.urls import fetch_url, url_argument_spec
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
EAPI_FORMATS = ['json', 'text']
|
||||
|
||||
|
@ -88,7 +89,7 @@ class EosConfigMixin(object):
|
|||
self.execute(['no configure session %s' % session])
|
||||
except NetworkError:
|
||||
exc = get_exception()
|
||||
if 'timeout trying to send command' in exc.message:
|
||||
if 'timeout trying to send command' in to_native(exc):
|
||||
# try to get control back and get out of config mode
|
||||
if isinstance(self, Cli):
|
||||
self.execute(['\x03', 'end'])
|
||||
|
|
|
@ -32,6 +32,7 @@ from ansible.module_utils.basic import AnsibleModule
|
|||
from ansible.module_utils.basic import env_fallback, get_exception
|
||||
from ansible.module_utils.netcli import Cli, Command
|
||||
from ansible.module_utils.netcfg import Config
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
NET_TRANSPORT_ARGS = dict(
|
||||
host=dict(required=True),
|
||||
|
@ -105,7 +106,7 @@ class NetworkModule(AnsibleModule):
|
|||
self.fail_json(msg='Unknown transport or no default transport specified')
|
||||
except (TypeError, NetworkError):
|
||||
exc = get_exception()
|
||||
self.fail_json(msg=exc.message)
|
||||
self.fail_json(msg=to_native(exc))
|
||||
|
||||
if connect_on_load:
|
||||
self.connect()
|
||||
|
@ -151,7 +152,7 @@ class NetworkModule(AnsibleModule):
|
|||
self.params['port'], self.params['transport']))
|
||||
except NetworkError:
|
||||
exc = get_exception()
|
||||
self.fail_json(msg=exc.message)
|
||||
self.fail_json(msg=to_native(exc))
|
||||
|
||||
def disconnect(self):
|
||||
try:
|
||||
|
@ -160,7 +161,7 @@ class NetworkModule(AnsibleModule):
|
|||
self.log('disconnected from %s' % self.params['host'])
|
||||
except NetworkError:
|
||||
exc = get_exception()
|
||||
self.fail_json(msg=exc.message)
|
||||
self.fail_json(msg=to_native(exc))
|
||||
|
||||
def register_transport(transport, default=False):
|
||||
def register(cls):
|
||||
|
|
|
@ -32,6 +32,7 @@ except ImportError:
|
|||
from ansible.module_utils.basic import get_exception
|
||||
from ansible.module_utils.network import NetworkError
|
||||
from ansible.module_utils.six.moves import StringIO
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
ANSI_RE = [
|
||||
re.compile(r'(\x1b\[\?1h\x1b=)'),
|
||||
|
@ -51,7 +52,6 @@ class ShellError(Exception):
|
|||
|
||||
def __init__(self, msg, command=None):
|
||||
super(ShellError, self).__init__(msg)
|
||||
self.message = msg
|
||||
self.command = command
|
||||
|
||||
|
||||
|
@ -155,7 +155,7 @@ class Shell(object):
|
|||
raise ShellError("timeout trying to send command: %s" % cmd)
|
||||
except socket.error:
|
||||
exc = get_exception()
|
||||
raise ShellError("problem sending command to host: %s" % exc.message)
|
||||
raise ShellError("problem sending command to host: %s" % to_native(exc))
|
||||
return responses
|
||||
|
||||
def close(self):
|
||||
|
@ -228,7 +228,7 @@ class CliBase(object):
|
|||
except ShellError:
|
||||
exc = get_exception()
|
||||
raise NetworkError(
|
||||
msg='failed to connect to %s:%s' % (host, port), exc=str(exc)
|
||||
msg='failed to connect to %s:%s' % (host, port), exc=to_native(exc)
|
||||
)
|
||||
|
||||
self._connected = True
|
||||
|
@ -247,7 +247,7 @@ class CliBase(object):
|
|||
return self.shell.send(commands)
|
||||
except ShellError:
|
||||
exc = get_exception()
|
||||
raise NetworkError(exc.message, commands=commands)
|
||||
raise NetworkError(to_native(exc), commands=commands)
|
||||
|
||||
def run_commands(self, commands):
|
||||
return self.execute(to_list(commands))
|
||||
|
|
Loading…
Reference in a new issue