|
|
@ -94,7 +94,7 @@ from ansible.module_utils.basic import AnsibleModule
|
|
|
|
from ansible.module_utils.network.common.config import CustomNetworkConfig
|
|
|
|
from ansible.module_utils.network.common.config import CustomNetworkConfig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_existing(module, args):
|
|
|
|
def get_existing(module, args, gl):
|
|
|
|
existing = {}
|
|
|
|
existing = {}
|
|
|
|
config = str(get_config(module))
|
|
|
|
config = str(get_config(module))
|
|
|
|
address = module.params['rp_address']
|
|
|
|
address = module.params['rp_address']
|
|
|
@ -105,6 +105,11 @@ def get_existing(module, args):
|
|
|
|
values = line.split()
|
|
|
|
values = line.split()
|
|
|
|
if values[0] != address:
|
|
|
|
if values[0] != address:
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
|
|
|
|
if gl and 'group-list' not in line:
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
elif not gl and 'group-list' in line:
|
|
|
|
|
|
|
|
if '224.0.0.0/4' not in line: # ignore default group-list
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
existing['bidir'] = existing.get('bidir') or 'bidir' in line
|
|
|
|
existing['bidir'] = existing.get('bidir') or 'bidir' in line
|
|
|
|
if len(values) > 2:
|
|
|
|
if len(values) > 2:
|
|
|
@ -114,6 +119,7 @@ def get_existing(module, args):
|
|
|
|
elif values[1] == 'prefix-list':
|
|
|
|
elif values[1] == 'prefix-list':
|
|
|
|
existing['prefix_list'] = value
|
|
|
|
existing['prefix_list'] = value
|
|
|
|
elif values[1] == 'group-list':
|
|
|
|
elif values[1] == 'group-list':
|
|
|
|
|
|
|
|
if value != '224.0.0.0/4': # ignore default group-list
|
|
|
|
existing['group_list'] = value
|
|
|
|
existing['group_list'] = value
|
|
|
|
|
|
|
|
|
|
|
|
return existing
|
|
|
|
return existing
|
|
|
@ -122,6 +128,14 @@ def get_existing(module, args):
|
|
|
|
def state_present(module, existing, proposed, candidate):
|
|
|
|
def state_present(module, existing, proposed, candidate):
|
|
|
|
address = module.params['rp_address']
|
|
|
|
address = module.params['rp_address']
|
|
|
|
command = 'ip pim rp-address {0}'.format(address)
|
|
|
|
command = 'ip pim rp-address {0}'.format(address)
|
|
|
|
|
|
|
|
if module.params['group_list'] and not proposed.get('group_list'):
|
|
|
|
|
|
|
|
command += ' group-list ' + module.params['group_list']
|
|
|
|
|
|
|
|
if module.params['prefix_list']:
|
|
|
|
|
|
|
|
if not proposed.get('prefix_list'):
|
|
|
|
|
|
|
|
command += ' prefix-list ' + module.params['prefix_list']
|
|
|
|
|
|
|
|
if module.params['route_map']:
|
|
|
|
|
|
|
|
if not proposed.get('route_map'):
|
|
|
|
|
|
|
|
command += ' route-map ' + module.params['route_map']
|
|
|
|
commands = build_command(proposed, command)
|
|
|
|
commands = build_command(proposed, command)
|
|
|
|
if commands:
|
|
|
|
if commands:
|
|
|
|
candidate.add(commands, parents=[])
|
|
|
|
candidate.add(commands, parents=[])
|
|
|
@ -140,15 +154,33 @@ def build_command(param_dict, command):
|
|
|
|
def state_absent(module, existing, candidate):
|
|
|
|
def state_absent(module, existing, candidate):
|
|
|
|
address = module.params['rp_address']
|
|
|
|
address = module.params['rp_address']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
commands = []
|
|
|
|
command = 'no ip pim rp-address {0}'.format(address)
|
|
|
|
command = 'no ip pim rp-address {0}'.format(address)
|
|
|
|
if existing.get('group_list'):
|
|
|
|
if module.params['group_list'] == existing.get('group_list'):
|
|
|
|
commands = build_command(existing, command)
|
|
|
|
commands = build_command(existing, command)
|
|
|
|
else:
|
|
|
|
elif not module.params['group_list']:
|
|
|
|
commands = [command]
|
|
|
|
commands = [command]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if commands:
|
|
|
|
candidate.add(commands, parents=[])
|
|
|
|
candidate.add(commands, parents=[])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_proposed(pargs, existing):
|
|
|
|
|
|
|
|
proposed = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for key, value in pargs.items():
|
|
|
|
|
|
|
|
if key != 'rp_address':
|
|
|
|
|
|
|
|
if str(value).lower() == 'true':
|
|
|
|
|
|
|
|
value = True
|
|
|
|
|
|
|
|
elif str(value).lower() == 'false':
|
|
|
|
|
|
|
|
value = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if existing.get(key) != value:
|
|
|
|
|
|
|
|
proposed[key] = value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return proposed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
|
argument_spec = dict(
|
|
|
|
argument_spec = dict(
|
|
|
|
rp_address=dict(required=True, type='str'),
|
|
|
|
rp_address=dict(required=True, type='str'),
|
|
|
@ -180,20 +212,16 @@ def main():
|
|
|
|
'bidir'
|
|
|
|
'bidir'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
existing = get_existing(module, args)
|
|
|
|
|
|
|
|
proposed_args = dict((k, v) for k, v in module.params.items()
|
|
|
|
proposed_args = dict((k, v) for k, v in module.params.items()
|
|
|
|
if v is not None and k in args)
|
|
|
|
if v is not None and k in args)
|
|
|
|
|
|
|
|
|
|
|
|
proposed = {}
|
|
|
|
if module.params['group_list']:
|
|
|
|
for key, value in proposed_args.items():
|
|
|
|
existing = get_existing(module, args, True)
|
|
|
|
if key != 'rp_address':
|
|
|
|
proposed = get_proposed(proposed_args, existing)
|
|
|
|
if str(value).lower() == 'true':
|
|
|
|
|
|
|
|
value = True
|
|
|
|
|
|
|
|
elif str(value).lower() == 'false':
|
|
|
|
|
|
|
|
value = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if existing.get(key) != value:
|
|
|
|
else:
|
|
|
|
proposed[key] = value
|
|
|
|
existing = get_existing(module, args, False)
|
|
|
|
|
|
|
|
proposed = get_proposed(proposed_args, existing)
|
|
|
|
|
|
|
|
|
|
|
|
candidate = CustomNetworkConfig(indent=3)
|
|
|
|
candidate = CustomNetworkConfig(indent=3)
|
|
|
|
if state == 'present' and (proposed or not existing):
|
|
|
|
if state == 'present' and (proposed or not existing):
|
|
|
@ -205,7 +233,19 @@ def main():
|
|
|
|
candidate = candidate.items_text()
|
|
|
|
candidate = candidate.items_text()
|
|
|
|
result['commands'] = candidate
|
|
|
|
result['commands'] = candidate
|
|
|
|
result['changed'] = True
|
|
|
|
result['changed'] = True
|
|
|
|
load_config(module, candidate)
|
|
|
|
msgs = load_config(module, candidate, True)
|
|
|
|
|
|
|
|
if msgs:
|
|
|
|
|
|
|
|
for item in msgs:
|
|
|
|
|
|
|
|
if item:
|
|
|
|
|
|
|
|
if isinstance(item, dict):
|
|
|
|
|
|
|
|
err_str = item['clierror']
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
err_str = item
|
|
|
|
|
|
|
|
if 'No policy was configured' in err_str:
|
|
|
|
|
|
|
|
if state == 'absent':
|
|
|
|
|
|
|
|
addr = module.params['rp_address']
|
|
|
|
|
|
|
|
new_cmd = 'no ip pim rp-address {0}'.format(addr)
|
|
|
|
|
|
|
|
load_config(module, new_cmd)
|
|
|
|
|
|
|
|
|
|
|
|
module.exit_json(**result)
|
|
|
|
module.exit_json(**result)
|
|
|
|
|
|
|
|
|
|
|
|