Merge pull request #2550 from lippylee/patch-2

Make digital_ocean_domain use API v2
This commit is contained in:
Brian Coca 2015-11-25 09:35:10 -08:00
commit e698eaa3e9

View file

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