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

@ -35,7 +35,6 @@ description:
commands that are not already configured. The config source can
be a set of commands or a template.
deprecated: Deprecated in 2.2. Use M(eos_config) instead
extends_documentation_fragment: eos_local
options:
src:
description:
@ -124,33 +123,10 @@ responses:
"""
import re
from ansible.module_utils import eos
from ansible.module_utils import eos_local
from ansible.module_utils.local import LocalAnsibleModule
from ansible.module_utils.eos import load_config, get_config
from ansible.module_utils.basic import AnsibleModle
from ansible.module_utils.netcfg import NetworkConfig, dumps
SHARED_LIB = 'eos'
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)
load_config = partial(invoke, 'load_config')
get_config = partial(invoke, 'get_config')
def check_args(module):
warnings = list()
if SHARED_LIB == 'eos_local':
eos_local.check_args(module)
return warnings
def get_current_config(module):
config = module.params.get('config')
if not config and not module.params['force']:
@ -201,11 +177,9 @@ def main():
mutually_exclusive = [('config', 'backup'), ('config', 'force')]
cls = get_ansible_module()
module = cls(argument_spec=argument_spec,
mutually_exclusive=mutually_exclusive,
supports_check_mode=True)
module = AnsibleModule(argument_spec=argument_spec,
mutually_exclusive=mutually_exclusive,
supports_check_mode=True)
warnings = check_args(module)
@ -245,5 +219,4 @@ def main():
module.exit_json(**result)
if __name__ == '__main__':
SHARED_LIB = 'eos_local'
main()

View file

@ -16,9 +16,11 @@
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
ANSIBLE_METADATA = {'status': ['preview'],
'supported_by': 'community',
'version': '1.0'}
ANSIBLE_METADATA = {
'status': ['preview'],
'supported_by': 'community',
'version': '1.0'
}
DOCUMENTATION = """
---
@ -30,8 +32,6 @@ description:
- This will configure both login and motd banners on remote devices
running Arista EOS. It allows playbooks to add or remote
banner text from the active running configuration.
notes:
- This module requires connection to be network_cli
options:
banner:
description:
@ -91,23 +91,8 @@ session_name:
returned: always
type: str
sample: ansible_1479315771
start:
description: The time the job started
returned: always
type: str
sample: "2016-11-16 10:38:15.126146"
end:
description: The time the job ended
returned: always
type: str
sample: "2016-11-16 10:38:25.595612"
delta:
description: The time elapsed to perform all operations
returned: always
type: str
sample: "0:00:10.469466"
"""
from ansible.module_utils.local import LocalAnsibleModule
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.eos import load_config, run_commands
def map_obj_to_commands(updates, module):
@ -156,9 +141,9 @@ def main():
required_if = [('state', 'present', ('text',))]
module = LocalAnsibleModule(argument_spec=argument_spec,
required_if=required_if,
supports_check_mode=True)
module = AnsibleModule(argument_spec=argument_spec,
required_if=required_if,
supports_check_mode=True)
result = {'changed': False}

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()

View file

@ -34,7 +34,6 @@ description:
an implementation for working with eos configuration sections in
a deterministic way. This module works with either CLI or eAPI
transports.
extends_documentation_fragment: eos_local
options:
lines:
description:
@ -203,61 +202,21 @@ backup_path:
returned: when backup is yes
type: path
sample: /playbooks/ansible/backup/eos_config.2016-07-16@22:28:34
start:
description: The time the job started
returned: always
type: str
sample: "2016-11-16 10:38:15.126146"
end:
description: The time the job ended
returned: always
type: str
sample: "2016-11-16 10:38:25.595612"
delta:
description: The time elapsed to perform all operations
returned: always
type: str
sample: "0:00:10.469466"
"""
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.netcfg import NetworkConfig, dumps
SHARED_LIB = 'eos'
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')
get_config = partial(invoke, 'get_config')
load_config = partial(invoke, 'load_config')
supports_sessions = partial(invoke, 'supports_sessions')
from ansible.module_utils.eos import get_config, load_config
from ansible.module_utils.eos import run_commands
from ansible.module_utils.eos import eos_argument_spec
from ansible.module_utils.eos import check_args as eos_check_args
def check_args(module, warnings):
if SHARED_LIB == 'eos_local':
eos_local.check_args(module)
eos_check_args(module, warnings)
if module.params['force']:
warnings.append('The force argument is deprecated, please use '
'match=none instead. This argument will be '
'removed in the future')
if not supports_sessions(module):
warnings.append('The current version of EOS on the remote device does '
'not support configuration sessions. The commit '
'argument will be ignored')
def get_candidate(module):
candidate = NetworkConfig(indent=3)
if module.params['src']:
@ -330,7 +289,7 @@ def main():
force=dict(default=False, type='bool'),
)
argument_spec.update(eos_local.eos_local_argument_spec)
argument_spec.update(eos_argument_spec)
mutually_exclusive = [('lines', 'src')]
@ -339,12 +298,10 @@ def main():
('replace', 'block', ['lines']),
('replace', 'config', ['src'])]
cls = get_ansible_module()
module = cls(argument_spec=argument_spec,
mutually_exclusive=mutually_exclusive,
required_if=required_if,
supports_check_mode=True)
module = AnsibleModule(argument_spec=argument_spec,
mutually_exclusive=mutually_exclusive,
required_if=required_if,
supports_check_mode=True)
if module.params['force'] is True:
module.params['match'] = 'none'
@ -371,5 +328,4 @@ def main():
if __name__ == '__main__':
SHARED_LIB = 'eos_local'
main()

