mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 22:00:22 -07:00
Move Conditional class to netcfg. Added error handling for connect and execute methods.
Fix comments
This commit is contained in:
parent
9286143b53
commit
5a45ca8bb1
4 changed files with 147 additions and 34 deletions
|
@ -128,6 +128,7 @@ class Nxapi(object):
|
|||
|
||||
return result
|
||||
|
||||
|
||||
class Cli(object):
|
||||
|
||||
def __init__(self, module):
|
||||
|
@ -142,11 +143,16 @@ class Cli(object):
|
|||
password = self.module.params['password']
|
||||
|
||||
self.shell = Shell()
|
||||
self.shell.open(host, port=port, username=username, password=password)
|
||||
|
||||
try:
|
||||
self.shell.open(host, port=port, username=username, password=password)
|
||||
except Exception, exc:
|
||||
self.module.fail_json('Failed to connect to {0}:{1} - {2}'.format(host, port, str(exc)))
|
||||
|
||||
def send(self, commands, encoding='text'):
|
||||
return self.shell.send(commands)
|
||||
|
||||
|
||||
class NetworkModule(AnsibleModule):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
@ -190,7 +196,10 @@ class NetworkModule(AnsibleModule):
|
|||
return responses
|
||||
|
||||
def execute(self, commands, **kwargs):
|
||||
return self.connection.send(commands, **kwargs)
|
||||
try:
|
||||
return self.connection.send(commands, **kwargs)
|
||||
except Exception, exc:
|
||||
self.fail_json(msg=exc.message, commands=commands)
|
||||
|
||||
def disconnect(self):
|
||||
self.connection.close()
|
||||
|
@ -206,6 +215,7 @@ class NetworkModule(AnsibleModule):
|
|||
response = self.execute(cmd)
|
||||
return response[0]
|
||||
|
||||
|
||||
def get_module(**kwargs):
|
||||
"""Return instance of NetworkModule
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue