From c3d37f39b76d5220ab721e43e29223cd43fb4463 Mon Sep 17 00:00:00 2001 From: chkp-orso <47325598+chkp-orso@users.noreply.github.com> Date: Wed, 28 Aug 2019 19:16:05 +0300 Subject: [PATCH] Checkpoint Network module (#61309) * network module * delete cp_network, cp_network_facts, and change test_cp_network to match the new network module * Update ignore.txt * adding state: present * update example * list to dict * Update test_cp_mgmt_network.py * remove white-space --- .../{cp_network.py => cp_mgmt_network.py} | 70 +++++++------------ ...work_facts.py => cp_mgmt_network_facts.py} | 34 ++++++--- test/sanity/ignore.txt | 4 +- ..._cp_network.py => test_cp_mgmt_network.py} | 34 ++++----- 4 files changed, 71 insertions(+), 71 deletions(-) rename lib/ansible/modules/network/checkpoint/{cp_network.py => cp_mgmt_network.py} (72%) rename lib/ansible/modules/network/checkpoint/{cp_network_facts.py => cp_mgmt_network_facts.py} (74%) rename test/units/modules/network/checkpoint/{test_cp_network.py => test_cp_mgmt_network.py} (80%) diff --git a/lib/ansible/modules/network/checkpoint/cp_network.py b/lib/ansible/modules/network/checkpoint/cp_mgmt_network.py similarity index 72% rename from lib/ansible/modules/network/checkpoint/cp_network.py rename to lib/ansible/modules/network/checkpoint/cp_mgmt_network.py index f3f62796a4d..64afe5d8cc8 100644 --- a/lib/ansible/modules/network/checkpoint/cp_network.py +++ b/lib/ansible/modules/network/checkpoint/cp_mgmt_network.py @@ -27,11 +27,11 @@ ANSIBLE_METADATA = {'metadata_version': '1.1', DOCUMENTATION = """ --- -module: cp_network +module: cp_mgmt_network short_description: Manages network objects on Checkpoint over Web Services API description: - Manages network objects on Checkpoint devices including creating, updating and removing objects. - All operations are performed over Web Services API. + - All operations are performed over Web Services API. version_added: "2.9" author: "Or Soffer (@chkp-orso)" options: @@ -54,8 +54,8 @@ options: type: str mask_length: description: - - IPv4 or IPv6 network mask length. If both masks are required use mask-length4 and mask-length6 fields - explicitly. Instead of IPv4 mask length it is possible to specify IPv4 mask itself in subnet-mask field. + - IPv4 or IPv6 network mask length. If both masks are required use mask-length4 and mask-length6 fields explicitly. Instead of IPv4 mask length + it is possible to specify IPv4 mask itself in subnet-mask field. type: int mask_length4: description: @@ -72,7 +72,7 @@ options: nat_settings: description: - NAT settings. - type: list + type: dict suboptions: auto_rule: description: @@ -80,9 +80,8 @@ options: type: bool ip_address: description: - - IPv4 or IPv6 address. If both addresses are required use ipv4-address and ipv6-address fields - explicitly. This parameter is not required in case "method" parameter is "hide" and "hide-behind" parameter - is "gateway". + - IPv4 or IPv6 address. If both addresses are required use ipv4-address and ipv6-address fields explicitly. This parameter is not + required in case "method" parameter is "hide" and "hide-behind" parameter is "gateway". type: str ipv4_address: description: @@ -119,19 +118,17 @@ options: description: - Color of the object. Should be one of existing colors. type: str - choices: ['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green', 'khaki', - 'orchid', 'dark orange', 'dark sea green', 'pink', 'turquoise', 'dark blue', 'firebrick', 'brown', - 'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon', 'coral', - 'sea green', 'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', - 'red', 'sienna', 'yellow'] + choices: ['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green', 'khaki', 'orchid', 'dark orange', 'dark sea green', + 'pink', 'turquoise', 'dark blue', 'firebrick', 'brown', 'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon', + 'coral', 'sea green', 'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', 'sienna', 'yellow'] comments: description: - Comments string. type: str details_level: description: - - The level of detail for some of the fields in the response can vary from showing only the UID value of - the object to a fully detailed representation of the object. + - The level of detail for some of the fields in the response can vary from showing only the UID value of the object to a fully detailed + representation of the object. type: str choices: ['uid', 'standard', 'full'] groups: @@ -144,34 +141,22 @@ options: type: bool ignore_errors: description: - - Apply changes ignoring errors. You won't be able to publish such a changes. If ignore-warnings flag was - omitted - warnings will also be ignored. + - Apply changes ignoring errors. You won't be able to publish such a changes. If ignore-warnings flag was omitted - warnings will also be ignored. type: bool - new_name: - description: - - New name of the object. - type: str extends_documentation_fragment: checkpoint_objects """ EXAMPLES = """ - name: add-network - cp_network: - name: New Network 3 - nat_settings: - auto_rule: true - hide_behind: ip-address - install_on: All - ip_address: 192.0.2.1 - method: static + cp_mgmt_network: + name: New Network 1 state: present - subnet: 192.0.2.1 + subnet: 192.0.2.0 subnet_mask: 255.255.255.0 - name: set-network - cp_network: + cp_mgmt_network: color: green - groups: New Group 1 mask_length: 16 name: New Network 1 new_name: New Network 2 @@ -179,13 +164,13 @@ EXAMPLES = """ subnet: 192.0.0.0 - name: delete-network - cp_network: + cp_mgmt_network: name: New Network 2 state: absent """ RETURN = """ -cp_network: +cp_mgmt_network: description: The checkpoint object created or updated. returned: always, except when deleting the object. type: dict @@ -205,7 +190,7 @@ def main(): mask_length4=dict(type='int'), mask_length6=dict(type='int'), subnet_mask=dict(type='str'), - nat_settings=dict(type='list', options=dict( + nat_settings=dict(type='dict', options=dict( auto_rule=dict(type='bool'), ip_address=dict(type='str'), ipv4_address=dict(type='str'), @@ -216,19 +201,16 @@ def main(): )), tags=dict(type='list'), broadcast=dict(type='str', choices=['disallow', 'allow']), - color=dict(type='str', choices=['aquamarine', 'black', 'blue', - 'crete blue', 'burlywood', 'cyan', 'dark green', 'khaki', 'orchid', - 'dark orange', 'dark sea green', 'pink', 'turquoise', 'dark blue', 'firebrick', - 'brown', 'forest green', 'gold', 'dark gold', 'gray', 'dark gray', - 'light green', 'lemon chiffon', 'coral', 'sea green', 'sky blue', 'magenta', - 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', - 'sienna', 'yellow']), + color=dict(type='str', choices=['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green', + 'khaki', 'orchid', 'dark orange', 'dark sea green', 'pink', 'turquoise', 'dark blue', 'firebrick', 'brown', + 'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon', 'coral', 'sea green', + 'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', 'sienna', + 'yellow']), comments=dict(type='str'), details_level=dict(type='str', choices=['uid', 'standard', 'full']), groups=dict(type='list'), ignore_warnings=dict(type='bool'), - ignore_errors=dict(type='bool'), - new_name=dict(type='str') + ignore_errors=dict(type='bool') ) argument_spec.update(checkpoint_argument_spec_for_objects) diff --git a/lib/ansible/modules/network/checkpoint/cp_network_facts.py b/lib/ansible/modules/network/checkpoint/cp_mgmt_network_facts.py similarity index 74% rename from lib/ansible/modules/network/checkpoint/cp_network_facts.py rename to lib/ansible/modules/network/checkpoint/cp_mgmt_network_facts.py index 81e9b51f3cf..262c5911ee0 100644 --- a/lib/ansible/modules/network/checkpoint/cp_network_facts.py +++ b/lib/ansible/modules/network/checkpoint/cp_mgmt_network_facts.py @@ -27,12 +27,12 @@ ANSIBLE_METADATA = {'metadata_version': '1.1', DOCUMENTATION = """ --- -module: cp_network_facts +module: cp_mgmt_network_facts short_description: Get network objects facts on Checkpoint over Web Services API description: - Get network objects facts on Checkpoint devices. - All operations are performed over Web Services API. - This module handles both operations, get a specific object and get several objects. + - All operations are performed over Web Services API. + - This module handles both operations, get a specific object and get several objects, For getting a specific object use the parameter 'name'. version_added: "2.9" author: "Or Soffer (@chkp-orso)" @@ -40,25 +40,40 @@ options: name: description: - Object name. + This parameter is relevant only for getting a specific object. type: str details_level: description: - - The level of detail for some of the fields in the response can vary from showing only the UID value of - the object to a fully detailed representation of the object. + - The level of detail for some of the fields in the response can vary from showing only the UID value of the object to a fully detailed + representation of the object. type: str choices: ['uid', 'standard', 'full'] limit: description: - No more than that many results will be returned. + This parameter is relevant only for getting few objects. type: int offset: description: - Skip that many results before beginning to return them. + This parameter is relevant only for getting few objects. type: int order: description: - Sorts results by the given field. By default the results are sorted in the ascending order by name. + This parameter is relevant only for getting few objects. type: list + suboptions: + ASC: + description: + - Sorts results by the given field in ascending order. + type: str + choices: ['name'] + DESC: + description: + - Sorts results by the given field in descending order. + type: str + choices: ['name'] show_membership: description: - Indicates whether to calculate and show "groups" field for every object in reply. @@ -68,11 +83,11 @@ extends_documentation_fragment: checkpoint_facts EXAMPLES = """ - name: show-network - cp_network_facts: + cp_mgmt_network_facts: name: New Network 1 - name: show-networks - cp_network_facts: + cp_mgmt_network_facts: details_level: standard limit: 50 offset: 0 @@ -95,7 +110,10 @@ def main(): details_level=dict(type='str', choices=['uid', 'standard', 'full']), limit=dict(type='int'), offset=dict(type='int'), - order=dict(type='list'), + order=dict(type='list', options=dict( + ASC=dict(type='str', choices=['name']), + DESC=dict(type='str', choices=['name']) + )), show_membership=dict(type='bool') ) argument_spec.update(checkpoint_argument_spec_for_facts) diff --git a/test/sanity/ignore.txt b/test/sanity/ignore.txt index 21f707c06ef..7db85707124 100644 --- a/test/sanity/ignore.txt +++ b/test/sanity/ignore.txt @@ -6323,8 +6323,8 @@ test/units/modules/network/checkpoint/test_checkpoint_session.py future-import-b test/units/modules/network/checkpoint/test_checkpoint_session.py metaclass-boilerplate test/units/modules/network/checkpoint/test_checkpoint_task_facts.py future-import-boilerplate test/units/modules/network/checkpoint/test_checkpoint_task_facts.py metaclass-boilerplate -test/units/modules/network/checkpoint/test_cp_network.py future-import-boilerplate -test/units/modules/network/checkpoint/test_cp_network.py metaclass-boilerplate +test/units/modules/network/checkpoint/test_cp_mgmt_network.py future-import-boilerplate +test/units/modules/network/checkpoint/test_cp_mgmt_network.py metaclass-boilerplate test/units/modules/network/cloudvision/test_cv_server_provision.py future-import-boilerplate test/units/modules/network/cloudvision/test_cv_server_provision.py metaclass-boilerplate test/units/modules/network/cumulus/test_nclu.py future-import-boilerplate diff --git a/test/units/modules/network/checkpoint/test_cp_network.py b/test/units/modules/network/checkpoint/test_cp_mgmt_network.py similarity index 80% rename from test/units/modules/network/checkpoint/test_cp_network.py rename to test/units/modules/network/checkpoint/test_cp_mgmt_network.py index 1cd7c091ab3..88af4b995f5 100644 --- a/test/units/modules/network/checkpoint/test_cp_network.py +++ b/test/units/modules/network/checkpoint/test_cp_mgmt_network.py @@ -23,28 +23,28 @@ from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleFa from ansible.module_utils import basic from ansible.module_utils.network.checkpoint.checkpoint import api_call -from ansible.modules.network.checkpoint import cp_network +from ansible.modules.network.checkpoint import cp_mgmt_network -OBJECT = {'name': 'test_network', 'nat_settings': [{'auto_rule': True, - 'hide_behind': 'ip-address', - 'ip_address': '192.168.1.111'}], +OBJECT = {'name': 'test_network', 'nat_settings': {'auto_rule': True, + 'hide_behind': 'ip-address', + 'ip_address': '192.168.1.111'}, 'subnet': '192.0.2.1', 'subnet_mask': '255.255.255.0', 'state': 'present'} -CREATE_PAYLOAD = {'name': 'test_network', 'nat_settings': [{'auto_rule': True, - 'hide_behind': 'ip-address', - 'ip_address': '192.168.1.111'}], +CREATE_PAYLOAD = {'name': 'test_network', 'nat_settings': {'auto_rule': True, + 'hide_behind': 'ip-address', + 'ip_address': '192.168.1.111'}, 'subnet': '192.168.1.0', 'subnet_mask': '255.255.255.0', 'state': 'present'} -UPDATE_PAYLOAD = {'name': 'test_new_network', 'nat_settings': [{'auto_rule': True, - 'hide_behind': 'ip-address', - 'ip_address': '192.168.1.111'}], +UPDATE_PAYLOAD = {'name': 'test_new_network', 'nat_settings': {'auto_rule': True, + 'hide_behind': 'ip-address', + 'ip_address': '192.168.1.111'}, 'subnet': '192.168.1.0', 'subnet_mask': '255.255.255.0', 'state': 'present'} DELETE_PAYLOAD = {'name': 'test_new_network', 'state': 'absent'} class TestCheckpointNetwork(object): - module = cp_network + module = cp_mgmt_network checkpoint_argument_spec_for_objects = dict( auto_publish_session=dict(type='bool'), @@ -64,12 +64,12 @@ class TestCheckpointNetwork(object): @pytest.fixture def get_network_404(self, mocker): - mock_function = mocker.patch('ansible.modules.network.checkpoint.cp_network.api_call') + mock_function = mocker.patch('ansible.modules.network.checkpoint.cp_mgmt_network.api_call') mock_function.return_value = (404, 'Object not found') return mock_function.return_value def test_network_create(self, mocker, connection_mock): - mock_function = mocker.patch('ansible.modules.network.checkpoint.cp_network.api_call') + mock_function = mocker.patch('ansible.modules.network.checkpoint.cp_mgmt_network.api_call') mock_function.return_value = {'changed': True, 'network': OBJECT} connection_mock.api_call.return_value = {'changed': True, 'network': OBJECT} result = self._run_module(CREATE_PAYLOAD) @@ -78,7 +78,7 @@ class TestCheckpointNetwork(object): assert 'network' in result def test_network_create_idempotent(self, mocker, connection_mock): - mock_function = mocker.patch('ansible.modules.network.checkpoint.cp_network.api_call') + mock_function = mocker.patch('ansible.modules.network.checkpoint.cp_mgmt_network.api_call') mock_function.return_value = {'changed': False, 'network': OBJECT} connection_mock.send_request.return_value = (200, OBJECT) result = self._run_module(CREATE_PAYLOAD) @@ -86,7 +86,7 @@ class TestCheckpointNetwork(object): assert not result['changed'] def test_network_update(self, mocker, connection_mock): - mock_function = mocker.patch('ansible.modules.network.checkpoint.cp_network.api_call') + mock_function = mocker.patch('ansible.modules.network.checkpoint.cp_mgmt_network.api_call') mock_function.return_value = {'changed': True, 'network': OBJECT} connection_mock.send_request.return_value = (200, OBJECT) result = self._run_module(UPDATE_PAYLOAD) @@ -94,7 +94,7 @@ class TestCheckpointNetwork(object): assert result['changed'] def test_network_delete(self, mocker, connection_mock): - mock_function = mocker.patch('ansible.modules.network.checkpoint.cp_network.api_call') + mock_function = mocker.patch('ansible.modules.network.checkpoint.cp_mgmt_network.api_call') mock_function.return_value = {'changed': True} connection_mock.send_request.return_value = (200, OBJECT) result = self._run_module(DELETE_PAYLOAD) @@ -102,7 +102,7 @@ class TestCheckpointNetwork(object): assert result['changed'] def test_network_delete_idempotent(self, mocker, connection_mock): - mock_function = mocker.patch('ansible.modules.network.checkpoint.cp_network.api_call') + mock_function = mocker.patch('ansible.modules.network.checkpoint.cp_mgmt_network.api_call') mock_function.return_value = {'changed': False} connection_mock.send_request.return_value = (200, OBJECT) result = self._run_module(DELETE_PAYLOAD)