updates eos modules to use socket (#21197)

* updates eos modules to use persistent connection socket
* removes split eos shared module and combines into one
* adds singular eos doc frag (eos_local to be removed after module updates)
* updates unit test cases
This commit is contained in:
Peter Sprygada 2017-02-13 20:22:10 -05:00 committed by GitHub
commit 14b942f3fb
23 changed files with 837 additions and 1348 deletions

View file

@ -33,7 +33,6 @@ description:
read from the device. This module includes an
argument that will cause the module to wait for a specific condition
before returning or timing out if the condition is not met.
extends_documentation_fragment: eos_local
options:
commands:
description:
@ -125,37 +124,15 @@ failed_conditions:
"""
import time
from functools import partial
from ansible.module_utils import eos
from ansible.module_utils import eos_local
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.local import LocalAnsibleModule
from ansible.module_utils.six import string_types
from ansible.module_utils.netcli import Conditional
from ansible.module_utils.network_common import ComplexList
SHARED_LIB = 'eos'
from ansible.module_utils.eos import run_commands
from ansible.module_utils.eos import eos_argument_spec, check_args
VALID_KEYS = ['command', 'output', 'prompt', 'response']
def get_ansible_module():
if SHARED_LIB == 'eos':
return LocalAnsibleModule
return AnsibleModule
def invoke(name, *args, **kwargs):
obj = globals().get(SHARED_LIB)
func = getattr(obj, name)
return func(*args, **kwargs)
run_commands = partial(invoke, 'run_commands')
def check_args(module, warnings):
if SHARED_LIB == 'eos_local':
eos_local.check_args(module, warnings)
def to_lines(stdout):
lines = list()
for item in stdout:
@ -193,7 +170,6 @@ def main():
"""entry point for module execution
"""
argument_spec = dict(
# { command: <str>, output: <str>, prompt: <str>, response: <str> }
commands=dict(type='list', required=True),
wait_for=dict(type='list', aliases=['waitfor']),
@ -203,16 +179,15 @@ def main():
interval=dict(default=1, type='int')
)
argument_spec.update(eos_local.eos_local_argument_spec)
argument_spec.update(eos_argument_spec)
cls = get_ansible_module()
module = cls(argument_spec=argument_spec, supports_check_mode=True)
warnings = list()
check_args(module, warnings)
module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)
result = {'changed': False}
warnings = list()
check_args(module, warnings)
commands = parse_commands(module, warnings)
if warnings:
result['warnings'] = warnings
@ -255,5 +230,4 @@ def main():
if __name__ == '__main__':
SHARED_LIB = 'eos_local'
main()