diff options
author | Michal Ptacek <m.ptacek@partner.samsung.com> | 2019-09-04 15:39:20 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-09-04 15:39:20 +0000 |
commit | 1da8b7af533aa48450d42219f0615d0bb510da4a (patch) | |
tree | 827fc4fa9da8d685d6d7960978ce99680e8f7d31 /tools/cicdansible/library/os_floating_ips_facts.py | |
parent | 8620b2be770895ffca1385f3a8a57b9422ecf126 (diff) | |
parent | 2e34522351d40edd0e37b4919630736748949f2a (diff) |
Merge changes from topic "OOM-2042"
* changes:
Add ansible configuration file
Add cicdansible playbook
Add onap installation role
Add onap instance configuration role
Add ansible role to deploy onap infrastructure on openstack
Add floating ip fact retrieval module
Add inventory for cicdansible playbook
Add heat template to deploy onap infrastructure
Add the .gitignore for cicdansible
Diffstat (limited to 'tools/cicdansible/library/os_floating_ips_facts.py')
-rw-r--r-- | tools/cicdansible/library/os_floating_ips_facts.py | 61 |
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() |