mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
Bulk autopep8 (modules)
As agreed in 2017-12-07 Core meeting bulk fix pep8 issues Generated using: autopep8 1.3.3 (pycodestyle: 2.3.1) autopep8 -r --max-line-length 160 --in-place --ignore E305,E402,E722,E741 lib/ansible/modules Manually fix issues that autopep8 has introduced
This commit is contained in:
committed by
John R Barker
parent
d13d7e9404
commit
c57a7f05e1
@@ -96,6 +96,7 @@ from ansible.module_utils.network.ios.ios import load_config, run_commands
|
||||
from ansible.module_utils.network.ios.ios import ios_argument_spec, check_args
|
||||
import re
|
||||
|
||||
|
||||
def map_obj_to_commands(updates, module):
|
||||
commands = list()
|
||||
want, have = updates
|
||||
@@ -114,6 +115,7 @@ def map_obj_to_commands(updates, module):
|
||||
|
||||
return commands
|
||||
|
||||
|
||||
def map_config_to_obj(module):
|
||||
rc, out, err = exec_command(module, 'show banner %s' % module.params['banner'])
|
||||
if rc == 0:
|
||||
@@ -132,6 +134,7 @@ def map_config_to_obj(module):
|
||||
obj['state'] = 'present'
|
||||
return obj
|
||||
|
||||
|
||||
def map_params_to_obj(module):
|
||||
text = module.params['text']
|
||||
if text:
|
||||
@@ -143,6 +146,7 @@ def map_params_to_obj(module):
|
||||
'state': module.params['state']
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
""" main entry point for module execution
|
||||
"""
|
||||
|
||||
@@ -140,12 +140,14 @@ from ansible.module_utils.network.common.utils import ComplexList
|
||||
from ansible.module_utils.network.common.parsing import Conditional
|
||||
from ansible.module_utils.six import string_types
|
||||
|
||||
|
||||
def to_lines(stdout):
|
||||
for item in stdout:
|
||||
if isinstance(item, string_types):
|
||||
item = str(item).split('\n')
|
||||
yield item
|
||||
|
||||
|
||||
def parse_commands(module, warnings):
|
||||
command = ComplexList(dict(
|
||||
command=dict(key=True),
|
||||
@@ -167,6 +169,7 @@ def parse_commands(module, warnings):
|
||||
)
|
||||
return commands
|
||||
|
||||
|
||||
def main():
|
||||
"""main entry point for module execution
|
||||
"""
|
||||
@@ -220,7 +223,6 @@ def main():
|
||||
msg = 'One or more conditional statements have not be satisfied'
|
||||
module.fail_json(msg=msg, failed_conditions=failed_conditions)
|
||||
|
||||
|
||||
result.update({
|
||||
'changed': False,
|
||||
'stdout': responses,
|
||||
|
||||
@@ -162,13 +162,13 @@ class FactsBase(object):
|
||||
self.facts = dict()
|
||||
self.responses = None
|
||||
|
||||
|
||||
def populate(self):
|
||||
self.responses = run_commands(self.module, self.COMMANDS, check_rc=False)
|
||||
|
||||
def run(self, cmd):
|
||||
return run_commands(self.module, cmd, check_rc=False)
|
||||
|
||||
|
||||
class Default(FactsBase):
|
||||
|
||||
COMMANDS = ['show version']
|
||||
@@ -440,6 +440,7 @@ FACT_SUBSETS = dict(
|
||||
|
||||
VALID_SUBSETS = frozenset(FACT_SUBSETS.keys())
|
||||
|
||||
|
||||
def main():
|
||||
"""main entry point for module execution
|
||||
"""
|
||||
|
||||
@@ -125,6 +125,7 @@ from ansible.module_utils.network.common.utils import ComplexList
|
||||
|
||||
_CONFIGURED_VRFS = None
|
||||
|
||||
|
||||
def has_vrf(module, vrf):
|
||||
global _CONFIGURED_VRFS
|
||||
if _CONFIGURED_VRFS is not None:
|
||||
@@ -133,20 +134,23 @@ def has_vrf(module, vrf):
|
||||
_CONFIGURED_VRFS = re.findall(r'vrf definition (\S+)', config)
|
||||
return vrf in _CONFIGURED_VRFS
|
||||
|
||||
|
||||
def requires_vrf(module, vrf):
|
||||
if not has_vrf(module, vrf):
|
||||
module.fail_json(msg='vrf %s is not configured' % vrf)
|
||||
|
||||
|
||||
def diff_list(want, have):
|
||||
adds = [w for w in want if w not in have]
|
||||
removes = [h for h in have if h not in want]
|
||||
return (adds, removes)
|
||||
|
||||
|
||||
def map_obj_to_commands(want, have, module):
|
||||
commands = list()
|
||||
state = module.params['state']
|
||||
|
||||
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))
|
||||
|
||||
if state == 'absent':
|
||||
if have['hostname'] != 'Router':
|
||||
@@ -226,7 +230,6 @@ def map_obj_to_commands(want, have, module):
|
||||
else:
|
||||
commands.append('ip domain list %s' % item['name'])
|
||||
|
||||
|
||||
if want['name_servers']:
|
||||
adds, removes = diff_list(want['name_servers'], have['name_servers'])
|
||||
for item in removes:
|
||||
@@ -243,10 +246,12 @@ def map_obj_to_commands(want, have, module):
|
||||
|
||||
return commands
|
||||
|
||||
|
||||
def parse_hostname(config):
|
||||
match = re.search(r'^hostname (\S+)', config, re.M)
|
||||
return match.group(1)
|
||||
|
||||
|
||||
def parse_domain_name(config):
|
||||
match = re.findall(r'^ip domain name (?:vrf (\S+) )*(\S+)', config, re.M)
|
||||
matches = list()
|
||||
@@ -256,6 +261,7 @@ def parse_domain_name(config):
|
||||
matches.append({'name': name, 'vrf': vrf})
|
||||
return matches
|
||||
|
||||
|
||||
def parse_domain_search(config):
|
||||
match = re.findall(r'^ip domain list (?:vrf (\S+) )*(\S+)', config, re.M)
|
||||
matches = list()
|
||||
@@ -265,6 +271,7 @@ def parse_domain_search(config):
|
||||
matches.append({'name': name, 'vrf': vrf})
|
||||
return matches
|
||||
|
||||
|
||||
def parse_name_servers(config):
|
||||
match = re.findall(r'^ip name-server (?:vrf (\S+) )*(.*)', config, re.M)
|
||||
matches = list()
|
||||
@@ -275,11 +282,13 @@ def parse_name_servers(config):
|
||||
matches.append({'server': server, 'vrf': vrf})
|
||||
return matches
|
||||
|
||||
|
||||
def parse_lookup_source(config):
|
||||
match = re.search(r'ip domain lookup source-interface (\S+)', config, re.M)
|
||||
if match:
|
||||
return match.group(1)
|
||||
|
||||
|
||||
def map_config_to_obj(module):
|
||||
config = get_config(module)
|
||||
return {
|
||||
@@ -291,6 +300,7 @@ def map_config_to_obj(module):
|
||||
'name_servers': parse_name_servers(config)
|
||||
}
|
||||
|
||||
|
||||
def map_params_to_obj(module):
|
||||
obj = {
|
||||
'hostname': module.params['hostname'],
|
||||
@@ -324,6 +334,7 @@ def map_params_to_obj(module):
|
||||
|
||||
return obj
|
||||
|
||||
|
||||
def main():
|
||||
""" Main entry point for Ansible module execution
|
||||
"""
|
||||
|
||||
@@ -175,9 +175,10 @@ def add_command_to_vrf(name, cmd, commands):
|
||||
])
|
||||
commands.append(cmd)
|
||||
|
||||
|
||||
def map_obj_to_commands(updates, module):
|
||||
commands = list()
|
||||
state = module.params['state'] # FIXME NOT USED
|
||||
state = module.params['state'] # FIXME NOT USED
|
||||
|
||||
for update in updates:
|
||||
want, have = update
|
||||
@@ -226,6 +227,7 @@ def map_obj_to_commands(updates, module):
|
||||
|
||||
return commands
|
||||
|
||||
|
||||
def parse_description(configobj, name):
|
||||
cfg = configobj['vrf definition %s' % name]
|
||||
cfg = '\n'.join(cfg.children)
|
||||
@@ -233,6 +235,7 @@ def parse_description(configobj, name):
|
||||
if match:
|
||||
return match.group(1)
|
||||
|
||||
|
||||
def parse_rd(configobj, name):
|
||||
cfg = configobj['vrf definition %s' % name]
|
||||
cfg = '\n'.join(cfg.children)
|
||||
@@ -240,6 +243,7 @@ def parse_rd(configobj, name):
|
||||
if match:
|
||||
return match.group(1)
|
||||
|
||||
|
||||
def parse_interfaces(configobj, name):
|
||||
vrf_cfg = 'vrf forwarding %s' % name
|
||||
interfaces = list()
|
||||
@@ -249,6 +253,7 @@ def parse_interfaces(configobj, name):
|
||||
interfaces.append(intf.split(' ')[1])
|
||||
return interfaces
|
||||
|
||||
|
||||
def map_config_to_obj(module):
|
||||
config = get_config(module)
|
||||
configobj = NetworkConfig(indent=1, contents=config)
|
||||
@@ -290,6 +295,7 @@ def get_param_value(key, item, module):
|
||||
|
||||
return value
|
||||
|
||||
|
||||
def map_params_to_obj(module):
|
||||
vrfs = module.params.get('vrfs')
|
||||
if not vrfs:
|
||||
@@ -320,6 +326,7 @@ def map_params_to_obj(module):
|
||||
|
||||
return objects
|
||||
|
||||
|
||||
def update_objects(want, have):
|
||||
updates = list()
|
||||
for entry in want:
|
||||
|
||||
Reference in New Issue
Block a user