6060
6161delete_params = ['name' , 'uid' , 'layer' , 'exception-group-name' , 'rule-name' , 'package' ]
6262
63+ remove_from_set_payload = {'lsm-cluster' : ['security-profile' , 'name-prefix' , 'name-suffix' , 'main-ip-address' ],
64+ 'md-permissions-profile' : ['permission-level' ]}
65+
66+ remove_from_add_payload = {'lsm-cluster' : ['name' ]}
67+
6368
6469# parse failure message with code and response
6570def parse_fail_message (code , response ):
@@ -84,6 +89,14 @@ def is_checkpoint_param(parameter):
8489 return True
8590
8691
92+ def contains_show_identifier_param (payload ):
93+ identifier_params = ["name" , "uid" , "assigned-domain" ]
94+ for param in identifier_params :
95+ if payload .get (param ) is not None :
96+ return True
97+ return False
98+
99+
87100# build the payload from the parameters which has value (not None), and they are parameter of checkpoint API as well
88101def get_payload_from_parameters (params ):
89102 payload = {}
@@ -210,7 +223,7 @@ def discard_and_fail(module, code, response, connection, version):
210223
211224# handle publish command, and wait for it to end if the user asked so
212225def handle_publish (module , connection , version ):
213- if module .params ['auto_publish_session' ]:
226+ if 'auto_publish_session' in module . params and module .params ['auto_publish_session' ]:
214227 publish_code , publish_response = send_request (connection , version , 'publish' )
215228 if publish_code != 200 :
216229 discard_and_fail (module , publish_code , publish_response , connection , version )
@@ -275,6 +288,8 @@ def api_command(module, command):
275288 del response ['tasks' ]
276289
277290 result [command ] = response
291+
292+ handle_publish (module , connection , version )
278293 else :
279294 discard_and_fail (module , code , response , connection , version )
280295
@@ -287,8 +302,8 @@ def api_call_facts(module, api_call_object, api_call_object_plural_version):
287302 connection = Connection (module ._socket_path )
288303 version = get_version (module )
289304
290- # if there is neither name nor uid , the API command will be in plural version (e.g. show-hosts instead of show-host)
291- if payload . get ( "name" ) is None and payload . get ( "uid" ) is None :
305+ # if there isn't an identifier param , the API command will be in plural version (e.g. show-hosts instead of show-host)
306+ if not contains_show_identifier_param ( payload ) :
292307 api_call_object = api_call_object_plural_version
293308
294309 response = handle_call (connection , version , 'show-' + api_call_object , payload , module , False , False )
@@ -331,12 +346,10 @@ def api_call(module, api_call_object):
331346 if equals_code == 200 :
332347 # else objects are equals and there is no need for set request
333348 if not equals_response ['equals' ]:
334- if 'lsm-cluster' == api_call_object :
335- build_lsm_cluster_payload (payload , 'set' )
349+ build_payload (api_call_object , payload , remove_from_set_payload )
336350 handle_call_and_set_result (connection , version , 'set-' + api_call_object , payload , module , result )
337351 elif equals_code == 404 :
338- if 'lsm-cluster' == api_call_object :
339- build_lsm_cluster_payload (payload , 'add' )
352+ build_payload (api_call_object , payload , remove_from_add_payload )
340353 handle_call_and_set_result (connection , version , 'add-' + api_call_object , payload , module , result )
341354 elif module .params ['state' ] == 'absent' :
342355 handle_delete (equals_code , payload , delete_params , connection , version , api_call_object , module , result )
@@ -406,17 +419,6 @@ def build_rulebase_payload(api_call_object, payload, position_number):
406419 return rulebase_payload
407420
408421
409- def build_lsm_cluster_payload (payload , operator ):
410- fields = ['security-profile' , 'name-prefix' , 'name-suffix' , 'main-ip-address' ]
411- if operator == 'add' :
412- del payload ['name' ]
413- else :
414- for field in fields :
415- if field in payload .keys ():
416- del payload [field ]
417- return payload
418-
419-
420422def build_rulebase_command (api_call_object ):
421423 rulebase_command = 'show-' + api_call_object .split ('-' )[0 ] + '-rulebase'
422424
@@ -426,6 +428,14 @@ def build_rulebase_command(api_call_object):
426428 return rulebase_command
427429
428430
431+ # remove from payload unrecognized params (used for cases where add payload differs from that of a set)
432+ def build_payload (api_call_object , payload , params_to_remove ):
433+ if api_call_object in params_to_remove :
434+ for param in params_to_remove [api_call_object ]:
435+ del payload [param ]
436+ return payload
437+
438+
429439# extract rule from rulebase response
430440def extract_rule_from_rulebase_response (response ):
431441 rule = response ['rulebase' ][0 ]
0 commit comments