Debian Codegraph @

ansible_collections/check_point/mgmt/plugins/action/cp_mgmt_access_rules.py

raw
1 from __future__ import absolute_import, division, print_function
2
3 __metaclass__ = type
4
5
6 from ansible.errors import AnsibleActionFail
7 from ansible.plugins.action import ActionBase
8 from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import (
9 prepare_rule_params_for_execute_module,
10 check_if_to_publish_for_action,
11 )
12
13
14 class ActionModule(ActionBase):
15 def run(self, tmp=None, task_vars=None):
16
17 module = super(ActionModule, self).run(tmp, task_vars)
18
19 result = self._execute_module(
20 module_name="check_point.mgmt.cp_mgmt_access_rules",
21 module_args=self._task.args,
22 task_vars=task_vars,
23 tmp=tmp,
24 )
25
26 if "msg" in result.keys():
27 raise AnsibleActionFail(result["msg"])
28
29 module_args = self._task.args
30
31 fields = {"position", "layer", "auto_publish_session"}
32 rules_list = module_args["rules"]
33 for rule in rules_list:
34 for field in fields:
35 if field in rule.keys():
36 raise AnsibleActionFail(
37 "Unsupported parameter " + field + " for rule"
38 )
39 # check_fields_for_rule_action_module(module_args)
40 rules_list = self._task.args["rules"]
41 position = 1
42 below_rule_name = None
43
44 for rule in rules_list:
45 (
46 rule,
47 position,
48 below_rule_name,
49 ) = prepare_rule_params_for_execute_module(
50 rule=rule,
51 module_args=module_args,
52 position=position,
53 below_rule_name=below_rule_name,
54 )
55
56 result["rule: " + rule["name"]] = self._execute_module(
57 module_name="check_point.mgmt.cp_mgmt_access_rule",
58 module_args=rule,
59 task_vars=task_vars,
60 tmp=tmp,
61 wrap_async=False,
62 )
63 if (
64 "changed" in result["rule: " + rule["name"]].keys()
65 and result["rule: " + rule["name"]]["changed"] is True
66 ):
67 result["changed"] = True
68 if (
69 "failed" in result["rule: " + rule["name"]].keys()
70 and result["rule: " + rule["name"]]["failed"] is True
71 ):
72 temp = result["rule: " + rule["name"]].copy()
73 result = {}
74 result["rule: " + rule["name"]] = temp
75 result["failed"] = True
76 result["discard:"] = self._execute_module(
77 module_name="check_point.mgmt.cp_mgmt_discard",
78 module_args={},
79 task_vars=task_vars,
80 tmp=tmp,
81 )
82 break
83 if check_if_to_publish_for_action(result, module_args):
84 result["publish:"] = self._execute_module(
85 module_name="check_point.mgmt.cp_mgmt_publish",
86 module_args={},
87 task_vars=task_vars,
88 tmp=tmp,
89 )
90
91 return result