mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #16486 from privateip/netcmd
removes dependency on collections module from netcmd
This commit is contained in:
commit
216a845244
1 changed files with 5 additions and 15 deletions
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import collections
|
|
||||||
import itertools
|
import itertools
|
||||||
import shlex
|
import shlex
|
||||||
|
|
||||||
|
@ -153,26 +152,17 @@ class FailedConditionsError(Exception):
|
||||||
super(FailedConditionsError, self).__init__(msg)
|
super(FailedConditionsError, self).__init__(msg)
|
||||||
self.failed_conditions = failed_conditions
|
self.failed_conditions = failed_conditions
|
||||||
|
|
||||||
class CommandRunner(collections.Mapping):
|
class CommandRunner(object):
|
||||||
|
|
||||||
def __init__(self, module):
|
def __init__(self, module):
|
||||||
self.module = module
|
self.module = module
|
||||||
|
|
||||||
self.items = dict()
|
self.items = list()
|
||||||
self.conditionals = set()
|
self.conditionals = set()
|
||||||
|
|
||||||
self.retries = 10
|
self.retries = 10
|
||||||
self.interval = 1
|
self.interval = 1
|
||||||
|
|
||||||
def __getitem__(self, key):
|
|
||||||
return self.items[key]
|
|
||||||
|
|
||||||
def __len__(self):
|
|
||||||
return len(self.items)
|
|
||||||
|
|
||||||
def __iter__(self):
|
|
||||||
return iter(self.items)
|
|
||||||
|
|
||||||
def add_command(self, command, output=None):
|
def add_command(self, command, output=None):
|
||||||
self.module.cli.add_commands(command, output=output)
|
self.module.cli.add_commands(command, output=output)
|
||||||
|
|
||||||
|
@ -181,14 +171,14 @@ class CommandRunner(collections.Mapping):
|
||||||
|
|
||||||
def run_commands(self):
|
def run_commands(self):
|
||||||
responses = self.module.cli.run_commands()
|
responses = self.module.cli.run_commands()
|
||||||
for cmd, resp in itertools.izip(self.module.cli.commands, responses):
|
self.items = responses
|
||||||
self.items[str(cmd)] = resp
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while self.retries > 0:
|
while self.retries > 0:
|
||||||
self.run_commands()
|
self.run_commands()
|
||||||
|
|
||||||
for item in list(self.conditionals):
|
for item in list(self.conditionals):
|
||||||
if item(self.items.values()):
|
if item(self.items):
|
||||||
self.conditionals.remove(item)
|
self.conditionals.remove(item)
|
||||||
|
|
||||||
if not self.conditionals:
|
if not self.conditionals:
|
||||||
|
|
Loading…
Reference in a new issue