@@ -305,17 +305,30 @@ def _add_nitro_attributes_aliases(self, payload):
305305
306306 @trace
307307 def _filter_resource_module_params (self ):
308+ def filter_values (value ):
309+ if isinstance (value , dict ):
310+ cleaned_dict = {}
311+ for k , v in value .items ():
312+ cleaned_v = filter_values (v )
313+ if cleaned_v is not None :
314+ cleaned_dict [k ] = cleaned_v
315+ return cleaned_dict if cleaned_dict else None
316+ elif isinstance (value , list ):
317+ cleaned_list = []
318+ for item in value :
319+ cleaned_item = filter_values (item )
320+ if cleaned_item is not None :
321+ cleaned_list .append (cleaned_item )
322+ return cleaned_list if cleaned_list else None
323+ else :
324+ return value if value is not None else None
325+
308326 log ("DEBUG: self.module.params: %s" % self .module .params )
309327 for k , v in self .module .params .items ():
310- if (not k .endswith ("_binding" )) and (
311- k
312- in NITRO_RESOURCE_MAP [self .resource_name ]["readwrite_arguments" ].keys ()
313- ):
314- # self.module.params is a dict of key:value pairs. If an attribute is not
315- # defined in the playbook, it's value will be None. So, filter out those attributes.
316- # Also, filter out attributes ending with `_binding` as they are handled separately
317- if v is not None :
318- self .resource_module_params [k ] = v
328+ if not k .endswith ("_binding" ) and k in NITRO_RESOURCE_MAP [self .resource_name ]["readwrite_arguments" ]:
329+ cleaned_value = filter_values (v )
330+ if cleaned_value is not None :
331+ self .resource_module_params [k ] = cleaned_value
319332
320333 if self .resource_name in NITRO_ATTRIBUTES_ALIASES :
321334 self .resource_module_params = self ._add_nitro_attributes_aliases (
@@ -500,7 +513,7 @@ def create_or_update(self):
500513 errorcode = None
501514 message = None
502515 err_str = str (err )
503- regex_string = re .search (r' status_code:\s*(\d+)' , err_str )
516+ regex_string = re .search (r" status_code:\s*(\d+)" , err_str )
504517 if regex_string :
505518 status_code = int (regex_string .group (1 ))
506519 regex_string = re .search (r"'errorcode':\s*(\d+)" , err_str )
@@ -510,9 +523,9 @@ def create_or_update(self):
510523 if regex_string :
511524 message = regex_string .group (1 )
512525 if not (
513- status_code == 599 and
514- errorcode == 1065 and
515- message == "Internal error while adding HSM key."
526+ status_code == 599
527+ and errorcode == 1065
528+ and message == "Internal error while adding HSM key."
516529 ):
517530 self .return_failure (err )
518531
@@ -580,15 +593,21 @@ def create_or_update(self):
580593 "INFO: Resource %s:%s exists and is different. Will be REMOVED and ADDED."
581594 % (self .resource_name , self .resource_id )
582595 )
583- if self .resource_name == "systemfile" :
584- # If the systemfile is present, we will delete it and add it again
585- self .delete ()
586- ok , err = create_resource (
587- self .client , self .resource_name , self .resource_module_params
588- )
589- if not ok :
590- self .return_failure (err )
591-
596+ # If the systemfile is present, we will delete it and add it again
597+ self .delete ()
598+ ok , err = create_resource (
599+ self .client , self .resource_name , self .resource_module_params
600+ )
601+ if not ok :
602+ self .return_failure (err )
603+ elif self .resource_name == "location" :
604+ # TODO: primary composite key needs to be added.
605+ # location resource has composite primary key. 1.ipfrom 2.ipto
606+ ok , err = create_resource (
607+ self .client , self .resource_name , self .resource_module_params
608+ )
609+ if not ok :
610+ self .return_failure (err )
592611 elif self .resource_name .endswith ("_binding" ):
593612 # Generally bindings are not updated. They are removed and added again.
594613 log (
@@ -707,7 +726,7 @@ def delete(self):
707726 errorcode = None
708727 message = None
709728 err_str = str (err )
710- regex_string = re .search (r' status_code:\s*(\d+)' , err_str )
729+ regex_string = re .search (r" status_code:\s*(\d+)" , err_str )
711730 if regex_string :
712731 status_code = int (regex_string .group (1 ))
713732 regex_string = re .search (r"'errorcode':\s*(\d+)" , err_str )
@@ -717,9 +736,9 @@ def delete(self):
717736 if regex_string :
718737 message = regex_string .group (1 )
719738 if not (
720- status_code == 599 and
721- errorcode == 1065 and
722- message == "Internal error while adding HSM key."
739+ status_code == 599
740+ and errorcode == 1065
741+ and message == "Internal error while adding HSM key."
723742 ):
724743 self .return_failure (err )
725744 else :
0 commit comments