20
20
from .logger import log
21
21
from .nitro_resource_map import NITRO_RESOURCE_MAP
22
22
23
+
23
24
@trace
24
25
def get_netscaler_version (client ):
25
26
is_exist , response = get_resource (client , "nsversion" )
@@ -105,7 +106,7 @@ def get_resource(client, resource_name, resource_id=None, resource_module_params
105
106
# for zero bindings and some resources, the response_body will be {'errorcode': 0, 'message': 'Done', 'severity': 'NONE'}
106
107
if resource_name in NESTED_POST_DATA_RESOURCES :
107
108
if "routerDynamicRouting" in response_body :
108
- response_body = response_body ["routerDynamicRouting" ]
109
+ response_body = response_body ["routerDynamicRouting" ]
109
110
if resource_name not in response_body :
110
111
if resource_name == "sslcipher" :
111
112
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
114
115
]
115
116
116
117
return False , []
117
-
118
+
118
119
# `update-only` resources return a dict instead of a list.
119
120
return_response = response_body [resource_name ]
120
121
# 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):
194
195
)
195
196
return is_exists
196
197
198
+
197
199
@trace
198
200
def _check_create_resource_params (resource_name , resource_module_params , action = None ):
199
201
post_data = {}
@@ -226,26 +228,26 @@ def _check_create_resource_params(resource_name, resource_module_params, action=
226
228
else :
227
229
# TODO: Should we allow non-add keys for the resource? OR should we error out if any non-add key is passed?
228
230
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
248
249
)
250
+ )
249
251
else :
250
252
for key in resource_module_params .keys ():
251
253
if not action :
@@ -310,7 +312,7 @@ def create_resource(client, resource_name, resource_module_params, action=None):
310
312
# For nested post data resources, post_data is already properly structured
311
313
if resource_name not in NESTED_POST_DATA_RESOURCES :
312
314
post_data = {resource_name : post_data }
313
-
315
+
314
316
status_code , response_body = client .post (
315
317
post_data = post_data ,
316
318
resource = resource_name ,
0 commit comments