From 60741184741db24da43fbb5846ab35eb6b00a370 Mon Sep 17 00:00:00 2001 From: Michal Zegan Date: Thu, 22 Aug 2019 14:59:55 +0200 Subject: Add floating ip fact retrieval module This change adds the ansible module that retrieves facts about floating ips, that is missing from the ansible core modules. This module is used to translate floating ips into their resource identifiers before using heat template. Change-Id: I7a8756eff30b33f82dade2f35227ff241a8c5972 Issue-ID: OOM-2042 Signed-off-by: Michal Zegan --- tools/cicdansible/library/os_floating_ips_facts.py | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tools/cicdansible/library/os_floating_ips_facts.py diff --git a/tools/cicdansible/library/os_floating_ips_facts.py b/tools/cicdansible/library/os_floating_ips_facts.py new file mode 100644 index 00000000..ad546004 --- /dev/null +++ b/tools/cicdansible/library/os_floating_ips_facts.py @@ -0,0 +1,61 @@ +#!/usr/bin/python +ANSIBLE_METADATA = { + 'METADATA_VERSION': '1.1', + 'supported_by': 'community', + 'status': 'preview' +} + +DOCUMENTATION = ''' +--- +module: "os_floating_ips_facts" +short_description: "Retrieves facts about floating ips" +description: + - "This module retrieves facts about one or more floating ips allocated to project." +version_added: "2.7" +author: + - "Michal Zegan" +requirements: + - "python => 2.7" + - "openstacksdk" +options: + floating_ip: + description: + - "The floating ip to retrieve facts for" + type: "str" + network: + description: + - "Name or id of the floating ip network to query." + required: true + type: "str" +notes: + - "Registers facts starting with openstack_floating_ips" +extends_documentation_fragment: openstack +''' + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module + +def run_module(): + args=openstack_module_kwargs() + argspec=openstack_full_argument_spec( + floating_ip=dict(type=str), + network=dict(type=str, required=True)) + module=AnsibleModule(argument_spec=argspec, **args) + sdk, cloud = openstack_cloud_from_module(module) + try: + fip_network=cloud.network.find_network(module.params['network']) + filter=dict( + project_id=cloud.current_project_id, + floating_network_id=fip_network.id) + if not (module.params['floating_ip'] is None): + filter['floating_ip_address'] = module.params['floating_ip'] + ips=[dict(x) for x in cloud.network.ips(**filter)] + module.exit_json( + changed=False, + ansible_facts=dict(openstack_floating_ips=ips) + ) + except sdk.exceptions.OpenStackCloudException as e: + module.fail_json(msg=str(e)) + +if __name__ == '__main__': + run_module() -- cgit 1.2.3-korg