diff options
author | Peter Sprygada <privateip@users.noreply.github.com> | 2016-07-04 22:34:50 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-04 22:34:50 -0400 |
commit | d9546d636782c14b4716c87ee492ba5f79624d14 (patch) | |
tree | e7f5db4edc0e257fcc133809b7043d026cb27f4b | |
parent | 54db1df24499ca99f44c61b24bef59176ccdfa21 (diff) | |
parent | 527e4196b261bc013d4cab08150853169136c0cf (diff) | |
download | ansible-d9546d636782c14b4716c87ee492ba5f79624d14.tar.gz |
Merge pull request #16572 from privateip/netcmd
adds new method to return specific response from command to netcmd
-rw-r--r-- | lib/ansible/module_utils/netcmd.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/ansible/module_utils/netcmd.py b/lib/ansible/module_utils/netcmd.py index c5eb197d13..651c437dd0 100644 --- a/lib/ansible/module_utils/netcmd.py +++ b/lib/ansible/module_utils/netcmd.py @@ -163,9 +163,23 @@ class CommandRunner(object): self.retries = 10 self.interval = 1 + self._cache = dict() + def add_command(self, command, output=None): self.module.cli.add_commands(command, output=output) + def get_command(self, command): + try: + cmdobj = self._cache[command] + return cmdobj.response + except KeyError: + for cmd in self.module.cli.commands: + if str(cmd) == command: + self._cache[command] = cmd + return cmd.response + raise ValueError("command '%s' not found" % command) + + def add_conditional(self, condition): self.conditionals.add(Conditional(condition)) |