3535)
3636from .constants import (
3737 ATTRIBUTES_NOT_PRESENT_IN_GET_RESPONSE ,
38+ GETALL_ONLY_RESOURCES ,
3839 HTTP_RESOURCE_ALREADY_EXISTS ,
3940 NETSCALER_COMMON_ARGUMENTS ,
4041 NITRO_ATTRIBUTES_ALIASES ,
41- GETALL_ONLY_RESOURCES ,
4242)
4343from .decorators import trace
4444from .logger import log , loglines
@@ -91,9 +91,7 @@ def __init__(self, resource_name, supports_check_mode=True):
9191 argument_spec = argument_spec ,
9292 supports_check_mode = supports_check_mode ,
9393 mutually_exclusive = [
94- (
95- "nitro_pass" , "nitro_auth_token"
96- ),
94+ ("nitro_pass" , "nitro_auth_token" ),
9795 (
9896 "managed_netscaler_instance_name" ,
9997 "managed_netscaler_instance_ip" ,
@@ -148,10 +146,9 @@ def __init__(self, resource_name, supports_check_mode=True):
148146 self .module .params ["api_path" ] = "nitro/v2/config"
149147 self .have_token = self .module .params .get ("nitro_auth_token" , None )
150148 self .client = NitroAPIClient (self .module , self .resource_name )
151- have_userpass = all ([
152- self .module .params .get ("nitro_user" ),
153- self .module .params .get ("nitro_pass" )
154- ])
149+ have_userpass = all (
150+ [self .module .params .get ("nitro_user" ), self .module .params .get ("nitro_pass" )]
151+ )
155152 if have_userpass and not self .module .check_mode :
156153 self .client ._headers .pop ("X-NITRO-USER" , None )
157154 self .client ._headers .pop ("X-NITRO-PASS" , None )
@@ -167,13 +164,22 @@ def __init__(self, resource_name, supports_check_mode=True):
167164
168165 else :
169166 if self .netscaler_console_as_proxy_server :
170- self .module .params ["nitro_auth_token" ] = response ["login" ][0 ].get ("sessionid" , None )
167+ self .module .params ["nitro_auth_token" ] = response ["login" ][0 ].get (
168+ "sessionid" , None
169+ )
171170 else :
172- self .module .params ["nitro_auth_token" ] = response .get ("sessionid" , None )
171+ self .module .params ["nitro_auth_token" ] = response .get (
172+ "sessionid" , None
173+ )
173174
174175 if not self .module .params ["nitro_auth_token" ]:
175- self .return_failure ("ERROR: Login failed. No sessionid returned from the NetScaler ADC" )
176- log ("INFO: Login successful. Session ID: %s" % self .module .params ["nitro_auth_token" ])
176+ self .return_failure (
177+ "ERROR: Login failed. No sessionid returned from the NetScaler ADC"
178+ )
179+ log (
180+ "INFO: Login successful. Session ID: %s"
181+ % self .module .params ["nitro_auth_token" ]
182+ )
177183
178184 self .client ._headers ["Cookie" ] = (
179185 "NITRO_AUTH_TOKEN=%s" % self .module .params ["nitro_auth_token" ]
@@ -222,7 +228,11 @@ def return_success(self):
222228 # }
223229 if self .resource_name == "login" :
224230 self .module_result ["sessionid" ] = self .sessionid
225- if self .client ._headers .get ("Cookie" , None ) not in (None , "" ) and not self .module .check_mode and not self .have_token :
231+ if (
232+ self .client ._headers .get ("Cookie" , None ) not in (None , "" )
233+ and not self .module .check_mode
234+ and not self .have_token
235+ ):
226236 ok , response = adc_logout (self .client )
227237 if not ok :
228238 log ("ERROR: Logout failed: %s" % response )
@@ -252,7 +262,11 @@ def update_diff_list(self, existing=None, desired=None, delete=False, **kwargs):
252262
253263 @trace
254264 def return_failure (self , msg ):
255- if self .client ._headers .get ("Cookie" , None ) not in (None , "" ) and not self .module .check_mode and not self .have_token :
265+ if (
266+ self .client ._headers .get ("Cookie" , None ) not in (None , "" )
267+ and not self .module .check_mode
268+ and not self .have_token
269+ ):
256270 ok , response = adc_logout (self .client )
257271 if not ok :
258272 log ("ERROR: Logout failed: %s" % response )
@@ -445,21 +459,23 @@ def install(self):
445459 @trace
446460 def create_or_update (self ):
447461 desired_state = self .module .params ["state" ]
448- remove_non_updatable_params = self .module .params .get ("remove_non_updatable_params" , "no" )
462+ remove_non_updatable_params = self .module .params .get (
463+ "remove_non_updatable_params" , "no"
464+ )
449465 if (
450- desired_state == "present" and
451- self .resource_name .endswith ("_binding" ) and
452- "state" in self .resource_module_params
466+ desired_state == "present"
467+ and self .resource_name .endswith ("_binding" )
468+ and "state" in self .resource_module_params
453469 ):
454470 self .resource_module_params .pop ("state" )
455471 self .update_diff_list (
456472 existing = self .existing_resource , desired = self .resource_module_params
457473 )
458474 if not self .existing_resource and "add" in self .supported_operations :
459- if (
460- self . resource_name . endswith ( "_binding" ) and
461- desired_state in { "enabled" , " disabled"}
462- ) :
475+ if self . resource_name . endswith ( "_binding" ) and desired_state in {
476+ "enabled" ,
477+ " disabled",
478+ } :
463479 self .resource_module_params ["state" ] = desired_state .upper ()
464480
465481 self .module_result ["changed" ] = True
@@ -556,9 +572,8 @@ def create_or_update(self):
556572 % (self .resource_name , self .resource_id )
557573 )
558574 self .delete ()
559- if (
560- self .module .params ["state" ] == "present" and
561- any (x in self .supported_operations for x in ("enabled" , "disabled" ))
575+ if self .module .params ["state" ] == "present" and any (
576+ x in self .supported_operations for x in ("enabled" , "disabled" )
562577 ):
563578 # We want to keep the previous state of the binding
564579 self .resource_module_params ["state" ] = (
@@ -569,7 +584,9 @@ def create_or_update(self):
569584 )
570585 # Here we are checking if resource has immutable keys
571586 # if yes, we will check if the user wants to keep the non-updatable params (which in turn will return error)
572- elif immutable_keys_list is None or (immutable_keys_list and remove_non_updatable_params == "no" ):
587+ elif immutable_keys_list is None or (
588+ immutable_keys_list and remove_non_updatable_params == "no"
589+ ):
573590 self .module_result ["changed" ] = True
574591 log (
575592 "INFO: Resource %s:%s exists and is different. Will be UPDATED."
@@ -597,18 +614,21 @@ def create_or_update(self):
597614 self .module_result ["changed" ] = False
598615 self .module .exit_json (** self .module_result )
599616 else :
600- if (
601- self .resource_name .endswith ("_binding" ) and
602- self .module .params ["state" ] in {"enabled" , "disabled" }
603- ):
604- existing_state = self .existing_resource .get ("state" , "" ).upper ()
617+ if self .resource_name .endswith (
618+ "_binding"
619+ ) and self .module .params ["state" ] in {"enabled" , "disabled" }:
620+ existing_state = self .existing_resource .get (
621+ "state" , ""
622+ ).upper ()
605623 if existing_state != desired_state :
606624 # Create the resource in desired state
607625 self .module_result ["changed" ] = True
608626 self .delete ()
609627 self .resource_module_params ["state" ] = desired_state
610628 ok , err = create_resource (
611- self .client , self .resource_name , self .resource_module_params
629+ self .client ,
630+ self .resource_name ,
631+ self .resource_module_params ,
612632 )
613633 if not ok :
614634 self .return_failure (err )
@@ -847,8 +867,10 @@ def sync_single_binding(self, binding_name):
847867 self .add_bindings (
848868 binding_name = binding_name ,
849869 desired_bindings = [
850- x for x in desired_binding_members
851- if x [get_bindprimary_key (binding_name , x )] in to_be_added_bindprimary_keys
870+ x
871+ for x in desired_binding_members
872+ if x [get_bindprimary_key (binding_name , x )]
873+ in to_be_added_bindprimary_keys
852874 ],
853875 )
854876
@@ -967,9 +989,9 @@ def change_password(self):
967989 )
968990 else :
969991 # set system user USERNAME -password NEW_PASSWORD
970- self .resource_module_params [
971- "password"
972- ] = self . resource_module_params [ "new_password" ]
992+ self .resource_module_params ["password" ] = (
993+ self . resource_module_params [ "new_password" ]
994+ )
973995 ok , err = update_resource (
974996 self .client , "systemuser" , self .resource_module_params
975997 )
@@ -1096,7 +1118,10 @@ def main(self):
10961118 if "bindings" in NITRO_RESOURCE_MAP [self .resource_name ].keys ():
10971119 self .sync_all_bindings ()
10981120
1099- elif self .resource_name == "install" and self .module .params ["state" ] == "installed" :
1121+ elif (
1122+ self .resource_name == "install"
1123+ and self .module .params ["state" ] == "installed"
1124+ ):
11001125 self .install ()
11011126
11021127 elif self .module .params ["state" ] in {
0 commit comments