bugfix for eos shared module and new optimization
This commit address to issues in the eos shard module. The first one is a bug fix for returning the running config when the transport is eapi. The shared module will now return config text instead of an object. The second is a optimization that delays when the eos module connects to the remote devices. This provies a performance enhancement when using ssh since the module doesn't default to connecting immediately
This commit is contained in:
parent
180e70b67a
commit
e3671a8a83
1 changed files with 13 additions and 6 deletions
|
@ -16,6 +16,7 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
NET_PASSWD_RE = re.compile(r"[\r\n]?password: $", re.I)
|
||||
|
||||
NET_COMMON_ARGS = dict(
|
||||
|
@ -27,7 +28,7 @@ NET_COMMON_ARGS = dict(
|
|||
auth_pass=dict(no_log=True),
|
||||
transport=dict(choices=['cli', 'eapi']),
|
||||
use_ssl=dict(default=True, type='bool'),
|
||||
provider=dict()
|
||||
provider=dict(type='dict')
|
||||
)
|
||||
|
||||
def to_list(val):
|
||||
|
@ -144,6 +145,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):
|
||||
|
@ -168,7 +174,7 @@ class NetworkModule(AnsibleModule):
|
|||
|
||||
try:
|
||||
self.connection.connect()
|
||||
self.execute('terminal length 0')
|
||||
self.connection.send('terminal length 0')
|
||||
|
||||
if self.params['authorize']:
|
||||
self.connection.authorize()
|
||||
|
@ -176,12 +182,13 @@ class NetworkModule(AnsibleModule):
|
|||
except Exception, exc:
|
||||
self.fail_json(msg=exc.message)
|
||||
|
||||
self._connected = True
|
||||
|
||||
def configure(self, commands):
|
||||
commands = to_list(commands)
|
||||
commands.insert(0, 'configure terminal')
|
||||
responses = self.execute(commands)
|
||||
responses.pop(0)
|
||||
|
||||
return responses
|
||||
|
||||
def config_replace(self, commands):
|
||||
|
@ -195,6 +202,8 @@ class NetworkModule(AnsibleModule):
|
|||
|
||||
def execute(self, commands, **kwargs):
|
||||
try:
|
||||
if not self.connected:
|
||||
self.connect()
|
||||
return self.connection.send(commands, **kwargs)
|
||||
except Exception, exc:
|
||||
self.fail_json(msg=exc.message, commands=commands)
|
||||
|
@ -213,7 +222,7 @@ class NetworkModule(AnsibleModule):
|
|||
return self.execute(cmd)[0]
|
||||
else:
|
||||
resp = self.execute(cmd, encoding='text')
|
||||
return resp[0]
|
||||
return resp[0]['output']
|
||||
|
||||
|
||||
def get_module(**kwargs):
|
||||
|
@ -230,7 +239,5 @@ def get_module(**kwargs):
|
|||
if module.params['transport'] == 'cli' and not HAS_PARAMIKO:
|
||||
module.fail_json(msg='paramiko is required but does not appear to be installed')
|
||||
|
||||
module.connect()
|
||||
|
||||
return module
|
||||
|
||||
|
|
Loading…
Reference in a new issue