From d34f7c24d9c718af2b27303814b6c6ae016a8b79 Mon Sep 17 00:00:00 2001 From: d3justi Date: Sat, 17 Sep 2016 10:38:24 -0500 Subject: Fixed transport issues when calling self.execute from Cli --- lib/ansible/module_utils/nxos.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/ansible/module_utils/nxos.py b/lib/ansible/module_utils/nxos.py index 7ba3018317..058c0b946f 100644 --- a/lib/ansible/module_utils/nxos.py +++ b/lib/ansible/module_utils/nxos.py @@ -43,7 +43,10 @@ class NxapiConfigMixin(object): def load_config(self, config): checkpoint = 'ansible_%s' % int(time.time()) - self.execute(['checkpoint %s' % checkpoint], output='text') + try: + self.execute(['checkpoint %s' % checkpoint], output='text') + except TypeError: + self.execute(['checkpoint %s' % checkpoint]) try: self.configure(config) @@ -51,14 +54,21 @@ class NxapiConfigMixin(object): self.load_checkpoint(checkpoint) raise - self.execute(['no checkpoint %s' % checkpoint], output='text') + try: + self.execute(['no checkpoint %s' % checkpoint], output='text') + except TypeError: + self.execute(['no checkpoint %s' % checkpoint]) def save_config(self, **kwargs): self.execute(['copy running-config startup-config']) def load_checkpoint(self, checkpoint): - self.execute(['rollback running-config checkpoint %s' % checkpoint, - 'no checkpoint %s' % checkpoint], output='text') + try: + self.execute(['rollback running-config checkpoint %s' % checkpoint, + 'no checkpoint %s' % checkpoint], output='text') + except TypeError: + self.execute(['rollback running-config checkpoint %s' % checkpoint, + 'no checkpoint %s' % checkpoint]) class Nxapi(NxapiConfigMixin): -- cgit v1.2.1 From 07f3b27351e20434a68198a095bd93bdfbf4e589 Mon Sep 17 00:00:00 2001 From: d3justi Date: Sat, 17 Sep 2016 14:32:03 -0500 Subject: added a couple more checks --- lib/ansible/module_utils/nxos.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/nxos.py b/lib/ansible/module_utils/nxos.py index 058c0b946f..b364468bf4 100644 --- a/lib/ansible/module_utils/nxos.py +++ b/lib/ansible/module_utils/nxos.py @@ -201,14 +201,20 @@ class Nxapi(NxapiConfigMixin): for cmd in commands: if output and output != cmd.output: - responses.extend(self.execute(cmds, output=output)) + try: + responses.extend(self.execute(cmds, output=output)) + except ValueError: + responses.extend(self.execute(cmds)) cmds = list() output = cmd.output cmds.append(str(cmd)) if cmds: - responses.extend(self.execute(cmds, output=output)) + try: + responses.extend(self.execute(cmds, output=output)) + except ValueError: + responses.extend(self.execute(cmds)) return responses @@ -217,7 +223,10 @@ class Nxapi(NxapiConfigMixin): def configure(self, commands): commands = to_list(commands) - return self.execute(commands, output='config') + try: + return self.execute(commands, output='config') + except ValueError: + return self.execute(commands) def _jsonify(self, data): for encoding in ("utf-8", "latin-1"): -- cgit v1.2.1 From 261666a01bc36bf176ba90b812bec9d2727e4596 Mon Sep 17 00:00:00 2001 From: d3justi Date: Sat, 17 Sep 2016 14:40:00 -0500 Subject: Removed checks from Nxapi class. D\'oh\! --- lib/ansible/module_utils/nxos.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/lib/ansible/module_utils/nxos.py b/lib/ansible/module_utils/nxos.py index b364468bf4..058c0b946f 100644 --- a/lib/ansible/module_utils/nxos.py +++ b/lib/ansible/module_utils/nxos.py @@ -201,20 +201,14 @@ class Nxapi(NxapiConfigMixin): for cmd in commands: if output and output != cmd.output: - try: - responses.extend(self.execute(cmds, output=output)) - except ValueError: - responses.extend(self.execute(cmds)) + responses.extend(self.execute(cmds, output=output)) cmds = list() output = cmd.output cmds.append(str(cmd)) if cmds: - try: - responses.extend(self.execute(cmds, output=output)) - except ValueError: - responses.extend(self.execute(cmds)) + responses.extend(self.execute(cmds, output=output)) return responses @@ -223,10 +217,7 @@ class Nxapi(NxapiConfigMixin): def configure(self, commands): commands = to_list(commands) - try: - return self.execute(commands, output='config') - except ValueError: - return self.execute(commands) + return self.execute(commands, output='config') def _jsonify(self, data): for encoding in ("utf-8", "latin-1"): -- cgit v1.2.1