Skip to content

Commit c81ef68

Browse files
committed
checkpoint older modules
1 parent 890a15b commit c81ef68

File tree

3 files changed

+340
-0
lines changed

3 files changed

+340
-0
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/usr/bin/python
2+
#
3+
# This file is part of Ansible
4+
#
5+
# Ansible is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# Ansible is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
17+
#
18+
19+
from __future__ import absolute_import, division, print_function
20+
21+
__metaclass__ = type
22+
23+
24+
ANSIBLE_METADATA = {
25+
"metadata_version": "1.1",
26+
"status": ["preview"],
27+
"supported_by": "network",
28+
}
29+
30+
31+
DOCUMENTATION = """module: checkpoint_run_script
32+
short_description: Run scripts on Check Point devices over Web Services API
33+
description:
34+
- Run scripts on Check Point devices. All operations are performed over Web Services
35+
API.
36+
version_added: "2.7"
37+
author: Ansible by Red Hat (@rcarrillocruz)
38+
options:
39+
script_name:
40+
description:
41+
- Name of the script.
42+
type: str
43+
required: true
44+
script:
45+
description:
46+
- Script body contents.
47+
type: str
48+
required: true
49+
targets:
50+
description:
51+
- Targets the script should be run against. Can reference either name or UID.
52+
type: list
53+
required: true
54+
"""
55+
56+
EXAMPLES = """
57+
- name: Run script
58+
checkpoint_run_script:
59+
script_name: "List root"
60+
script: ls -l /
61+
targets:
62+
- mycheckpointgw
63+
"""
64+
65+
RETURN = """
66+
checkpoint_run_script:
67+
description: The checkpoint run script output.
68+
returned: always.
69+
type: list
70+
"""
71+
72+
73+
from ansible.module_utils.basic import AnsibleModule
74+
from ansible.module_utils.connection import Connection
75+
76+
77+
def run_script(module, connection):
78+
script_name = module.params["script_name"]
79+
script = module.params["script"]
80+
targets = module.params["targets"]
81+
82+
payload = {
83+
"script-name": script_name,
84+
"script": script,
85+
"targets": targets,
86+
}
87+
88+
code, response = connection.send_request("/web_api/run-script", payload)
89+
90+
return code, response
91+
92+
93+
def main():
94+
argument_spec = dict(
95+
script_name=dict(type="str", required=True),
96+
script=dict(type="str", required=True),
97+
targets=dict(type="list", required=True),
98+
)
99+
100+
module = AnsibleModule(argument_spec=argument_spec)
101+
connection = Connection(module._socket_path)
102+
code, response = run_script(module, connection)
103+
result = {"changed": True}
104+
105+
if code == 200:
106+
result["checkpoint_run_script"] = response
107+
else:
108+
module.fail_json(
109+
msg="Checkpoint device returned error {0} with message {1}".format(
110+
code, response
111+
)
112+
)
113+
114+
module.exit_json(**result)
115+
116+
117+
if __name__ == "__main__":
118+
main()
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#!/usr/bin/python
2+
#
3+
# This file is part of Ansible
4+
#
5+
# Ansible is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# Ansible is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
17+
#
18+
19+
from __future__ import absolute_import, division, print_function
20+
21+
__metaclass__ = type
22+
23+
24+
ANSIBLE_METADATA = {
25+
"metadata_version": "1.1",
26+
"status": ["preview"],
27+
"supported_by": "network",
28+
}
29+
30+
31+
DOCUMENTATION = """module: checkpoint_session
32+
short_description: Manages session objects on Check Point over Web Services API
33+
description:
34+
- Manages session objects on Check Point devices performing actions like publish and
35+
discard. All operations are performed over Web Services API.
36+
version_added: "2.7"
37+
author: Ansible by Red Hat (@rcarrillocruz)
38+
options:
39+
uid:
40+
description:
41+
- UID of the session.
42+
type: str
43+
required: true
44+
state:
45+
description:
46+
- Action to perform on the session object. Valid choices are published and discarded.
47+
type: str
48+
choices:
49+
- published
50+
- discarded
51+
default: published
52+
"""
53+
54+
EXAMPLES = """
55+
- name: Publish session
56+
checkpoint_session:
57+
uid: 7a13a360-9b24-40d7-acd3-5b50247be33e
58+
state: published
59+
60+
- name: Discard session
61+
checkpoint_session:
62+
uid: 7a13a360-9b24-40d7-acd3-5b50247be33e
63+
state: discarded
64+
"""
65+
66+
RETURN = """
67+
checkpoint_session:
68+
description: The checkpoint session output per return from API. It will differ depending on action.
69+
returned: always.
70+
type: list
71+
"""
72+
73+
74+
from ansible.module_utils.basic import AnsibleModule
75+
from ansible.module_utils.connection import Connection
76+
77+
78+
def get_session(module, connection):
79+
payload = {"uid": module.params["uid"]}
80+
81+
code, result = connection.send_request("/web_api/show-session", payload)
82+
83+
return code, result
84+
85+
86+
def main():
87+
argument_spec = dict(
88+
uid=dict(type="str", default=None),
89+
state=dict(
90+
type="str", default="published", choices=["published", "discarded"]
91+
),
92+
)
93+
94+
module = AnsibleModule(argument_spec=argument_spec)
95+
connection = Connection(module._socket_path)
96+
code, response = get_session(module, connection)
97+
result = {"changed": False}
98+
99+
if code == 200:
100+
result["changed"] = True
101+
payload = None
102+
103+
if module.params["uid"]:
104+
payload = {"uid": module.params["uid"]}
105+
106+
if module.params["state"] == "published":
107+
code, response = connection.send_request(
108+
"/web_api/publish", payload
109+
)
110+
else:
111+
code, response = connection.send_request(
112+
"/web_api/discard", payload
113+
)
114+
if code != 200:
115+
module.fail_json(msg=response)
116+
result["checkpoint_session"] = response
117+
else:
118+
module.fail_json(
119+
msg="Check Point device returned error {0} with message {1}".format(
120+
code, response
121+
)
122+
)
123+
124+
module.exit_json(**result)
125+
126+
127+
if __name__ == "__main__":
128+
main()
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/python
2+
#
3+
# This file is part of Ansible
4+
#
5+
# Ansible is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# Ansible is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
17+
#
18+
19+
20+
from __future__ import absolute_import, division, print_function
21+
22+
__metaclass__ = type
23+
24+
25+
ANSIBLE_METADATA = {
26+
"metadata_version": "1.1",
27+
"status": ["preview"],
28+
"supported_by": "network",
29+
}
30+
31+
32+
DOCUMENTATION = """module: checkpoint_task_facts
33+
short_description: Get task objects facts on Check Point over Web Services API
34+
description:
35+
- Get task objects facts on Check Point devices. All operations are performed over
36+
Web Services API.
37+
version_added: "2.7"
38+
author: Ansible by Red Hat (@rcarrillocruz)
39+
options:
40+
task_id:
41+
description:
42+
- ID of the task object.
43+
type: str
44+
required: true
45+
"""
46+
47+
EXAMPLES = """
48+
- name: Get task facts
49+
checkpoint_task_facts:
50+
task_id: 2eec70e5-78a8-4bdb-9a76-cfb5601d0bcb
51+
"""
52+
53+
RETURN = """
54+
ansible_facts:
55+
description: The checkpoint task facts.
56+
returned: always.
57+
type: list
58+
"""
59+
60+
from ansible.module_utils.basic import AnsibleModule
61+
from ansible.module_utils.connection import Connection
62+
63+
64+
def get_task(module, connection):
65+
task_id = module.params["task_id"]
66+
67+
if task_id:
68+
payload = {"task-id": task_id, "details-level": "full"}
69+
70+
code, response = connection.send_request("/web_api/show-task", payload)
71+
else:
72+
code, response = connection.send_request("/web_api/show-tasks", None)
73+
74+
return code, response
75+
76+
77+
def main():
78+
argument_spec = dict(task_id=dict(type="str"))
79+
80+
module = AnsibleModule(argument_spec=argument_spec)
81+
connection = Connection(module._socket_path)
82+
code, response = get_task(module, connection)
83+
if code == 200:
84+
module.exit_json(ansible_facts=dict(checkpoint_tasks=response))
85+
else:
86+
module.fail_json(
87+
msg="Checkpoint device returned error {0} with message {1}".format(
88+
code, response
89+
)
90+
)
91+
92+
93+
if __name__ == "__main__":
94+
main()

0 commit comments

Comments
 (0)