|
|
@ -29,6 +29,7 @@ NET_COMMON_ARGS = dict(
|
|
|
|
provider=dict()
|
|
|
|
provider=dict()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def to_list(val):
|
|
|
|
def to_list(val):
|
|
|
|
if isinstance(val, (list, tuple)):
|
|
|
|
if isinstance(val, (list, tuple)):
|
|
|
|
return list(val)
|
|
|
|
return list(val)
|
|
|
@ -37,6 +38,7 @@ def to_list(val):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return list()
|
|
|
|
return list()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Cli(object):
|
|
|
|
class Cli(object):
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, module):
|
|
|
|
def __init__(self, module):
|
|
|
@ -51,7 +53,11 @@ class Cli(object):
|
|
|
|
password = self.module.params['password']
|
|
|
|
password = self.module.params['password']
|
|
|
|
|
|
|
|
|
|
|
|
self.shell = Shell()
|
|
|
|
self.shell = Shell()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.shell.open(host, port=port, username=username, password=password)
|
|
|
|
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):
|
|
|
|
def authorize(self):
|
|
|
|
passwd = self.module.params['auth_pass']
|
|
|
|
passwd = self.module.params['auth_pass']
|
|
|
@ -60,6 +66,7 @@ class Cli(object):
|
|
|
|
def send(self, commands):
|
|
|
|
def send(self, commands):
|
|
|
|
return self.shell.send(commands)
|
|
|
|
return self.shell.send(commands)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NetworkModule(AnsibleModule):
|
|
|
|
class NetworkModule(AnsibleModule):
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
@ -101,7 +108,10 @@ class NetworkModule(AnsibleModule):
|
|
|
|
return responses
|
|
|
|
return responses
|
|
|
|
|
|
|
|
|
|
|
|
def execute(self, commands, **kwargs):
|
|
|
|
def execute(self, commands, **kwargs):
|
|
|
|
return self.connection.send(commands)
|
|
|
|
try:
|
|
|
|
|
|
|
|
return self.connection.send(commands, **kwargs)
|
|
|
|
|
|
|
|
except Exception, exc:
|
|
|
|
|
|
|
|
self.fail_json(msg=exc.message, commands=commands)
|
|
|
|
|
|
|
|
|
|
|
|
def disconnect(self):
|
|
|
|
def disconnect(self):
|
|
|
|
self.connection.close()
|
|
|
|
self.connection.close()
|
|
|
@ -115,6 +125,7 @@ class NetworkModule(AnsibleModule):
|
|
|
|
cmd += ' all'
|
|
|
|
cmd += ' all'
|
|
|
|
return self.execute(cmd)[0]
|
|
|
|
return self.execute(cmd)[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_module(**kwargs):
|
|
|
|
def get_module(**kwargs):
|
|
|
|
"""Return instance of NetworkModule
|
|
|
|
"""Return instance of NetworkModule
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|