Refactor DigitalOcean modules (#35934)

- Updated documentation fragment
- Updated Argument spec
- Use common REST class for API calls

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2018-02-17 22:00:53 +05:30 committed by GitHub
commit d74d416beb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 116 additions and 144 deletions

View file

@ -27,11 +27,6 @@ options:
- Indicate desired state of the target.
default: present
choices: ['present', 'absent']
oauth_token:
description:
- DigitalOcean api token.
version_added: "1.9.5"
aliases: ['API_TOKEN']
id:
description:
- Numeric, the droplet id you want to operate on.
@ -42,7 +37,7 @@ options:
ip:
description:
- The IP address to point a domain at.
extends_documentation_fragment: digital_ocean.documentation
notes:
- Environment variables DO_OAUTH_TOKEN can be used for the oauth_token.
- As of Ansible 1.9.5 and 2.0, Version 2 of the DigitalOcean API is used, this removes C(client_id) and C(api_key) options in favor of C(oauth_token).
@ -84,7 +79,6 @@ import traceback
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.digital_ocean import DigitalOceanHelper
from ansible.module_utils._text import to_native
from ansible.module_utils.basic import env_fallback
class DoManager(DigitalOceanHelper, object):
@ -185,18 +179,16 @@ def core(module):
def main():
argument_spec = DigitalOceanHelper.digital_ocean_argument_spec()
argument_spec.update(
state=dict(choices=['present', 'absent'], default='present'),
name=dict(type='str'),
id=dict(aliases=['droplet_id'], type='int'),
ip=dict(type='str')
)
module = AnsibleModule(
argument_spec=dict(
state=dict(choices=['present', 'absent'], default='present'),
oauth_token=dict(
aliases=['API_TOKEN'],
no_log=True,
fallback=(env_fallback, ['DO_API_TOKEN', 'DO_API_KEY', 'DO_OAUTH_TOKEN'])
),
name=dict(type='str'),
id=dict(aliases=['droplet_id'], type='int'),
ip=dict(type='str'),
),
argument_spec=argument_spec,
required_one_of=(
['id', 'name'],
),