3131__metaclass__ = type
3232
3333import time
34-
3534from ansible .module_utils .connection import Connection
3635
3736BEFORE_REQUEST = 1
@@ -200,6 +199,9 @@ def chkp_facts_api_call(module, api_call_object, is_multible):
200199 if "static-route" == api_call_object :
201200 if "address" in module_key_params and "mask_length" in module_key_params :
202201 show_single = True
202+ elif "maestro" in api_call_object :
203+ if "id" in module_key_params or "interface_name" in module_key_params or "site_id" in module_key_params :
204+ show_single = True
203205 else :
204206 if len (module_key_params ) > 0 :
205207 show_single = True
@@ -219,7 +221,7 @@ def chkp_facts_api_call(module, api_call_object, is_multible):
219221 }
220222
221223
222- def chkp_api_call (module , api_call_object , has_add_api , ignore = None , show_params = None , add_params = None ):
224+ def chkp_api_call (module , api_call_object , has_add_api , ignore = None , show_params = None , add_params = None , is_maestro_special = False ):
223225 target_version = get_version (module )
224226 changed = False
225227 if show_params is None :
@@ -229,46 +231,56 @@ def chkp_api_call(module, api_call_object, has_add_api, ignore=None, show_params
229231 modules_params_original = module .params
230232 module_params_show = dict ((k , v ) for k , v in module .params .items () if k in show_params and v is not None )
231233 module .params = module_params_show
232- code , res = api_call (module , target_version , api_call_object = "show-{0}" .format (api_call_object ))
233- before = res .copy ()
234- [before .pop (key , None ) for key in ignore ]
234+ if not is_maestro_special :
235+ code , res = api_call (module , target_version , api_call_object = "show-{0}" .format (api_call_object ))
236+ before = res .copy ()
237+ [before .pop (key , None ) for key in ignore ]
238+ else :
239+ code , res = api_call (module , target_version , api_call_object = "show-maestro-security-groups" )
240+ before = res .copy ()
235241
236242 # Run the command:
237243 module .params = modules_params_original
238244 if 'state' in module .params and module .params ['state' ] == 'absent' : # handle delete
239- if code == 200 :
240- # delete/show require same params
241- module .params = module_params_show
242- code , res = api_call (module , target_version , api_call_object = "delete-{0}" .format (api_call_object ))
245+ if is_maestro_special :
246+ code , res = api_call (module , target_version , api_call_object = "discard-{0}" .format (api_call_object ))
243247 else :
244- return {
245- api_call_object .replace ('-' , '_' ): {},
246- "changed" : False
247- }
248- else : # handle set/add
249- params_dict = module .params .copy ()
250- for key , value in module .params .items ():
251- if not is_checkpoint_param (key ):
252- del params_dict [key ]
253-
254- if code == 200 :
255- if idempotency_check (res , params_dict ) is True :
248+ if code == 200 :
249+ # delete/show require same params
250+ module .params = module_params_show
251+ code , res = api_call (module , target_version , api_call_object = "delete-{0}" .format (api_call_object ))
252+ else :
256253 return {
257- api_call_object .replace ('-' , '_' ): res ,
254+ api_call_object .replace ('-' , '_' ): {} ,
258255 "changed" : False
259256 }
260- code , res = api_call (module , target_version , api_call_object = "set-{0}" .format (api_call_object ))
257+ else : # handle set/add
258+ if is_maestro_special :
259+ code , res = api_call (module , target_version , api_call_object = "apply-{0}" .format (api_call_object ))
261260 else :
262- if has_add_api is True :
263- if add_params :
264- [module .params .pop (key ) for key in show_params if key not in add_params ]
265- module .params .update (add_params )
266- if 'loopback-interface' == api_call_object : # loopback doesn't take 'name' for add-... api
267- if 'name' in module .params :
268- module .params .pop ("name" )
269- code , res = api_call (module , target_version , api_call_object = "add-{0}" .format (api_call_object ))
270- else : # some requests like static-route don't have add, try set instead
261+ params_dict = module .params .copy ()
262+ for key , value in module .params .items ():
263+ if not is_checkpoint_param (key ):
264+ del params_dict [key ]
265+
266+ if code == 200 :
267+ if idempotency_check (res , params_dict ) is True :
268+ return {
269+ api_call_object .replace ('-' , '_' ): res ,
270+ "changed" : False
271+ }
271272 code , res = api_call (module , target_version , api_call_object = "set-{0}" .format (api_call_object ))
273+ else :
274+ if has_add_api is True :
275+ if add_params :
276+ [module .params .pop (key ) for key in show_params if key not in add_params ]
277+ module .params .update (add_params )
278+ if 'loopback-interface' == api_call_object : # loopback doesn't take 'name' for add-... api
279+ if 'name' in module .params :
280+ module .params .pop ("name" )
281+ code , res = api_call (module , target_version , api_call_object = "add-{0}" .format (api_call_object ))
282+ else : # some requests like static-route don't have add, try set instead
283+ code , res = api_call (module , target_version , api_call_object = "set-{0}" .format (api_call_object ))
272284
273285 if code == 200 :
274286 if 'wait_for_task' in module .params and module .params ['wait_for_task' ] is True :
0 commit comments