Skip to content

Commit

Permalink
Merge pull request #35 from duanetoler/loopback_interface
Browse files Browse the repository at this point in the history
Add loopback interface modules and modify checkpoint.py to support special loopback interface params
  • Loading branch information
chkp-majds authored Jan 1, 2025
2 parents 315ed9b + 82c200f commit 17229b3
Show file tree
Hide file tree
Showing 3 changed files with 290 additions and 0 deletions.
3 changes: 3 additions & 0 deletions plugins/module_utils/checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ def chkp_api_call(module, api_call_object, has_add_api, ignore=None, show_params
if add_params:
[module.params.pop(key) for key in show_params if key not in add_params]
module.params.update(add_params)
if 'loopback-interface' == api_call_object: # loopback doesn't take 'name' for add-... api
if 'name' in module.params:
module.params.pop("name")
code, res = api_call(module, target_version, api_call_object="add-{0}".format(api_call_object))
else: # some requests like static-route don't have add, try set instead
code, res = api_call(module, target_version, api_call_object="set-{0}".format(api_call_object))
Expand Down
125 changes: 125 additions & 0 deletions plugins/modules/cp_gaia_loopback_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Ansible module to manage CheckPoint Firewall (c) 2019
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#

from __future__ import (absolute_import, division, print_function)

__metaclass__ = type

DOCUMENTATION = """
module: cp_gaia_loopback_interface
author: Duane Toler (@duanetoler)
description:
- Modify loopback interface.
short_description: Modify loopback interface.
version_added: '5.0.x'
notes:
- Supports C(check_mode).
options:
version:
description: Gaia API version for example 1.6.
required: false
type: str
state:
description: Ansible state which can be C(present) or C(absent).
required: false
type: str
default: present
choices: [present, absent]
name:
description:
- Interface name with format C(loop<id>), for example "loop00", "loop01"
- Not required when adding new loopback interface
- Newly-created loopback interface name returned in dict details
required: false
type: str
ipv4_address:
description: Interface IPv4 address.
required: false
type: str
ipv4_mask_length:
description: Interface IPv4 address mask length.
required: false
type: int
ipv6_address:
description: Interface IPv6 address.
required: false
type: str
ipv6_autoconfig:
description: Configure IPv6 auto-configuration.
required: false
type: bool
ipv6_mask_length:
description: Interface IPv6 address mask length.
required: false
type: int
comments:
description: Interface Comments.
required: false
type: str
enabled:
description: Interface State.
required: false
type: bool
"""

EXAMPLES = """
- name: Set comment field of a loopback interface
check_point.gaia.cp_gaia_loopback_interface:
comments: "loop01 interface"
name: loop01
"""

RETURN = """
loopback_interface:
description: The updated interface details.
returned: always.
type: dict
"""

from ansible.module_utils.basic import AnsibleModule
from ansible_collections.check_point.gaia.plugins.module_utils.checkpoint import chkp_api_call, checkpoint_argument_spec_for_all


def main():
# arguments for the module:
fields = dict(
state=dict(type='str', default='present', choices=['present', 'absent']),
name=dict(type='str'),
enabled=dict(type='bool'),
comments=dict(type='str'),
ipv4_address=dict(type='str'),
ipv4_mask_length=dict(type='int'),
ipv6_address=dict(type='str'),
ipv6_autoconfig=dict(type='bool'),
ipv6_mask_length=dict(type='int')
)
fields.update(checkpoint_argument_spec_for_all)
module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
api_call_object = 'loopback-interface'
ignore = ['status']
show_params = ['name']
add_params = {}

res = chkp_api_call(module, api_call_object, True, ignore=ignore, show_params=show_params, add_params=add_params)
module.exit_json(**res)


if __name__ == "__main__":
main()
162 changes: 162 additions & 0 deletions plugins/modules/cp_gaia_loopback_interface_facts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Ansible module to manage CheckPoint Firewall (c) 2019
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#

from __future__ import (absolute_import, division, print_function)

__metaclass__ = type

DOCUMENTATION = """
module: cp_gaia_loopback_interface_facts
author: Duane Toler (@duanetoler)
description:
- Show loopback interface.
short_description: Show loopback interface/s.
version_added: '5.0.x'
notes:
- Supports C(check_mode).
options:
version:
description: Gaia API version for example 1.6.
required: False
type: str
name:
description: Interface name to show. If not specified, all loopback interfaces information is returned.
required: false
type: str
"""

EXAMPLES = """
- name: Show loopback interface
check_point.gaia.cp_gaia_loopback_interface_facts:
- name: Show loopback interface by specifying it's name
check_point.gaia.cp_gaia_loopback_interface_facts:
name: loop01
"""

RETURN = """
ansible_facts:
description: The interface/s facts.
returned: always.
type: dict
contains:
objects:
description:
- List of interfaces.
returned: always
type: list
elements: dict
contains:
name:
description:
- Interface name.
returned: always
type: str
ipv4_address:
description: Interface IPv4 address.
returned: always
type: str
ipv4_mask_length:
description: Interface IPv4 address mask length.
returned: always
type: int
ipv6_address:
description: Interface IPv6 address.
returned: always
type: str
ipv6_autoconfig:
description: Configure IPv6 auto-configuration.
returned: always
type: bool
ipv6_mask_length:
description: Interface IPv6 address mask length.
returned: always
type: int
comments:
description: Interface Comments.
returned: always
type: str
enabled:
description: Interface State.
returned: always
type: bool
mtu:
description: Interface mtu.
returned: always
type: int
ipv6_local_link_address:
description: Interface ipv6 local link address.
returned: always
type: str
status:
description: Interface data.
returned: always
type: dict
contains:
link_state:
description: Link status.
returned: always
type: bool
speed:
description: Speed.
returned: always
type: str
duplex:
description: Duplex.
returned: always
type: str
tx_bytes:
description: TX bytes.
returned: always
type: int
tx_packets:
description: TX packets.
returned: always
type: int
rx_bytes:
description: RX bytes.
returned: always
type: int
rx_packets:
description: RX packets.
returned: always
type: int
"""

from ansible.module_utils.basic import AnsibleModule
from ansible_collections.check_point.gaia.plugins.module_utils.checkpoint import chkp_facts_api_call, checkpoint_argument_spec_for_all


def main():
# arguments for the module:
fields = dict(
name=dict(required=False, type='str')
)
fields.update(checkpoint_argument_spec_for_all)
module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
api_call_object = "loopback-interface"

res = chkp_facts_api_call(module, api_call_object, True)
module.exit_json(ansible_facts=res["ansible_facts"])


if __name__ == "__main__":
main()

0 comments on commit 17229b3

Please sign in to comment.