| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# |
| 4 |
# Ansible module to manage CheckPoint Firewall (c) 2019 |
| 5 |
# |
| 6 |
# Ansible is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# Ansible is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
# |
| 19 |
|
| 20 |
from __future__ import absolute_import, division, print_function |
| 21 |
|
| 22 |
__metaclass__ = type |
| 23 |
|
| 24 |
ANSIBLE_METADATA = { |
| 25 |
"metadata_version": "1.1", |
| 26 |
"status": ["preview"], |
| 27 |
"supported_by": "community", |
| 28 |
} |
| 29 |
|
| 30 |
DOCUMENTATION = """ |
| 31 |
--- |
| 32 |
module: cp_mgmt_delete_rules_batch |
| 33 |
short_description: Delete rules in batch from the same layer. Use this API to achieve optimum performance when removing more than one rule. |
| 34 |
description: |
| 35 |
- Delete rules in batch from the same layer. Use this API to achieve optimum performance when removing more than one rule. |
| 36 |
- Warnings are ignored when using this API, operation will apply changes while ignoring warnings. |
| 37 |
- Supported rules types are access-rule, nat-rule, https-rule and threat-exception. |
| 38 |
- This module is not idempotent. |
| 39 |
- All operations are performed over Web Services API. |
| 40 |
- Available from R81.10 JHF management version. |
| 41 |
version_added: "3.0.0" |
| 42 |
author: "Eden Brillant (@chkp-edenbr)" |
| 43 |
options: |
| 44 |
objects: |
| 45 |
description: |
| 46 |
- Batch of rules separated by types. |
| 47 |
type: list |
| 48 |
elements: dict |
| 49 |
suboptions: |
| 50 |
layer: |
| 51 |
description: |
| 52 |
- Layer name or uid. |
| 53 |
type: str |
| 54 |
type: |
| 55 |
description: |
| 56 |
- Type of rules to be deleted. <br>Only types from above are supported. |
| 57 |
type: str |
| 58 |
list: |
| 59 |
description: |
| 60 |
- List of rules from the same type to be deleted. <br>Use the "delete" API reference documentation for a single rule command to find the |
| 61 |
expected fields for the request.<br>For example, to delete access-rule, use the "delete-access-rule" command found in the API reference |
| 62 |
documentation (under Access Control & NAT). <br>Note, "ignore-errors", "ignore-warnings" and "details-level" options are not supported when |
| 63 |
deleting a batch of objects. |
| 64 |
type: list |
| 65 |
elements: dict |
| 66 |
auto_publish_session: |
| 67 |
description: |
| 68 |
- Publish the current session if changes have been performed after task completes. |
| 69 |
type: bool |
| 70 |
extends_documentation_fragment: check_point.mgmt.checkpoint_commands |
| 71 |
""" |
| 72 |
|
| 73 |
EXAMPLES = """ |
| 74 |
- name: delete-rules-batch |
| 75 |
cp_mgmt_delete_rules_batch: |
| 76 |
objects: |
| 77 |
- layer: Network |
| 78 |
list: |
| 79 |
- rule_number: 1 |
| 80 |
- rule_number: 2 |
| 81 |
type: access-rule |
| 82 |
- layer: Standard |
| 83 |
list: |
| 84 |
- rule_number: 1 |
| 85 |
- rule_number: 2 |
| 86 |
type: nat-rule |
| 87 |
- layer: Default Layer |
| 88 |
list: |
| 89 |
- rule_number: 1 |
| 90 |
- rule_number: 2 |
| 91 |
type: https-rule |
| 92 |
""" |
| 93 |
|
| 94 |
RETURN = """ |
| 95 |
cp_mgmt_delete_rules_batch: |
| 96 |
description: The checkpoint delete-rules-batch output. |
| 97 |
returned: always. |
| 98 |
type: dict |
| 99 |
""" |
| 100 |
|
| 101 |
from ansible.module_utils.basic import AnsibleModule |
| 102 |
from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import ( |
| 103 |
checkpoint_argument_spec_for_commands, |
| 104 |
api_command, |
| 105 |
) |
| 106 |
|
| 107 |
|
| 108 |
def main(): |
| 109 |
argument_spec = dict( |
| 110 |
objects=dict( |
| 111 |
type="list", |
| 112 |
elements="dict", |
| 113 |
options=dict( |
| 114 |
layer=dict(type="str"), |
| 115 |
type=dict(type="str"), |
| 116 |
list=dict(type="list", elements="dict"), |
| 117 |
), |
| 118 |
), |
| 119 |
auto_publish_session=dict(type="bool"), |
| 120 |
) |
| 121 |
argument_spec.update(checkpoint_argument_spec_for_commands) |
| 122 |
|
| 123 |
module = AnsibleModule(argument_spec=argument_spec) |
| 124 |
|
| 125 |
command = "delete-rules-batch" |
| 126 |
|
| 127 |
result = api_command(module, command) |
| 128 |
module.exit_json(**result) |
| 129 |
|
| 130 |
|
| 131 |
if __name__ == "__main__": |
| 132 |
main() |