enhancement to ios shared module connection

this enhancement will cause the module to connect to the remote ios device
the first time a command wants to run instead of building a connection
immediately
This commit is contained in:
Peter Sprygada 2016-04-04 21:50:59 -04:00
parent c2fac6c808
commit cca084c89d

View file

@ -90,6 +90,11 @@ class NetworkModule(AnsibleModule):
super(NetworkModule, self).__init__(*args, **kwargs)
self.connection = None
self._config = None
self._connected = False
@property
def connected(self):
return self._connected
@property
def config(self):
@ -109,10 +114,10 @@ class NetworkModule(AnsibleModule):
try:
self.connection = Cli(self)
self.connection.connect()
self.execute('terminal length 0')
self.connection.send('terminal length 0')
if self.params['authorize']:
self.connection.authorize()
self._connected = True
except Exception, exc:
self.fail_json(msg=exc.message)
@ -126,6 +131,8 @@ class NetworkModule(AnsibleModule):
def execute(self, commands, **kwargs):
try:
if not self.connected:
self.connect()
return self.connection.send(commands, **kwargs)
except ShellError, exc:
self.fail_json(msg=exc.message, command=exc.command)
@ -134,6 +141,7 @@ class NetworkModule(AnsibleModule):
def disconnect(self):
self.connection.close()
self._connected = False
def parse_config(self, cfg):
return parse(cfg, indent=1)
@ -159,6 +167,5 @@ def get_module(**kwargs):
if not HAS_PARAMIKO:
module.fail_json(msg='paramiko is required but does not appear to be installed')
module.connect()
return module