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:
parent
830f995ed4
commit
c3d37f39b7
4 changed files with 71 additions and 71 deletions
|
@ -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)
|
||||
|
|
@ -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)
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
OBJECT = {'name': 'test_network', 'nat_settings': {'auto_rule': True,
|
||||
'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'}
|
||||
|
||||
CREATE_PAYLOAD = {'name': 'test_network', 'nat_settings': [{'auto_rule': True,
|
||||
CREATE_PAYLOAD = {'name': 'test_network', 'nat_settings': {'auto_rule': True,
|
||||
'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'}
|
||||
|
||||
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',
|
||||
'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'}
|
||||
|
||||
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)
|
Loading…
Reference in a new issue