|
1 | | -from __future__ import (absolute_import, division, print_function) |
| 1 | +from __future__ import absolute_import, division, print_function |
2 | 2 |
|
3 | 3 | __metaclass__ = type |
4 | 4 |
|
5 | 5 |
|
6 | 6 | from ansible.errors import AnsibleActionFail |
7 | 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, check_if_to_publish_for_action |
| 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 | +) |
10 | 12 |
|
11 | 13 |
|
12 | 14 | class ActionModule(ActionBase): |
13 | | - |
14 | 15 | def run(self, tmp=None, task_vars=None): |
15 | 16 |
|
16 | 17 | module = super(ActionModule, self).run(tmp, task_vars) |
17 | 18 |
|
18 | | - result = self._execute_module(module_name='check_point.mgmt.cp_mgmt_access_rules', module_args=self._task.args, |
19 | | - task_vars=task_vars, tmp=tmp) |
| 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 | + ) |
20 | 25 |
|
21 | | - if 'msg' in result.keys(): |
22 | | - raise AnsibleActionFail(result['msg']) |
| 26 | + if "msg" in result.keys(): |
| 27 | + raise AnsibleActionFail(result["msg"]) |
23 | 28 |
|
24 | 29 | module_args = self._task.args |
25 | 30 |
|
26 | | - fields = {'position', 'layer', 'auto_publish_session'} |
27 | | - rules_list = module_args['rules'] |
| 31 | + fields = {"position", "layer", "auto_publish_session"} |
| 32 | + rules_list = module_args["rules"] |
28 | 33 | for rule in rules_list: |
29 | 34 | for field in fields: |
30 | 35 | if field in rule.keys(): |
31 | | - raise AnsibleActionFail('Unsupported parameter ' + field + ' for rule') |
| 36 | + raise AnsibleActionFail( |
| 37 | + "Unsupported parameter " + field + " for rule" |
| 38 | + ) |
32 | 39 | # check_fields_for_rule_action_module(module_args) |
33 | | - rules_list = self._task.args['rules'] |
| 40 | + rules_list = self._task.args["rules"] |
34 | 41 | position = 1 |
35 | 42 | below_rule_name = None |
36 | 43 |
|
37 | 44 | for rule in rules_list: |
38 | | - rule, position, below_rule_name = prepare_rule_params_for_execute_module(rule=rule, module_args=module_args, |
39 | | - position=position, |
40 | | - below_rule_name=below_rule_name) |
41 | | - |
42 | | - result['rule: ' + rule['name']] = self._execute_module(module_name='check_point.mgmt.cp_mgmt_access_rule', |
43 | | - module_args=rule, |
44 | | - task_vars=task_vars, tmp=tmp, wrap_async=False) |
45 | | - if 'changed' in result['rule: ' + rule['name']].keys() and \ |
46 | | - result['rule: ' + rule['name']]['changed'] is True: |
47 | | - result['changed'] = True |
48 | | - if 'failed' in result['rule: ' + rule['name']].keys() and result['rule: ' + rule['name']]['failed'] is True: |
49 | | - temp = result['rule: ' + rule['name']].copy() |
| 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() |
50 | 73 | result = {} |
51 | | - result['rule: ' + rule['name']] = temp |
52 | | - result['failed'] = True |
53 | | - result['discard:'] = self._execute_module(module_name='check_point.mgmt.cp_mgmt_discard', |
54 | | - module_args={}, task_vars=task_vars, tmp=tmp) |
| 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 | + ) |
55 | 82 | break |
56 | 83 | if check_if_to_publish_for_action(result, module_args): |
57 | | - result['publish:'] = self._execute_module(module_name='check_point.mgmt.cp_mgmt_publish', module_args={}, |
58 | | - task_vars=task_vars, tmp=tmp) |
| 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 | + ) |
59 | 90 |
|
60 | 91 | return result |
0 commit comments