diff options
Diffstat (limited to 'lib/ansible/modules/network/eos')
-rw-r--r-- | lib/ansible/modules/network/eos/eos_banner.py | 3 | ||||
-rw-r--r-- | lib/ansible/modules/network/eos/eos_command.py | 4 | ||||
-rw-r--r-- | lib/ansible/modules/network/eos/eos_config.py | 1 | ||||
-rw-r--r-- | lib/ansible/modules/network/eos/eos_eapi.py | 14 | ||||
-rw-r--r-- | lib/ansible/modules/network/eos/eos_facts.py | 4 | ||||
-rw-r--r-- | lib/ansible/modules/network/eos/eos_system.py | 17 | ||||
-rw-r--r-- | lib/ansible/modules/network/eos/eos_user.py | 5 |
7 files changed, 39 insertions, 9 deletions
diff --git a/lib/ansible/modules/network/eos/eos_banner.py b/lib/ansible/modules/network/eos/eos_banner.py index 0fbaa393af..d080fef06c 100644 --- a/lib/ansible/modules/network/eos/eos_banner.py +++ b/lib/ansible/modules/network/eos/eos_banner.py @@ -126,6 +126,7 @@ def map_obj_to_commands(updates, module): return commands + def map_config_to_obj(module): output = run_commands(module, ['show banner %s' % module.params['banner']]) obj = {'banner': module.params['banner'], 'state': 'absent'} @@ -144,6 +145,7 @@ def map_config_to_obj(module): obj['state'] = 'present' return obj + def map_params_to_obj(module): text = module.params['text'] if text: @@ -155,6 +157,7 @@ def map_params_to_obj(module): 'state': module.params['state'] } + def main(): """ main entry point for module execution """ diff --git a/lib/ansible/modules/network/eos/eos_command.py b/lib/ansible/modules/network/eos/eos_command.py index 3fe90bd72a..7d4c4cd18b 100644 --- a/lib/ansible/modules/network/eos/eos_command.py +++ b/lib/ansible/modules/network/eos/eos_command.py @@ -146,6 +146,7 @@ from ansible.module_utils.network.eos.eos import eos_argument_spec, check_args VALID_KEYS = ['command', 'output', 'prompt', 'response'] + def to_lines(stdout): lines = list() for item in stdout: @@ -154,6 +155,7 @@ def to_lines(stdout): lines.append(item) return lines + def parse_commands(module, warnings): spec = dict( command=dict(key=True), @@ -176,12 +178,14 @@ def parse_commands(module, warnings): return commands + def to_cli(obj): cmd = obj['command'] if obj.get('output') == 'json': cmd += ' | json' return cmd + def main(): """entry point for module execution """ diff --git a/lib/ansible/modules/network/eos/eos_config.py b/lib/ansible/modules/network/eos/eos_config.py index f34334e104..88b3fbc4f0 100644 --- a/lib/ansible/modules/network/eos/eos_config.py +++ b/lib/ansible/modules/network/eos/eos_config.py @@ -403,7 +403,6 @@ def main(): result['changed'] = True - running_config = None startup_config = None diff --git a/lib/ansible/modules/network/eos/eos_eapi.py b/lib/ansible/modules/network/eos/eos_eapi.py index f65f4403c6..22d4a8d1d8 100644 --- a/lib/ansible/modules/network/eos/eos_eapi.py +++ b/lib/ansible/modules/network/eos/eos_eapi.py @@ -187,6 +187,7 @@ from ansible.module_utils.network.eos.eos import run_commands, load_config from ansible.module_utils.six import iteritems from ansible.module_utils.network.eos.eos import eos_argument_spec, check_args + def check_transport(module): transport = module.params['transport'] provider_transport = (module.params['provider'] or {}).get('transport') @@ -194,18 +195,22 @@ def check_transport(module): if 'eapi' in (transport, provider_transport): module.fail_json(msg='eos_eapi module is only supported over cli transport') + def validate_http_port(value, module): if not 1 <= value <= 65535: module.fail_json(msg='http_port must be between 1 and 65535') + def validate_https_port(value, module): if not 1 <= value <= 65535: module.fail_json(msg='http_port must be between 1 and 65535') + def validate_local_http_port(value, module): if not 1 <= value <= 65535: module.fail_json(msg='http_port must be between 1 and 65535') + def validate_vrf(value, module): out = run_commands(module, ['show vrf']) configured_vrfs = re.findall(r'^\s+(\w+)(?=\s)', out[0], re.M) @@ -213,11 +218,12 @@ def validate_vrf(value, module): if value not in configured_vrfs: module.fail_json(msg='vrf `%s` is not configured on the system' % value) + def map_obj_to_commands(updates, module, warnings): commands = list() want, have = updates - needs_update = lambda x: want.get(x) is not None and (want.get(x) != have.get(x)) + def needs_update(x): return want.get(x) is not None and (want.get(x) != have.get(x)) def add(cmd): if 'management api http-commands' not in commands: @@ -266,7 +272,6 @@ def map_obj_to_commands(updates, module, warnings): elif want['state'] == 'started': add('no shutdown') - if needs_update('vrf'): add('vrf %s' % want['vrf']) # switching operational vrfs here @@ -278,6 +283,7 @@ def map_obj_to_commands(updates, module, warnings): return commands + def parse_state(data): if data[0]['enabled']: return 'started' @@ -299,6 +305,7 @@ def map_config_to_obj(module): 'state': parse_state(out) } + def map_params_to_obj(module): obj = { 'http': module.params['http'], @@ -320,6 +327,7 @@ def map_params_to_obj(module): return obj + def verify_state(updates, module): want, have = updates @@ -348,6 +356,7 @@ def verify_state(updates, module): if timeout == 0: module.fail_json(msg='timeout expired before eapi running state changed') + def collect_facts(module, result): out = run_commands(module, ['show management api http-commands | json']) facts = dict(eos_eapi_urls=dict()) @@ -359,6 +368,7 @@ def collect_facts(module, result): facts['eos_eapi_urls'][key].append(str(url).strip()) result['ansible_facts'] = facts + def main(): """ main entry point for module execution """ diff --git a/lib/ansible/modules/network/eos/eos_facts.py b/lib/ansible/modules/network/eos/eos_facts.py index e0961abad0..5dc7b20312 100644 --- a/lib/ansible/modules/network/eos/eos_facts.py +++ b/lib/ansible/modules/network/eos/eos_facts.py @@ -142,6 +142,7 @@ from ansible.module_utils.six import iteritems from ansible.module_utils.network.eos.eos import run_commands from ansible.module_utils.network.eos.eos import eos_argument_spec, check_args + class FactsBase(object): COMMANDS = frozenset() @@ -190,6 +191,7 @@ class Default(FactsBase): value = None return dict(image=value) + class Hardware(FactsBase): COMMANDS = [ @@ -218,6 +220,7 @@ class Hardware(FactsBase): memtotal_mb=int(values['memTotal']) / 1024 ) + class Config(FactsBase): COMMANDS = ['show running-config'] @@ -312,6 +315,7 @@ FACT_SUBSETS = dict( VALID_SUBSETS = frozenset(FACT_SUBSETS.keys()) + def main(): """main entry point for module execution """ diff --git a/lib/ansible/modules/network/eos/eos_system.py b/lib/ansible/modules/network/eos/eos_system.py index d8449e5fc2..44fdd1725e 100644 --- a/lib/ansible/modules/network/eos/eos_system.py +++ b/lib/ansible/modules/network/eos/eos_system.py @@ -135,6 +135,7 @@ from ansible.module_utils.network.eos.eos import eos_argument_spec _CONFIGURED_VRFS = None + def has_vrf(module, vrf): global _CONFIGURED_VRFS if _CONFIGURED_VRFS is not None: @@ -144,11 +145,12 @@ def has_vrf(module, vrf): _CONFIGURED_VRFS.append('default') return vrf in _CONFIGURED_VRFS + def map_obj_to_commands(want, have, module): commands = list() state = module.params['state'] - needs_update = lambda x: want.get(x) and (want.get(x) != have.get(x)) + def needs_update(x): return want.get(x) and (want.get(x) != have.get(x)) if state == 'absent': if have['domain_name']: @@ -205,9 +207,9 @@ def map_obj_to_commands(want, have, module): module.fail_json(msg='vrf %s is not configured' % item['vrf']) if item['vrf'] not in ('default', None): values = (item['vrf'], item['server']) - commands.append('no ip name-server vrf %s %s' % values) + commands.append('no ip name-server vrf %s %s' % values) else: - commands.append('no ip name-server %s' % item['server']) + commands.append('no ip name-server %s' % item['server']) # handle name_servers items to be added for item in want['name_servers']: @@ -222,31 +224,36 @@ def map_obj_to_commands(want, have, module): return commands + def parse_hostname(config): match = re.search(r'^hostname (\S+)', config, re.M) if match: return match.group(1) + def parse_domain_name(config): match = re.search(r'^ip domain-name (\S+)', config, re.M) if match: return match.group(1) + def parse_lookup_source(config): objects = list() regex = r'ip domain lookup (?:vrf (\S+) )*source-interface (\S+)' for vrf, intf in re.findall(regex, config, re.M): if len(vrf) == 0: - vrf= None + vrf = None objects.append({'interface': intf, 'vrf': vrf}) return objects + def parse_name_servers(config): objects = list() for vrf, addr in re.findall(r'ip name-server vrf (\S+) (\S+)', config, re.M): objects.append({'server': addr, 'vrf': vrf}) return objects + def map_config_to_obj(module): config = get_config(module) return { @@ -257,6 +264,7 @@ def map_config_to_obj(module): 'name_servers': parse_name_servers(config) } + def map_params_to_obj(module): obj = { 'hostname': module.params['hostname'], @@ -282,6 +290,7 @@ def map_params_to_obj(module): return obj + def main(): """ main entry point for module execution """ diff --git a/lib/ansible/modules/network/eos/eos_user.py b/lib/ansible/modules/network/eos/eos_user.py index 9bdec10838..be4b895000 100644 --- a/lib/ansible/modules/network/eos/eos_user.py +++ b/lib/ansible/modules/network/eos/eos_user.py @@ -174,8 +174,9 @@ def map_obj_to_commands(updates, module): for update in updates: want, have = update - needs_update = lambda x: want.get(x) and (want.get(x) != have.get(x)) - add = lambda x: commands.append('username %s %s' % (want['name'], x)) + def needs_update(x): return want.get(x) and (want.get(x) != have.get(x)) + + def add(x): return commands.append('username %s %s' % (want['name'], x)) if want['state'] == 'absent': commands.append('no username %s' % want['name']) |