From f44a14ceb4df3b1c537269fcf5d12b62d49bfdf6 Mon Sep 17 00:00:00 2001 From: Jaykumar Chhatbar <45447272+JchhatbarInfoblox@users.noreply.github.com> Date: Thu, 8 Aug 2024 12:00:11 +0530 Subject: [PATCH] - Added dhcp options supports for ipv4 and ipv6 network container. (#245) --- plugins/module_utils/api.py | 18 +++++++++++++++++- plugins/modules/nios_network.py | 3 ++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/api.py b/plugins/module_utils/api.py index 46af207e..ebbf961f 100644 --- a/plugins/module_utils/api.py +++ b/plugins/module_utils/api.py @@ -384,6 +384,22 @@ def run(self, ib_obj_type, ib_spec): if (ib_obj_type == NIOS_IPV4_NETWORK or ib_obj_type == NIOS_IPV6_NETWORK): proposed_object = convert_members_to_struct(proposed_object) + if (ib_obj_type == NIOS_IPV4_NETWORK_CONTAINER or ib_obj_type == NIOS_IPV6_NETWORK_CONTAINER): + + # Iterate over each option and remove the 'num' key + if current_object.get('options') or proposed_object.get('options'): + if current_object.get('options'): + for option in current_object['options']: + option.pop('num', None) + + # remove use_options false from current_object + current_object['options'] = [option for option in current_object['options'] if option.get('use_option', True)] + + # Assuming 'current_object' is the dictionary containing the 'options' list + current_object['options'] = sorted(current_object['options'], key=lambda x: x['name']) + if proposed_object.get('options'): + proposed_object['options'] = sorted(proposed_object['options'], key=lambda x: x['name']) + if (ib_obj_type == NIOS_RANGE): if proposed_object.get('new_start_addr'): proposed_object['start_addr'] = proposed_object.get('new_start_addr') @@ -656,7 +672,7 @@ def compare_objects(self, current_object, proposed_object): # If the lists are of a different length the objects and order of element mismatch # Ignore DHCP options while comparing due to extra num param is get response - if key != 'options' and proposed_item != current_item: + if proposed_item != current_item: return False elif isinstance(proposed_item, dict): diff --git a/plugins/modules/nios_network.py b/plugins/modules/nios_network.py index e2505966..4ec26a85 100644 --- a/plugins/modules/nios_network.py +++ b/plugins/modules/nios_network.py @@ -47,6 +47,7 @@ of values (see suboptions). When configuring suboptions at least one of C(name) or C(num) must be specified. type: list + default: [] elements: dict suboptions: name: @@ -359,7 +360,7 @@ def main(): network=dict(required=True, aliases=['name', 'cidr'], ib_req=True), network_view=dict(default='default', ib_req=True), - options=dict(type='list', elements='dict', options=option_spec, transform=options), + options=dict(type='list', elements='dict', options=option_spec, transform=options, default=[]), template=dict(type='str'), extattrs=dict(type='dict'),