Merge pull request #2550 from lippylee/patch-2
Make digital_ocean_domain use API v2
This commit is contained in:
commit
e698eaa3e9
1 changed files with 12 additions and 18 deletions
|
@ -29,12 +29,9 @@ options:
|
|||
- Indicate desired state of the target.
|
||||
default: present
|
||||
choices: ['present', 'absent']
|
||||
client_id:
|
||||
api_token:
|
||||
description:
|
||||
- DigitalOcean manager id.
|
||||
api_key:
|
||||
description:
|
||||
- DigitalOcean api key.
|
||||
- DigitalOcean api token.
|
||||
id:
|
||||
description:
|
||||
- Numeric, the droplet id you want to operate on.
|
||||
|
@ -46,8 +43,8 @@ options:
|
|||
- The IP address to point a domain at.
|
||||
|
||||
notes:
|
||||
- Two environment variables can be used, DO_CLIENT_ID and DO_API_KEY.
|
||||
- Version 1 of DigitalOcean API is used.
|
||||
- Two environment variables can be used, DO_API_KEY and DO_API_TOKEN. They both refer to the v2 token.
|
||||
- Version 2 of DigitalOcean API is used.
|
||||
|
||||
requirements:
|
||||
- "python >= 2.6"
|
||||
|
@ -68,9 +65,9 @@ EXAMPLES = '''
|
|||
- digital_ocean: >
|
||||
state=present
|
||||
name=test_droplet
|
||||
size_id=1
|
||||
region_id=2
|
||||
image_id=3
|
||||
size_id=1gb
|
||||
region_id=sgp1
|
||||
image_id=ubuntu-14-04-x64
|
||||
register: test_droplet
|
||||
|
||||
- digital_ocean_domain: >
|
||||
|
@ -135,8 +132,8 @@ class Domain(JsonfyMixIn):
|
|||
return cls(json)
|
||||
|
||||
@classmethod
|
||||
def setup(cls, client_id, api_key):
|
||||
cls.manager = DoManager(client_id, api_key)
|
||||
def setup(cls, api_token):
|
||||
cls.manager = DoManager(None, api_token, api_version=2)
|
||||
DomainRecord.manager = cls.manager
|
||||
|
||||
@classmethod
|
||||
|
@ -171,16 +168,14 @@ def core(module):
|
|||
return v
|
||||
|
||||
try:
|
||||
# params['client_id'] will be None even if client_id is not passed in
|
||||
client_id = module.params['client_id'] or os.environ['DO_CLIENT_ID']
|
||||
api_key = module.params['api_key'] or os.environ['DO_API_KEY']
|
||||
api_token = module.params['api_token'] or os.environ['DO_API_TOKEN'] or os.environ['DO_API_KEY']
|
||||
except KeyError, e:
|
||||
module.fail_json(msg='Unable to load %s' % e.message)
|
||||
|
||||
changed = True
|
||||
state = module.params['state']
|
||||
|
||||
Domain.setup(client_id, api_key)
|
||||
Domain.setup(api_token)
|
||||
if state in ('present'):
|
||||
domain = Domain.find(id=module.params["id"])
|
||||
|
||||
|
@ -223,8 +218,7 @@ def main():
|
|||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
state = dict(choices=['present', 'absent'], default='present'),
|
||||
client_id = dict(aliases=['CLIENT_ID'], no_log=True),
|
||||
api_key = dict(aliases=['API_KEY'], no_log=True),
|
||||
api_token = dict(aliases=['API_TOKEN'], no_log=True),
|
||||
name = dict(type='str'),
|
||||
id = dict(aliases=['droplet_id'], type='int'),
|
||||
ip = dict(type='str'),
|
||||
|
|
Loading…
Reference in a new issue