Move Conditional class to netcfg. Added error handling for connect and execute methods.

Fix comments
This commit is contained in:
chouseknecht 2016-02-09 14:59:44 -05:00
commit 5a45ca8bb1
4 changed files with 147 additions and 34 deletions

View file

@ -38,6 +38,7 @@ def to_list(val):
else:
return list()
class Eapi(object):
def __init__(self, module):
@ -107,6 +108,7 @@ class Eapi(object):
return response['result']
class Cli(object):
def __init__(self, module):
@ -121,15 +123,20 @@ 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 authorize(self):
passwd = self.module.params['auth_pass']
self.send(Command('enable', prompt=NET_PASSWD_RE, response=passwd))
def send(self, commands, encoding='text'):
def send(self, commands):
return self.shell.send(commands)
class NetworkModule(AnsibleModule):
def __init__(self, *args, **kwargs):