Fixing bugs

This commit is contained in:
GGabriele 2016-04-21 16:01:04 +02:00
parent c25610777f
commit 0f57bb1513

View file

@ -262,7 +262,7 @@ def parse_structured_data(body, interface_name, version, module):
address = {} address = {}
address['addr'] = interface_table.get('prefix', None) address['addr'] = interface_table.get('prefix', None)
if address['addr'] is not None: if address['addr'] is not None:
address['mask'] = interface_table.get('masklen', None) address['mask'] = str(interface_table.get('masklen', None))
interface['addresses'] = [address] interface['addresses'] = [address]
prefix = "{0}/{1}".format(address['addr'], address['mask']) prefix = "{0}/{1}".format(address['addr'], address['mask'])
address_list.append(prefix) address_list.append(prefix)
@ -416,16 +416,17 @@ def validate_params(addr, interface, mask, version, state, intf_type, module):
if is_default(interface, module) == "DNE": if is_default(interface, module) == "DNE":
module.fail_json(msg="That interface does not exist yet. Create " module.fail_json(msg="That interface does not exist yet. Create "
"it first.", interface=interface) "it first.", interface=interface)
try: if mask is not None:
if (int(mask) < 1 or int(mask) > 32) and version == "v4": try:
raise ValueError if (int(mask) < 1 or int(mask) > 32) and version == "v4":
elif int(mask) < 1 or int(mask) > 128: raise ValueError
raise ValueError elif int(mask) < 1 or int(mask) > 128:
except ValueError: raise ValueError
module.fail_json(msg="Warning! 'mask' must be an integer between" except ValueError:
" 1 and 32 when version v4 and up to 128 " module.fail_json(msg="Warning! 'mask' must be an integer between"
"when version v6.", version=version, " 1 and 32 when version v4 and up to 128 "
mask=mask) "when version v6.", version=version,
mask=mask)
def main(): def main():
@ -464,11 +465,17 @@ def main():
end_state = existing end_state = existing
if state == 'absent' and existing['addresses']: if state == 'absent' and existing['addresses']:
for address in existing['addresses']: if version == 'v6':
if address['addr'] == addr and address['mask'] == mask: for address in existing['addresses']:
command = get_remove_ip_config_commands(interface, addr, mask, if address['addr'] == addr and address['mask'] == mask:
version) command = get_remove_ip_config_commands(interface, addr,
commands.append(command) mask, version)
commands.append(command)
else:
command = get_remove_ip_config_commands(interface, addr,
mask, version)
commands.append(command)
elif state == 'present': elif state == 'present':
if not existing['addresses']: if not existing['addresses']: