|
|
@ -1,35 +1,27 @@
|
|
|
|
#!/usr/bin/python
|
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Copyright: (C) 2017-18, Ansible Project
|
|
|
|
# Copyright: Ansible Project
|
|
|
|
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ANSIBLE_METADATA = {'status': ['preview'],
|
|
|
|
ANSIBLE_METADATA = {
|
|
|
|
'supported_by': 'community',
|
|
|
|
'status': ['preview'],
|
|
|
|
'metadata_version': '1.1'}
|
|
|
|
'supported_by': 'community',
|
|
|
|
|
|
|
|
'metadata_version': '1.1'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DOCUMENTATION = '''
|
|
|
|
DOCUMENTATION = '''
|
|
|
|
---
|
|
|
|
---
|
|
|
|
module: digital_ocean_floating_ip_facts
|
|
|
|
module: digital_ocean_floating_ip_facts
|
|
|
|
short_description: DigitalOcean Floating IPs facts
|
|
|
|
short_description: DigitalOcean Floating IPs facts
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Fetch DigitalOcean Floating IPs facts.
|
|
|
|
- This module can be used to fetch DigitalOcean Floating IPs facts.
|
|
|
|
version_added: "2.5"
|
|
|
|
version_added: "2.5"
|
|
|
|
author: "Patrick Marques (@pmarques)"
|
|
|
|
author: "Patrick Marques (@pmarques)"
|
|
|
|
options:
|
|
|
|
extends_documentation_fragment: digital_ocean.documentation
|
|
|
|
oauth_token:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- DigitalOcean OAuth token.
|
|
|
|
|
|
|
|
required: true
|
|
|
|
|
|
|
|
timeout:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- The timeout in seconds used for polling DigitalOcean's API.
|
|
|
|
|
|
|
|
default: 30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
notes:
|
|
|
|
notes:
|
|
|
|
- Version 2 of DigitalOcean API is used.
|
|
|
|
- Version 2 of DigitalOcean API is used.
|
|
|
|
requirements:
|
|
|
|
requirements:
|
|
|
@ -84,12 +76,9 @@ floating_ips:
|
|
|
|
]
|
|
|
|
]
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from ansible.module_utils.basic import env_fallback
|
|
|
|
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
from ansible.module_utils.digital_ocean import DigitalOceanHelper
|
|
|
|
from ansible.module_utils.digital_ocean import DigitalOceanHelper
|
|
|
|
|
|
|
|
from ansible.module_utils._text import to_native
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def core(module):
|
|
|
|
def core(module):
|
|
|
@ -98,41 +87,34 @@ def core(module):
|
|
|
|
page = 1
|
|
|
|
page = 1
|
|
|
|
has_next = True
|
|
|
|
has_next = True
|
|
|
|
floating_ips = []
|
|
|
|
floating_ips = []
|
|
|
|
while has_next or 200 != status_code:
|
|
|
|
status_code = None
|
|
|
|
|
|
|
|
while has_next or status_code != 200:
|
|
|
|
response = rest.get("floating_ips?page={0}&per_page=20".format(page))
|
|
|
|
response = rest.get("floating_ips?page={0}&per_page=20".format(page))
|
|
|
|
status_code = response.status_code
|
|
|
|
status_code = response.status_code
|
|
|
|
# stop if any error during pagination
|
|
|
|
# stop if any error during pagination
|
|
|
|
if 200 != status_code:
|
|
|
|
if status_code != 200:
|
|
|
|
break
|
|
|
|
break
|
|
|
|
page = page + 1
|
|
|
|
page += 1
|
|
|
|
floating_ips.extend(response.json["floating_ips"])
|
|
|
|
floating_ips.extend(response.json["floating_ips"])
|
|
|
|
has_next = "pages" in response.json["links"] and "next" in response.json["links"]["pages"]
|
|
|
|
has_next = "pages" in response.json["links"] and "next" in response.json["links"]["pages"]
|
|
|
|
|
|
|
|
|
|
|
|
if status_code == 200:
|
|
|
|
if status_code == 200:
|
|
|
|
module.exit_json(changed=False, floating_ips=floating_ips)
|
|
|
|
module.exit_json(changed=False, floating_ips=floating_ips)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
module.fail_json(msg="Error fecthing facts [{0}: {1}]".format(
|
|
|
|
module.fail_json(msg="Error fetching facts [{0}: {1}]".format(
|
|
|
|
status_code, response.json["message"]))
|
|
|
|
status_code, response.json["message"]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
|
module = AnsibleModule(
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec=dict(
|
|
|
|
argument_spec=DigitalOceanHelper.digital_ocean_argument_spec()
|
|
|
|
oauth_token=dict(
|
|
|
|
|
|
|
|
no_log=True,
|
|
|
|
|
|
|
|
# Support environment variable for DigitalOcean OAuth Token
|
|
|
|
|
|
|
|
fallback=(env_fallback, ['DO_API_TOKEN', 'DO_API_KEY', 'DO_OAUTH_TOKEN']),
|
|
|
|
|
|
|
|
required=True,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
validate_certs=dict(type='bool', default=True),
|
|
|
|
|
|
|
|
timeout=dict(type='int', default=30),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
core(module)
|
|
|
|
core(module)
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
module.fail_json(msg=str(e))
|
|
|
|
module.fail_json(msg=to_native(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
|
|
|
main()
|
|
|
|