31
31
__metaclass__ = type
32
32
33
33
import time
34
-
35
34
from ansible .module_utils .connection import Connection
36
35
37
36
BEFORE_REQUEST = 1
@@ -200,6 +199,9 @@ def chkp_facts_api_call(module, api_call_object, is_multible):
200
199
if "static-route" == api_call_object :
201
200
if "address" in module_key_params and "mask_length" in module_key_params :
202
201
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
203
205
else :
204
206
if len (module_key_params ) > 0 :
205
207
show_single = True
@@ -219,7 +221,7 @@ def chkp_facts_api_call(module, api_call_object, is_multible):
219
221
}
220
222
221
223
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 ):
223
225
target_version = get_version (module )
224
226
changed = False
225
227
if show_params is None :
@@ -229,46 +231,56 @@ def chkp_api_call(module, api_call_object, has_add_api, ignore=None, show_params
229
231
modules_params_original = module .params
230
232
module_params_show = dict ((k , v ) for k , v in module .params .items () if k in show_params and v is not None )
231
233
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 ()
235
241
236
242
# Run the command:
237
243
module .params = modules_params_original
238
244
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 ))
243
247
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 :
256
253
return {
257
- api_call_object .replace ('-' , '_' ): res ,
254
+ api_call_object .replace ('-' , '_' ): {} ,
258
255
"changed" : False
259
256
}
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 ))
261
260
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
+ }
271
272
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 ))
272
284
273
285
if code == 200 :
274
286
if 'wait_for_task' in module .params and module .params ['wait_for_task' ] is True :
0 commit comments