View file

@ -178,25 +178,10 @@ session_name:
returned: when changed is True
type: str
sample: ansible_1479315771
start:
description: The time the job started
returned: always
type: str
sample: "2016-11-16 10:38:15.126146"
end:
description: The time the job ended
returned: always
type: str
sample: "2016-11-16 10:38:25.595612"
delta:
description: The time elapsed to perform all operations
returned: always
type: str
sample: "0:00:10.469466"
"""
import re
from ansible.module_utils.local import LocalAnsibleModule
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.eos import run_commands, load_config
from ansible.module_utils.six import iteritems
@ -335,8 +320,8 @@ def main():
state=dict(default='started', choices=['stopped', 'started']),
)
module = LocalAnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)
module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)
result = {'changed': False}

View file

@ -34,7 +34,6 @@ description:
base network fact keys with C(ansible_net_<fact>). The facts
module will always collect a base set of facts from the device
and can enable or disable collection of additional facts.
extends_documentation_fragment: eos_local
options:
gather_subset:
description:
@ -135,32 +134,10 @@ ansible_net_neighbors:
"""
import re
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 iteritems
SHARED_LIB = 'eos'
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)
from ansible.module_utils.eos import run_commands
from ansible.module_utils.eos import eos_argument_spec, check_args
class FactsBase(object):
@ -335,10 +312,10 @@ def main():
gather_subset=dict(default=['!config'], type='list')
)
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)
module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)
warnings = list()
check_args(module, warnings)
@ -397,5 +374,4 @@ def main():
if __name__ == '__main__':
SHARED_LIB = 'eos_local'
main()

View file

@ -137,25 +137,10 @@ session_name:
returned: when changed is True
type: str
sample: ansible_1479315771
start:
description: The time the job started
returned: always
type: str
sample: "2016-11-16 10:38:15.126146"
end:
description: The time the job ended
returned: always
type: str
sample: "2016-11-16 10:38:25.595612"
delta:
description: The time elapsed to perform all operations
returned: always
type: str
sample: "0:00:10.469466"
"""
import re
from ansible.module_utils.local import LocalAnsibleModule
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network_common import ComplexList
from ansible.module_utils.eos import load_config, get_config
@ -319,8 +304,8 @@ def main():
state=dict(default='present', choices=['present', 'absent'])
)
module = LocalAnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)
module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)
result = {'changed': False}

View file

@ -32,8 +32,6 @@ description:
either individual usernames or the collection of usernames in the
current running config. It also supports purging usernames from the
configuration that are not explicitly defined.
notes:
- This module requires connection to be network_cli
options:
users:
description:
@ -142,27 +140,12 @@ session_name:
returned: when changed is True
type: str
sample: ansible_1479315771
start:
description: The time the job started
returned: always
type: str
sample: "2016-11-16 10:38:15.126146"
end:
description: The time the job ended
returned: always
type: str
sample: "2016-11-16 10:38:25.595612"
delta:
description: The time elapsed to perform all operations
returned: always
type: str
sample: "0:00:10.469466"
"""
import re
from functools import partial
from ansible.module_utils.local import LocalAnsibleModule
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.eos import get_config, load_config
from ansible.module_utils.six import iteritems
@ -333,9 +316,9 @@ def main():
mutually_exclusive = [('username', 'users')]
module = LocalAnsibleModule(argument_spec=argument_spec,
mutually_exclusive=mutually_exclusive,
supports_check_mode=True)
module = AnsibleModule(argument_spec=argument_spec,
mutually_exclusive=mutually_exclusive,
supports_check_mode=True)
result = {'changed': False}