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
This commit is contained in:
chkp-orso 2019-08-28 19:16:05 +03:00 committed by Sumit Jaiswal
parent 830f995ed4
commit c3d37f39b7
4 changed files with 71 additions and 71 deletions

View file

@ -27,11 +27,11 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
DOCUMENTATION = """ DOCUMENTATION = """
--- ---
module: cp_network module: cp_mgmt_network
short_description: Manages network objects on Checkpoint over Web Services API short_description: Manages network objects on Checkpoint over Web Services API
description: description:
- Manages network objects on Checkpoint devices including creating, updating and removing objects. - 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" version_added: "2.9"
author: "Or Soffer (@chkp-orso)" author: "Or Soffer (@chkp-orso)"
options: options:
@ -54,8 +54,8 @@ options:
type: str type: str
mask_length: mask_length:
description: description:
- IPv4 or IPv6 network mask length. If both masks are required use mask-length4 and mask-length6 fields - IPv4 or IPv6 network mask length. If both masks are required use mask-length4 and mask-length6 fields explicitly. Instead of IPv4 mask length
explicitly. Instead of IPv4 mask length it is possible to specify IPv4 mask itself in subnet-mask field. it is possible to specify IPv4 mask itself in subnet-mask field.
type: int type: int
mask_length4: mask_length4:
description: description:
@ -72,7 +72,7 @@ options:
nat_settings: nat_settings:
description: description:
- NAT settings. - NAT settings.
type: list type: dict
suboptions: suboptions:
auto_rule: auto_rule:
description: description:
@ -80,9 +80,8 @@ options:
type: bool type: bool
ip_address: ip_address:
description: description:
- IPv4 or IPv6 address. If both addresses are required use ipv4-address and ipv6-address fields - IPv4 or IPv6 address. If both addresses are required use ipv4-address and ipv6-address fields explicitly. This parameter is not
explicitly. This parameter is not required in case "method" parameter is "hide" and "hide-behind" parameter required in case "method" parameter is "hide" and "hide-behind" parameter is "gateway".
is "gateway".
type: str type: str
ipv4_address: ipv4_address:
description: description:
@ -119,19 +118,17 @@ options:
description: description:
- Color of the object. Should be one of existing colors. - Color of the object. Should be one of existing colors.
type: str type: str
choices: ['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green', 'khaki', choices: ['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green', 'khaki', 'orchid', 'dark orange', 'dark sea green',
'orchid', 'dark orange', 'dark sea green', 'pink', 'turquoise', 'dark blue', 'firebrick', 'brown', 'pink', 'turquoise', 'dark blue', 'firebrick', 'brown', 'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon',
'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon', 'coral', 'coral', 'sea green', 'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', 'sienna', 'yellow']
'sea green', 'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange',
'red', 'sienna', 'yellow']
comments: comments:
description: description:
- Comments string. - Comments string.
type: str type: str
details_level: details_level:
description: description:
- The level of detail for some of the fields in the response can vary from showing only the UID value of - 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
the object to a fully detailed representation of the object. representation of the object.
type: str type: str
choices: ['uid', 'standard', 'full'] choices: ['uid', 'standard', 'full']
groups: groups:
@ -144,34 +141,22 @@ options:
type: bool type: bool
ignore_errors: ignore_errors:
description: description:
- Apply changes ignoring errors. You won't be able to publish such a changes. If ignore-warnings flag was - 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.
omitted - warnings will also be ignored.
type: bool type: bool
new_name:
description:
- New name of the object.
type: str
extends_documentation_fragment: checkpoint_objects extends_documentation_fragment: checkpoint_objects
""" """
EXAMPLES = """ EXAMPLES = """
- name: add-network - name: add-network
cp_network: cp_mgmt_network:
name: New Network 3 name: New Network 1
nat_settings:
auto_rule: true
hide_behind: ip-address
install_on: All
ip_address: 192.0.2.1
method: static
state: present state: present
subnet: 192.0.2.1 subnet: 192.0.2.0
subnet_mask: 255.255.255.0 subnet_mask: 255.255.255.0
- name: set-network - name: set-network
cp_network: cp_mgmt_network:
color: green color: green
groups: New Group 1
mask_length: 16 mask_length: 16
name: New Network 1 name: New Network 1
new_name: New Network 2 new_name: New Network 2
@ -179,13 +164,13 @@ EXAMPLES = """
subnet: 192.0.0.0 subnet: 192.0.0.0
- name: delete-network - name: delete-network
cp_network: cp_mgmt_network:
name: New Network 2 name: New Network 2
state: absent state: absent
""" """
RETURN = """ RETURN = """
cp_network: cp_mgmt_network:
description: The checkpoint object created or updated. description: The checkpoint object created or updated.
returned: always, except when deleting the object. returned: always, except when deleting the object.
type: dict type: dict
@ -205,7 +190,7 @@ def main():
mask_length4=dict(type='int'), mask_length4=dict(type='int'),
mask_length6=dict(type='int'), mask_length6=dict(type='int'),
subnet_mask=dict(type='str'), subnet_mask=dict(type='str'),
nat_settings=dict(type='list', options=dict( nat_settings=dict(type='dict', options=dict(
auto_rule=dict(type='bool'), auto_rule=dict(type='bool'),
ip_address=dict(type='str'), ip_address=dict(type='str'),
ipv4_address=dict(type='str'), ipv4_address=dict(type='str'),
@ -216,19 +201,16 @@ def main():
)), )),
tags=dict(type='list'), tags=dict(type='list'),
broadcast=dict(type='str', choices=['disallow', 'allow']), broadcast=dict(type='str', choices=['disallow', 'allow']),
color=dict(type='str', choices=['aquamarine', 'black', 'blue', color=dict(type='str', choices=['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green',
'crete blue', 'burlywood', 'cyan', 'dark green', 'khaki', 'orchid', 'khaki', 'orchid', 'dark orange', 'dark sea green', 'pink', 'turquoise', 'dark blue', 'firebrick', 'brown',
'dark orange', 'dark sea green', 'pink', 'turquoise', 'dark blue', 'firebrick', 'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon', 'coral', 'sea green',
'brown', 'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', 'sienna',
'light green', 'lemon chiffon', 'coral', 'sea green', 'sky blue', 'magenta', 'yellow']),
'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red',
'sienna', 'yellow']),
comments=dict(type='str'), comments=dict(type='str'),
details_level=dict(type='str', choices=['uid', 'standard', 'full']), details_level=dict(type='str', choices=['uid', 'standard', 'full']),
groups=dict(type='list'), groups=dict(type='list'),
ignore_warnings=dict(type='bool'), ignore_warnings=dict(type='bool'),
ignore_errors=dict(type='bool'), ignore_errors=dict(type='bool')
new_name=dict(type='str')
) )
argument_spec.update(checkpoint_argument_spec_for_objects) argument_spec.update(checkpoint_argument_spec_for_objects)

View file

@ -27,12 +27,12 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
DOCUMENTATION = """ DOCUMENTATION = """
--- ---
module: cp_network_facts module: cp_mgmt_network_facts
short_description: Get network objects facts on Checkpoint over Web Services API short_description: Get network objects facts on Checkpoint over Web Services API
description: description:
- Get network objects facts on Checkpoint devices. - Get network objects facts on Checkpoint devices.
All operations are performed over Web Services API. - All operations are performed over Web Services API.
This module handles both operations, get a specific object and get several objects. - This module handles both operations, get a specific object and get several objects,
For getting a specific object use the parameter 'name'. For getting a specific object use the parameter 'name'.
version_added: "2.9" version_added: "2.9"
author: "Or Soffer (@chkp-orso)" author: "Or Soffer (@chkp-orso)"
@ -40,25 +40,40 @@ options:
name: name:
description: description:
- Object name. - Object name.
This parameter is relevant only for getting a specific object.
type: str type: str
details_level: details_level:
description: description:
- The level of detail for some of the fields in the response can vary from showing only the UID value of - 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
the object to a fully detailed representation of the object. representation of the object.
type: str type: str
choices: ['uid', 'standard', 'full'] choices: ['uid', 'standard', 'full']
limit: limit:
description: description:
- No more than that many results will be returned. - No more than that many results will be returned.
This parameter is relevant only for getting few objects.
type: int type: int
offset: offset:
description: description:
- Skip that many results before beginning to return them. - Skip that many results before beginning to return them.
This parameter is relevant only for getting few objects.
type: int type: int
order: order:
description: description:
- Sorts results by the given field. By default the results are sorted in the ascending order by name. - 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 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: show_membership:
description: description:
- Indicates whether to calculate and show "groups" field for every object in reply. - Indicates whether to calculate and show "groups" field for every object in reply.
@ -68,11 +83,11 @@ extends_documentation_fragment: checkpoint_facts
EXAMPLES = """ EXAMPLES = """
- name: show-network - name: show-network
cp_network_facts: cp_mgmt_network_facts:
name: New Network 1 name: New Network 1
- name: show-networks - name: show-networks
cp_network_facts: cp_mgmt_network_facts:
details_level: standard details_level: standard
limit: 50 limit: 50
offset: 0 offset: 0
@ -95,7 +110,10 @@ def main():
details_level=dict(type='str', choices=['uid', 'standard', 'full']), details_level=dict(type='str', choices=['uid', 'standard', 'full']),
limit=dict(type='int'), limit=dict(type='int'),
offset=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') show_membership=dict(type='bool')
) )
argument_spec.update(checkpoint_argument_spec_for_facts) argument_spec.update(checkpoint_argument_spec_for_facts)

View file

@ -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_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 future-import-boilerplate
test/units/modules/network/checkpoint/test_checkpoint_task_facts.py metaclass-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_mgmt_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 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 future-import-boilerplate
test/units/modules/network/cloudvision/test_cv_server_provision.py metaclass-boilerplate test/units/modules/network/cloudvision/test_cv_server_provision.py metaclass-boilerplate
test/units/modules/network/cumulus/test_nclu.py future-import-boilerplate test/units/modules/network/cumulus/test_nclu.py future-import-boilerplate

View file

@ -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 import basic
from ansible.module_utils.network.checkpoint.checkpoint import api_call 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, OBJECT = {'name': 'test_network', 'nat_settings': {'auto_rule': True,
'hide_behind': 'ip-address', 'hide_behind': 'ip-address',
'ip_address': '192.168.1.111'}], 'ip_address': '192.168.1.111'},
'subnet': '192.0.2.1', 'subnet_mask': '255.255.255.0', 'state': 'present'} 'subnet': '192.0.2.1', 'subnet_mask': '255.255.255.0', 'state': 'present'}
CREATE_PAYLOAD = {'name': 'test_network', 'nat_settings': [{'auto_rule': True, CREATE_PAYLOAD = {'name': 'test_network', 'nat_settings': {'auto_rule': True,
'hide_behind': 'ip-address', 'hide_behind': 'ip-address',
'ip_address': '192.168.1.111'}], 'ip_address': '192.168.1.111'},
'subnet': '192.168.1.0', 'subnet_mask': '255.255.255.0', 'state': 'present'} 'subnet': '192.168.1.0', 'subnet_mask': '255.255.255.0', 'state': 'present'}
UPDATE_PAYLOAD = {'name': 'test_new_network', 'nat_settings': [{'auto_rule': True, UPDATE_PAYLOAD = {'name': 'test_new_network', 'nat_settings': {'auto_rule': True,
'hide_behind': 'ip-address', 'hide_behind': 'ip-address',
'ip_address': '192.168.1.111'}], 'ip_address': '192.168.1.111'},
'subnet': '192.168.1.0', 'subnet_mask': '255.255.255.0', 'state': 'present'} 'subnet': '192.168.1.0', 'subnet_mask': '255.255.255.0', 'state': 'present'}
DELETE_PAYLOAD = {'name': 'test_new_network', 'state': 'absent'} DELETE_PAYLOAD = {'name': 'test_new_network', 'state': 'absent'}
class TestCheckpointNetwork(object): class TestCheckpointNetwork(object):
module = cp_network module = cp_mgmt_network
checkpoint_argument_spec_for_objects = dict( checkpoint_argument_spec_for_objects = dict(
auto_publish_session=dict(type='bool'), auto_publish_session=dict(type='bool'),
@ -64,12 +64,12 @@ class TestCheckpointNetwork(object):
@pytest.fixture @pytest.fixture
def get_network_404(self, mocker): 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') mock_function.return_value = (404, 'Object not found')
return mock_function.return_value return mock_function.return_value
def test_network_create(self, mocker, connection_mock): 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} mock_function.return_value = {'changed': True, 'network': OBJECT}
connection_mock.api_call.return_value = {'changed': True, 'network': OBJECT} connection_mock.api_call.return_value = {'changed': True, 'network': OBJECT}
result = self._run_module(CREATE_PAYLOAD) result = self._run_module(CREATE_PAYLOAD)
@ -78,7 +78,7 @@ class TestCheckpointNetwork(object):
assert 'network' in result assert 'network' in result
def test_network_create_idempotent(self, mocker, connection_mock): 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} mock_function.return_value = {'changed': False, 'network': OBJECT}
connection_mock.send_request.return_value = (200, OBJECT) connection_mock.send_request.return_value = (200, OBJECT)
result = self._run_module(CREATE_PAYLOAD) result = self._run_module(CREATE_PAYLOAD)
@ -86,7 +86,7 @@ class TestCheckpointNetwork(object):
assert not result['changed'] assert not result['changed']
def test_network_update(self, mocker, connection_mock): 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} mock_function.return_value = {'changed': True, 'network': OBJECT}
connection_mock.send_request.return_value = (200, OBJECT) connection_mock.send_request.return_value = (200, OBJECT)
result = self._run_module(UPDATE_PAYLOAD) result = self._run_module(UPDATE_PAYLOAD)
@ -94,7 +94,7 @@ class TestCheckpointNetwork(object):
assert result['changed'] assert result['changed']
def test_network_delete(self, mocker, connection_mock): 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} mock_function.return_value = {'changed': True}
connection_mock.send_request.return_value = (200, OBJECT) connection_mock.send_request.return_value = (200, OBJECT)
result = self._run_module(DELETE_PAYLOAD) result = self._run_module(DELETE_PAYLOAD)
@ -102,7 +102,7 @@ class TestCheckpointNetwork(object):
assert result['changed'] assert result['changed']
def test_network_delete_idempotent(self, mocker, connection_mock): 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} mock_function.return_value = {'changed': False}
connection_mock.send_request.return_value = (200, OBJECT) connection_mock.send_request.return_value = (200, OBJECT)
result = self._run_module(DELETE_PAYLOAD) result = self._run_module(DELETE_PAYLOAD)