Skip to content

Commit c57ffc1

Browse files
authored
Merge pull request #57 from chkp-andreybak/new-feature-branch
Add Maestro modules and modify checkpoint.py to support special Masero modules
2 parents 6e6a5ac + a52c168 commit c57ffc1

13 files changed

+1445
-34
lines changed

CHANGELOG.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,32 @@ Check_Point.gaia Release Notes
44

55
.. contents:: Topics
66

7+
v7.0.0
8+
======
9+
10+
Release Summary
11+
---------------
12+
13+
This is release 6.0.0 of ``check_point.gaia``, released on 2025-01-28.
14+
15+
New Modules
16+
-----------
17+
18+
- check_point.gaia.cp_gaia_maestro_changes – apply or discard pending Maestro changes over Web Services API.
19+
- check_point.gaia.cp_gaia_maestro_gateways – manage Maestro Gateways over Web Services API.
20+
- check_point.gaia.cp_gaia_maestro_gateways_facts – get information about Maestro Gateways over Web Services API.
21+
- check_point.gaia.cp_gaia_maestro_ports – configure Maestro Orchestrator ports over Web Services API.
22+
- check_point.gaia.cp_gaia_maestro_ports_facts - get information about Maestro Orchestrator ports over Web Services API.
23+
- check_point.gaia.cp_gaia_maestro_security_groups - manage Maestro Security Groups over Web Services API.
24+
- check_point.gaia.cp_gaia_maestro_security_groups_facts - get information about Maestro Security Groups over Web Services API.
25+
- check_point.gaia.cp_gaia_maestro_sites - add description to Maestro Sites over Web Services API.
26+
- check_point.gaia.cp_gaia_maestro_sites_facts - get information about Maestro Sites over Web Services API.
27+
28+
Minor Changes
29+
---------------
30+
31+
modify infrastructure to support special Maestro APIs.
32+
733

834
v6.0.1
935
======

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,15 @@ Modules
147147
* `cp_gaia_snmp_trap_receiver_facts` – get SNMP trap receiver configuration of a Check Point machine over Web Services API.
148148
* `cp_gaia_snmp_user` – manage SNMP USM user configuration of a Check Point machine over Web Services API.
149149
* `cp_gaia_snmp_user_facts` – get SNMP USM user configuration of a Check Point machine over Web Services API.
150-
150+
* `cp_gaia_maestro_changes` – apply or discard pending Maestro changes over Web Services API.
151+
* `cp_gaia_maestro_gateways` – manage Maestro Gateways over Web Services API.
152+
* `cp_gaia_maestro_gateways_facts` – get information about Maestro Gateways over Web Services API.
153+
* `cp_gaia_maestro_ports` – configure Maestro Orchestrator ports over Web Services API.
154+
* `cp_gaia_maestro_ports_facts` - get information about Maestro Orchestrator ports over Web Services API.
155+
* `cp_gaia_maestro_security_groups` - manage Maestro Security Groups over Web Services API.
156+
* `cp_gaia_maestro_security_groups_facts` - get information about Maestro Security Groups over Web Services API.
157+
* `cp_gaia_maestro_sites` - add description to Maestro Sites over Web Services API.
158+
* `cp_gaia_maestro_sites_facts` - get information about Maestro Sites over Web Services API.
151159

152160
### Code of Conduct
153161
This collection follows the Ansible project's

galaxy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace: check_point
99
name: gaia
1010

1111
# The version of the collection. Must be compatible with semantic versioning
12-
version: 6.0.1
12+
version: 7.0.0
1313

1414
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
1515
readme: README.md

plugins/module_utils/checkpoint.py

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
__metaclass__ = type
3232

3333
import time
34-
3534
from ansible.module_utils.connection import Connection
3635

3736
BEFORE_REQUEST = 1
@@ -200,6 +199,9 @@ def chkp_facts_api_call(module, api_call_object, is_multible):
200199
if "static-route" == api_call_object:
201200
if "address" in module_key_params and "mask_length" in module_key_params:
202201
show_single = True
202+
elif "maestro" in api_call_object:
203+
if "id" in module_key_params or "interface_name" in module_key_params or "site_id" in module_key_params:
204+
show_single = True
203205
else:
204206
if len(module_key_params) > 0:
205207
show_single = True
@@ -219,7 +221,7 @@ def chkp_facts_api_call(module, api_call_object, is_multible):
219221
}
220222

