2020from .logger import log
2121from .nitro_resource_map import NITRO_RESOURCE_MAP
2222
23+
2324@trace
2425def get_netscaler_version (client ):
2526 is_exist , response = get_resource (client , "nsversion" )
@@ -105,7 +106,7 @@ def get_resource(client, resource_name, resource_id=None, resource_module_params
105106 # for zero bindings and some resources, the response_body will be {'errorcode': 0, 'message': 'Done', 'severity': 'NONE'}
106107 if resource_name in NESTED_POST_DATA_RESOURCES :
107108 if "routerDynamicRouting" in response_body :
108- response_body = response_body ["routerDynamicRouting" ]
109+ response_body = response_body ["routerDynamicRouting" ]
109110 if resource_name not in response_body :
110111 if resource_name == "sslcipher" :
111112 resource_primary_key = NITRO_RESOURCE_MAP [resource_name ]["primary_key" ]
@@ -114,7 +115,7 @@ def get_resource(client, resource_name, resource_id=None, resource_module_params
114115 ]
115116
116117 return False , []
117-
118+
118119 # `update-only` resources return a dict instead of a list.
119120 return_response = response_body [resource_name ]
120121 # FIXME: NITRO-BUG: for some resources like `policypatset_pattern_binding`, NITRO returns keys with uppercase. eg: `String` for `string`.
@@ -194,6 +195,7 @@ def is_resource_exists(client, resource_name, resource_module_params):
194195 )
195196 return is_exists
196197
198+
197199@trace
198200def _check_create_resource_params (resource_name , resource_module_params , action = None ):
199201 post_data = {}
@@ -226,26 +228,26 @@ def _check_create_resource_params(resource_name, resource_module_params, action=
226228 else :
227229 # TODO: Should we allow non-add keys for the resource? OR should we error out if any non-add key is passed?
228230 if resource_name in NESTED_POST_DATA_RESOURCES :
229- post_data = {"routerDynamicRouting" : {resource_name : {}}}
230- resource_add_keys = NITRO_RESOURCE_MAP [resource_name ]["add_payload_keys" ]
231-
232- for key in resource_module_params .keys ():
233- if key in resource_add_keys :
234- keylist = key .split ("." )
235- current_dict = post_data ["routerDynamicRouting" ][resource_name ]
236- for i , k in enumerate (keylist ):
237- if i == len (keylist ) - 1 :
238- current_dict [k ] = resource_module_params [key ]
239- else :
240- if k not in current_dict :
241- current_dict [k ] = {}
242- current_dict = current_dict [k ]
243- else :
244- log (
245- "WARNING: Key `{}` is not allowed for the resource `{}` for CREATE operation. Skipping the key for the operation" .format (
246- key , resource_name
247- )
231+ post_data = {"routerDynamicRouting" : {resource_name : {}}}
232+ resource_add_keys = NITRO_RESOURCE_MAP [resource_name ]["add_payload_keys" ]
233+
234+ for key in resource_module_params .keys ():
235+ if key in resource_add_keys :
236+ keylist = key .split ("." )
237+ current_dict = post_data ["routerDynamicRouting" ][resource_name ]
238+ for i , k in enumerate (keylist ):
239+ if i == len (keylist ) - 1 :
240+ current_dict [k ] = resource_module_params [key ]
241+ else :
242+ if k not in current_dict :
243+ current_dict [k ] = {}
244+ current_dict = current_dict [k ]
245+ else :
246+ log (
247+ "WARNING: Key `{}` is not allowed for the resource `{}` for CREATE operation. Skipping the key for the operation" .format (
248+ key , resource_name
248249 )
250+ )
249251 else :
250252 for key in resource_module_params .keys ():
251253 if not action :
@@ -310,7 +312,7 @@ def create_resource(client, resource_name, resource_module_params, action=None):
310312 # For nested post data resources, post_data is already properly structured
311313 if resource_name not in NESTED_POST_DATA_RESOURCES :
312314 post_data = {resource_name : post_data }
313-
315+
314316 status_code , response_body = client .post (
315317 post_data = post_data ,
316318 resource = resource_name ,
0 commit comments