Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use_options in nios_network and nios_range #276

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions plugins/modules/nios_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,27 @@ def options(module):
vendor_class: <value>
}
It will remove any options that are set to None since WAPI will error on
that condition. It will also verify that either `name` or `num` is
that condition. The use_option field only applies
to special options that are displayed separately from other options and
have a use flag. This function removes the use_option flag from all
other options. It will also verify that either `name` or `num` is
set in the structure but does not validate the values are equal.
The remainder of the value validation is performed by WAPI
'''
special_options = ['routers', 'router-templates', 'domain-name-servers',
'domain-name', 'broadcast-address', 'broadcast-address-offset',
'dhcp-lease-time', 'dhcp6.name-servers']
# options-router-templates, broadcast-address-offset, dhcp6.name-servers don't have any associated number
special_num = [3, 6, 15, 28, 51]
options = list()
for item in module.params['options']:
opt = dict([(k, v) for k, v in iteritems(item) if v is not None])
if 'name' not in opt and 'num' not in opt:
module.fail_json(msg='one of `name` or `num` is required for option value')
if 'name' in opt and opt['name'] not in special_options:
del opt['use_option']
if 'num' in opt and opt['num'] not in special_num:
del opt['use_option']
options.append(opt)
return options

Expand All @@ -329,19 +341,6 @@ def check_ip_addr_type(obj_filter, ib_spec):
return NIOS_IPV6_NETWORK, ib_spec


def check_vendor_specific_dhcp_option(module, ib_spec):
'''This function will check if the argument dhcp option belongs to vendor-specific and if yes then will remove
use_options flag which is not supported with vendor-specific dhcp options.
'''
for key, value in iteritems(ib_spec):
if isinstance(module.params[key], list):
for temp_dict in module.params[key]:
if 'num' in temp_dict:
if temp_dict['num'] in (43, 124, 125, 67, 60):
del temp_dict['use_option']
return ib_spec


def main():
''' Main entry point for module execution
'''
Expand Down Expand Up @@ -387,8 +386,6 @@ def main():
network_type, ib_spec = check_ip_addr_type(obj_filter, ib_spec)

wapi = WapiModule(module)
# to check for vendor specific dhcp option
ib_spec = check_vendor_specific_dhcp_option(module, ib_spec)

result = wapi.run(network_type, ib_spec)

Expand Down
29 changes: 13 additions & 16 deletions plugins/modules/nios_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,32 +300,31 @@ def options(module):
vendor_class: <value>
}
It will remove any options that are set to None since WAPI will error on
that condition. It will also verify that either `name` or `num` is
that condition. The use_option field only applies
to special options that are displayed separately from other options and
have a use flag. This function removes the use_option flag from all
other options. It will also verify that either `name` or `num` is
set in the structure but does not validate the values are equal.
The remainder of the value validation is performed by WAPI
'''
special_options = ['routers', 'router-templates', 'domain-name-servers',
'domain-name', 'broadcast-address', 'broadcast-address-offset',
'dhcp-lease-time', 'dhcp6.name-servers']
# options-router-templates, broadcast-address-offset, dhcp6.name-servers don't have any associated number
special_num = [3, 6, 15, 28, 51]
options = list()
for item in module.params['options']:
opt = dict([(k, v) for k, v in iteritems(item) if v is not None])
if 'name' not in opt and 'num' not in opt:
module.fail_json(msg='one of `name` or `num` is required for option value')
if 'name' in opt and opt['name'] not in special_options:
del opt['use_option']
if 'num' in opt and opt['num'] not in special_num:
del opt['use_option']
options.append(opt)
return options


def check_vendor_specific_dhcp_option(module, ib_spec):
'''This function will check if the argument dhcp option belongs to vendor-specific and if yes then will remove
use_options flag which is not supported with vendor-specific dhcp options.
'''
for key, value in iteritems(ib_spec):
if isinstance(module.params[key], list):
for temp_dict in module.params[key]:
if 'num' in temp_dict:
if temp_dict['num'] in (43, 124, 125, 67, 60):
del temp_dict['use_option']
return ib_spec


def convert_range_member_to_struct(module):
'''This function will check the module input to ensure that only one member assignment type is specified at once.
Member passed in is converted to the correct struct for the API to understand bassed on the member type.
Expand Down Expand Up @@ -396,8 +395,6 @@ def main():
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
module = convert_range_member_to_struct(module)
wapi = WapiModule(module)
# to check for vendor specific dhcp option
ib_spec = check_vendor_specific_dhcp_option(module, ib_spec)

result = wapi.run(NIOS_RANGE, ib_spec)

Expand Down