221223

222-
def chkp_api_call(module, api_call_object, has_add_api, ignore=None, show_params=None, add_params=None):
224+
def chkp_api_call(module, api_call_object, has_add_api, ignore=None, show_params=None, add_params=None, is_maestro_special=False):
223225
target_version = get_version(module)
224226
changed = False
225227
if show_params is None:
@@ -229,46 +231,56 @@ def chkp_api_call(module, api_call_object, has_add_api, ignore=None, show_params
229231
modules_params_original = module.params
230232
module_params_show = dict((k, v) for k, v in module.params.items() if k in show_params and v is not None)
231233
module.params = module_params_show
232-
code, res = api_call(module, target_version, api_call_object="show-{0}".format(api_call_object))
233-
before = res.copy()
234-
[before.pop(key, None) for key in ignore]
234+
if not is_maestro_special:
235+
code, res = api_call(module, target_version, api_call_object="show-{0}".format(api_call_object))
236+
before = res.copy()
237+
[before.pop(key, None) for key in ignore]
238+
else:
239+
code, res = api_call(module, target_version, api_call_object="show-maestro-security-groups")
240+
before = res.copy()
235241

236242
# Run the command:
237243
module.params = modules_params_original
238244
if 'state' in module.params and module.params['state'] == 'absent': # handle delete
239-
if code == 200:
240-
# delete/show require same params
241-
module.params = module_params_show
242-
code, res = api_call(module, target_version, api_call_object="delete-{0}".format(api_call_object))
245+
if is_maestro_special:
246+
code, res = api_call(module, target_version, api_call_object="discard-{0}".format(api_call_object))
243247
else:
244-
return {
245-
api_call_object.replace('-', '_'): {},
246-
"changed": False
247-
}
248-
else: # handle set/add
249-
params_dict = module.params.copy()
250-
for key, value in module.params.items():
251-
if not is_checkpoint_param(key):
252-
del params_dict[key]
253-
254-
if code == 200:
255-
if idempotency_check(res, params_dict) is True:
248+
if code == 200:
249+
# delete/show require same params
250+
module.params = module_params_show
251+
code, res = api_call(module, target_version, api_call_object="delete-{0}".format(api_call_object))
252+
else:
256253
return {
257-
api_call_object.replace('-', '_'): res,
254+
api_call_object.replace('-', '_'): {},
258255
"changed": False
259256
}
260-
code, res = api_call(module, target_version, api_call_object="set-{0}".format(api_call_object))
257+
else: # handle set/add
258+
if is_maestro_special:
259+
code, res = api_call(module, target_version, api_call_object="apply-{0}".format(api_call_object))
261260
else:
262-
if has_add_api is True:
263-
if add_params:
264-
[module.params.pop(key) for key in show_params if key not in add_params]
265-
module.params.update(add_params)
266-
if 'loopback-interface' == api_call_object: # loopback doesn't take 'name' for add-... api
267-
if 'name' in module.params:
268-
module.params.pop("name")
269-
code, res = api_call(module, target_version, api_call_object="add-{0}".format(api_call_object))
270-
else: # some requests like static-route don't have add, try set instead
261+
params_dict = module.params.copy()
262+
for key, value in module.params.items():
263+
if not is_checkpoint_param(key):
264+
del params_dict[key]
265+
266+
if code == 200:
267+
if idempotency_check(res, params_dict) is True:
268+
return {
269+
api_call_object.replace('-', '_'): res,
270+
"changed": False
271+
}
271272
code, res = api_call(module, target_version, api_call_object="set-{0}".format(api_call_object))
273+
else:
274+
if has_add_api is True:
275+
if add_params:
276+
[module.params.pop(key) for key in show_params if key not in add_params]
277+
module.params.update(add_params)
278+
if 'loopback-interface' == api_call_object: # loopback doesn't take 'name' for add-... api
279+
if 'name' in module.params:
280+
module.params.pop("name")
281+
code, res = api_call(module, target_version, api_call_object="add-{0}".format(api_call_object))
282+
else: # some requests like static-route don't have add, try set instead
283+
code, res = api_call(module, target_version, api_call_object="set-{0}".format(api_call_object))
272284

273285
if code == 200:
274286
if 'wait_for_task' in module.params and module.params['wait_for_task'] is True:
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
DOCUMENTATION = '''
25+
---
26+
author: Roi Tal (@chkp-roital)
27+
description: Handle pending changes, either apply or delete them.
28+
module: cp_gaia_maestro_changes
29+
short_description: Handle pending changes, either apply or delete them.
30+
version_added: '7.0.0'
31+
requirements: ['supported starting from gaia_api >= 1.8']
32+
options:
33+
version:
34+
description: Gaia API version for example 1.6.
35+
required: False
36+
type: str
37+
state:
38+
description: Ansible state which can be C(present) or C(absent). absent will delete the pending changes, present will apply them
39+
required: False
40+
type: str
41+
default: present
42+
choices: [present, absent]
43+
notes:
44+
- Supports C(check_mode).
45+
'''
46+
47+
EXAMPLES = """
48+
- name: Delete pending changes
49+
check_point.gaia.cp_gaia_user:
50+
state: absent
51+
52+
"""
53+
54+
RETURN = """
55+
56+
"""
57+
58+
from ansible.module_utils.basic import AnsibleModule
59+
from ansible_collections.check_point.gaia.plugins.module_utils.checkpoint import chkp_api_call, checkpoint_argument_spec_for_all
60+
61+
62+
def main():
63+
# arguments for the module:
64+
fields = dict(
65+
state=dict(type='str', default='present', choices=['present', 'absent'])
66+
)
67+
fields.update(checkpoint_argument_spec_for_all)
68+
module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
69+
api_call_object = "maestro-security-groups-changes"
70+
71+
res = chkp_api_call(module, api_call_object, False, is_maestro_special=True)
72+
module.exit_json(**res)
73+
74+
75+
if __name__ == "__main__":
76+
main()
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
DOCUMENTATION = '''
25+
---
26+
author: Roi Tal (@chkp-roital)
27+
description: Assign, re-assign or un-assign Gateways to Security Groups, and change GW descriptions.
28+
module: cp_gaia_maestro_gateways
29+
short_description: Modify Security Group Members.
30+
version_added: '7.0.0'
31+
requirements: ['supported starting from gaia_api >= 1.8']
32+
options:
33+
version:
34+
description: Gaia API version for example 1.6.
35+
required: False
36+
type: str
37+
id:
38+
description: The serial of the Gateway you wish to modify
39+
required: True
40+
type: str
41+
security_group:
42+
description: Choose ID of Security Group to assign this Gateway to
43+
required: False
44+
type: int
45+
description:
46+
description: Description of this Gateway
47+
required: False
48+
type: str
49+
50+
notes:
51+
- Supports C(check_mode).
52+
'''
53+
54+
EXAMPLES = """
55+
- name: Assign GW to SG and add description
56+
check_point.gaia.cp_gaia_gateways:
57+
id: 1007RT1992
58+
security_group: 1
59+
description: "1007RT1992 GW Description"
60+
61+
"""
62+
63+
RETURN = """
64+
maestro_gateway:
65+
description: The updated Maestro Gateway details.
66+
returned: always.
67+
type: dict
68+
"""
69+
70+
71+
from ansible.module_utils.basic import AnsibleModule
72+
from ansible_collections.check_point.gaia.plugins.module_utils.checkpoint import chkp_api_call, checkpoint_argument_spec_for_all
73+
74+
def main():
75+
# arguments for the module:
76+
fields = dict(
77+
id=dict(type='str', required=True),
78+
security_group=dict(type="int"),
79+
description=dict(type="str")
80+
)
81+
fields.update(checkpoint_argument_spec_for_all)
82+
module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
83+
api_call_object = 'maestro-gateway'
84+
show_params = ["id"]
85+
res = chkp_api_call(module, api_call_object, False, show_params=show_params)
86+
module.exit_json(**res)
87+
88+
if __name__ == "__main__":
89+
main()

0 commit comments

Comments
 (0)