mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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:
parent
c2fac6c808
commit
cca084c89d
1 changed files with 10 additions and 3 deletions
|
@ -90,6 +90,11 @@ class NetworkModule(AnsibleModule):
|
||||||
super(NetworkModule, self).__init__(*args, **kwargs)
|
super(NetworkModule, self).__init__(*args, **kwargs)
|
||||||
self.connection = None
|
self.connection = None
|
||||||
self._config = None
|
self._config = None
|
||||||
|
self._connected = False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def connected(self):
|
||||||
|
return self._connected
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def config(self):
|
def config(self):
|
||||||
|
@ -109,10 +114,10 @@ class NetworkModule(AnsibleModule):
|
||||||
try:
|
try:
|
||||||
self.connection = Cli(self)
|
self.connection = Cli(self)
|
||||||
self.connection.connect()
|
self.connection.connect()
|
||||||
self.execute('terminal length 0')
|
self.connection.send('terminal length 0')
|
||||||
|
|
||||||
if self.params['authorize']:
|
if self.params['authorize']:
|
||||||
self.connection.authorize()
|
self.connection.authorize()
|
||||||
|
self._connected = True
|
||||||
|
|
||||||
except Exception, exc:
|
except Exception, exc:
|
||||||
self.fail_json(msg=exc.message)
|
self.fail_json(msg=exc.message)
|
||||||
|
@ -126,6 +131,8 @@ class NetworkModule(AnsibleModule):
|
||||||
|
|
||||||
def execute(self, commands, **kwargs):
|
def execute(self, commands, **kwargs):
|
||||||
try:
|
try:
|
||||||
|
if not self.connected:
|
||||||
|
self.connect()
|
||||||
return self.connection.send(commands, **kwargs)
|
return self.connection.send(commands, **kwargs)
|
||||||
except ShellError, exc:
|
except ShellError, exc:
|
||||||
self.fail_json(msg=exc.message, command=exc.command)
|
self.fail_json(msg=exc.message, command=exc.command)
|
||||||
|
@ -134,6 +141,7 @@ class NetworkModule(AnsibleModule):
|
||||||
|
|
||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
|
self._connected = False
|
||||||
|
|
||||||
def parse_config(self, cfg):
|
def parse_config(self, cfg):
|
||||||
return parse(cfg, indent=1)
|
return parse(cfg, indent=1)
|
||||||
|
@ -159,6 +167,5 @@ def get_module(**kwargs):
|
||||||
if not HAS_PARAMIKO:
|
if not HAS_PARAMIKO:
|
||||||
module.fail_json(msg='paramiko is required but does not appear to be installed')
|
module.fail_json(msg='paramiko is required but does not appear to be installed')
|
||||||
|
|
||||||
module.connect()
|
|
||||||
return module
|
return module
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue