|
| 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": ["deprecated"], |
| 28 | + "supported_by": "network", |
| 29 | +} |
| 30 | + |
| 31 | + |
| 32 | +DOCUMENTATION = """module: checkpoint_access_layer_facts |
| 33 | +short_description: Get access layer facts on Check Point over Web Services API |
| 34 | +description: |
| 35 | +- Get access layer facts on Check Point devices. All operations are performed over |
| 36 | + Web Services API. |
| 37 | +deprecated: |
| 38 | + removed_in: '2.13' |
| 39 | + alternative: cp_mgmt_access_layer_facts |
| 40 | + why: Newer and updated modules released in Ansible 2.9 |
| 41 | +author: Ansible by Red Hat (@rcarrillocruz) |
| 42 | +options: |
| 43 | + uid: |
| 44 | + description: |
| 45 | + - UID of access layer object. |
| 46 | + type: str |
| 47 | + name: |
| 48 | + description: |
| 49 | + - Name of the access layer object. |
| 50 | + type: str |
| 51 | +""" |
| 52 | + |
| 53 | +EXAMPLES = """ |
| 54 | +- name: Get object facts |
| 55 | + checkpoint_access_layer_facts: |
| 56 | +""" |
| 57 | + |
| 58 | +RETURN = """ |
| 59 | +ansible_facts: |
| 60 | + description: The checkpoint access layer facts. |
| 61 | + returned: always. |
| 62 | + type: list |
| 63 | +""" |
| 64 | + |
| 65 | + |
| 66 | +from ansible.module_utils.basic import AnsibleModule |
| 67 | +from ansible.module_utils.connection import Connection |
| 68 | + |
| 69 | + |
| 70 | +def get_access_layer(module, connection): |
| 71 | + uid = module.params["uid"] |
| 72 | + name = module.params["name"] |
| 73 | + |
| 74 | + payload = {} |
| 75 | + |
| 76 | + if uid: |
| 77 | + payload = {"uid": uid} |
| 78 | + code, result = connection.send_request( |
| 79 | + "/web_api/show-access-layer", payload |
| 80 | + ) |
| 81 | + elif name: |
| 82 | + payload = {"name": name} |
| 83 | + code, result = connection.send_request( |
| 84 | + "/web_api/show-access-layer", payload |
| 85 | + ) |
| 86 | + else: |
| 87 | + code, result = connection.send_request( |
| 88 | + "/web_api/show-access-layers", payload |
| 89 | + ) |
| 90 | + |
| 91 | + return code, result |
| 92 | + |
| 93 | + |
| 94 | +def main(): |
| 95 | + argument_spec = dict( |
| 96 | + uid=dict(type="str", default=None), name=dict(type="str", default=None) |
| 97 | + ) |
| 98 | + |
| 99 | + module = AnsibleModule(argument_spec=argument_spec) |
| 100 | + connection = Connection(module._socket_path) |
| 101 | + |
| 102 | + code, response = get_access_layer(module, connection) |
| 103 | + |
| 104 | + if code == 200: |
| 105 | + module.exit_json(ansible_facts=dict(checkpoint_access_layers=response)) |
| 106 | + else: |
| 107 | + module.fail_json( |
| 108 | + msg="Check Point device returned error {0} with message {1}".format( |
| 109 | + code, response |
| 110 | + ) |
| 111 | + ) |
| 112 | + |
| 113 | + |
| 114 | +if __name__ == "__main__": |
| 115 | + main() |
0 commit comments