summaryrefslogtreecommitdiffstats
path: root/tools/cicdansible
diff options
context:
space:
mode:
authorMichal Zegan <m.zegan@samsung.com>2019-08-22 14:59:55 +0200
committerMichal Zegan <m.zegan@samsung.com>2019-09-04 11:24:52 +0200
commit60741184741db24da43fbb5846ab35eb6b00a370 (patch)
tree4b517110dfe7b5328c44498855eede448f0aaf4f /tools/cicdansible
parent3bf88a80668ce410b423e25a259bf4d59fd05417 (diff)
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 <m.zegan@samsung.com>
Diffstat (limited to 'tools/cicdansible')
-rw-r--r--tools/cicdansible/library/os_floating_ips_facts.py61
1 files changed, 61 insertions, 0 deletions
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()