Skip to content

Commit 17229b3

Browse files
authored
Merge pull request #35 from duanetoler/loopback_interface
Add loopback interface modules and modify checkpoint.py to support special loopback interface params
2 parents 315ed9b + 82c200f commit 17229b3

File tree

3 files changed

+290
-0
lines changed

3 files changed

+290
-0
lines changed

plugins/module_utils/checkpoint.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ def chkp_api_call(module, api_call_object, has_add_api, ignore=None, show_params
259259
if add_params:
260260
[module.params.pop(key) for key in show_params if key not in add_params]
261261
module.params.update(add_params)
262+
if 'loopback-interface' == api_call_object: # loopback doesn't take 'name' for add-... api
263+
if 'name' in module.params:
264+
module.params.pop("name")
262265
code, res = api_call(module, target_version, api_call_object="add-{0}".format(api_call_object))
263266
else: # some requests like static-route don't have add, try set instead
264267
code, res = api_call(module, target_version, api_call_object="set-{0}".format(api_call_object))
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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+
module: cp_gaia_loopback_interface
26+
author: Duane Toler (@duanetoler)
27+
description:
28+
- Modify loopback interface.
29+
short_description: Modify loopback interface.
30+
version_added: '5.0.x'
31+
notes:
32+
- Supports C(check_mode).
33+
options:
34+
version:
35+
description: Gaia API version for example 1.6.
36+
required: false
37+
type: str
38+
state:
39+
description: Ansible state which can be C(present) or C(absent).
40+
required: false
41+
type: str
42+
default: present
43+
choices: [present, absent]
44+
name:
45+
description:
46+
- Interface name with format C(loop<id>), for example "loop00", "loop01"
47+
- Not required when adding new loopback interface
48+
- Newly-created loopback interface name returned in dict details
49+
required: false
50+
type: str
51+
ipv4_address:
52+
description: Interface IPv4 address.
53+
required: false
54+
type: str
55+
ipv4_mask_length:
56+
description: Interface IPv4 address mask length.
57+
required: false
58+
type: int
59+
ipv6_address:
60+
description: Interface IPv6 address.
61+
required: false
62+
type: str
63+
ipv6_autoconfig:
64+
description: Configure IPv6 auto-configuration.
65+
required: false
66+
type: bool
67+
ipv6_mask_length:
68+
description: Interface IPv6 address mask length.
69+
required: false
70+
type: int
71+
comments:
72+
description: Interface Comments.
73+
required: false
74+
type: str
75+
enabled:
76+
description: Interface State.
77+
required: false
78+
type: bool
79+
"""
80+
81+
EXAMPLES = """
82+
- name: Set comment field of a loopback interface
83+
check_point.gaia.cp_gaia_loopback_interface:
84+
comments: "loop01 interface"
85+
name: loop01
86+
87+
"""
88+
89+
RETURN = """
90+
loopback_interface:
91+
description: The updated interface details.
92+
returned: always.
93+
type: dict
94+
"""
95+
96+
from ansible.module_utils.basic import AnsibleModule
97+
from ansible_collections.check_point.gaia.plugins.module_utils.checkpoint import chkp_api_call, checkpoint_argument_spec_for_all
98+
99+
100+
def main():
101+
# arguments for the module:
102+
fields = dict(
103+
state=dict(type='str', default='present', choices=['present', 'absent']),
104+
name=dict(type='str'),
105+
enabled=dict(type='bool'),
106+
comments=dict(type='str'),
107+
ipv4_address=dict(type='str'),
108+
ipv4_mask_length=dict(type='int'),
109+
ipv6_address=dict(type='str'),
110+
ipv6_autoconfig=dict(type='bool'),
111+
ipv6_mask_length=dict(type='int')
112+
)
113+
fields.update(checkpoint_argument_spec_for_all)
114+
module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
115+
api_call_object = 'loopback-interface'
116+
ignore = ['status']
117+
show_params = ['name']
118+
add_params = {}
119+
120+
res = chkp_api_call(module, api_call_object, True, ignore=ignore, show_params=show_params, add_params=add_params)
121+
module.exit_json(**res)
122+
123+
124+
if __name__ == "__main__":
125+
main()
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
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+
module: cp_gaia_loopback_interface_facts
26+
author: Duane Toler (@duanetoler)
27+
description:
28+
- Show loopback interface.
29+
short_description: Show loopback interface/s.
30+
version_added: '5.0.x'
31+
notes:
32+
- Supports C(check_mode).
33+
options:
34+
version:
35+
description: Gaia API version for example 1.6.
36+
required: False
37+
type: str
38+
name:
39+
description: Interface name to show. If not specified, all loopback interfaces information is returned.
40+
required: false
41+
type: str
42+
43+
"""
44+
45+
EXAMPLES = """
46+
- name: Show loopback interface
47+
check_point.gaia.cp_gaia_loopback_interface_facts:
48+
49+
- name: Show loopback interface by specifying it's name
50+
check_point.gaia.cp_gaia_loopback_interface_facts:
51+
name: loop01
52+
53+
"""
54+
55+
RETURN = """
56+
ansible_facts:
57+
description: The interface/s facts.
58+
returned: always.
59+
type: dict
60+
contains:
61+
objects:
62+
description:
63+
- List of interfaces.
64+
returned: always
65+
type: list
66+
elements: dict
67+
contains:
68+
name:
69+
description:
70+
- Interface name.
71+
returned: always
72+
type: str
73+
ipv4_address:
74+
description: Interface IPv4 address.
75+
returned: always
76+
type: str
77+
ipv4_mask_length:
78+
description: Interface IPv4 address mask length.
79+
returned: always
80+
type: int
81+
ipv6_address:
82+
description: Interface IPv6 address.
83+
returned: always
84+
type: str
85+
ipv6_autoconfig:
86+
description: Configure IPv6 auto-configuration.
87+
returned: always
88+
type: bool
89+
ipv6_mask_length:
90+
description: Interface IPv6 address mask length.
91+
returned: always
92+
type: int
93+
comments:
94+
description: Interface Comments.
95+
returned: always
96+
type: str
97+
enabled:
98+
description: Interface State.
99+
returned: always
100+
type: bool
101+
mtu:
102+
description: Interface mtu.
103+
returned: always
104+
type: int
105+
ipv6_local_link_address:
106+
description: Interface ipv6 local link address.
107+
returned: always
108+
type: str
109+
status:
110+
description: Interface data.
111+
returned: always
112+
type: dict
113+
contains:
114+
link_state:
115+
description: Link status.
116+
returned: always
117+
type: bool
118+
speed:
119+
description: Speed.
120+
returned: always
121+
type: str
122+
duplex:
123+
description: Duplex.
124+
returned: always
125+
type: str
126+
tx_bytes:
127+
description: TX bytes.
128+
returned: always
129+
type: int
130+
tx_packets:
131+
description: TX packets.
132+
returned: always
133+
type: int
134+
rx_bytes:
135+
description: RX bytes.
136+
returned: always
137+
type: int
138+
rx_packets:
139+
description: RX packets.
140+
returned: always
141+
type: int
142+
"""
143+
144+
from ansible.module_utils.basic import AnsibleModule
145+
from ansible_collections.check_point.gaia.plugins.module_utils.checkpoint import chkp_facts_api_call, checkpoint_argument_spec_for_all
146+
147+
148+
def main():
149+
# arguments for the module:
150+
fields = dict(
151+
name=dict(required=False, type='str')
152+
)
153+
fields.update(checkpoint_argument_spec_for_all)
154+
module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
155+
api_call_object = "loopback-interface"
156+
157+
res = chkp_facts_api_call(module, api_call_object, True)
158+
module.exit_json(ansible_facts=res["ansible_facts"])
159+
160+
161+
if __name__ == "__main__":
162+
main()

0 commit comments

Comments
 (0)