digital_ocean_domain: fix to allow updating the module param ip between calls (#42009)
* update the domain record with the new ip from params if resource exists * fixes for pylint and pep8 checks
This commit is contained in:
parent
905acd7c9e
commit
c123b4e7ef
1 changed files with 20 additions and 5 deletions
|
@ -134,10 +134,22 @@ class DoManager(DigitalOceanHelper, object):
|
|||
else:
|
||||
return json
|
||||
|
||||
def edit_domain_record(self):
|
||||
params = {'name': self.domain_name}
|
||||
resp = self.put('domains/%s/records/%s' % (self.domain_name, self.domain_id), data=params)
|
||||
def edit_domain_record(self, record):
|
||||
params = {'name': '@',
|
||||
'data': self.module.params.get('ip')}
|
||||
resp = self.put('domains/%s/records/%s' % (self.domain_name, record['id']), data=params)
|
||||
status, json = self.jsonify(resp)
|
||||
|
||||
return json['domain_record']
|
||||
|
||||
def create_domain_record(self):
|
||||
params = {'name': '@',
|
||||
'type': 'A',
|
||||
'data': self.module.params.get('ip')}
|
||||
|
||||
resp = self.post('domains/%s/records' % (self.domain_name), data=params)
|
||||
status, json = self.jsonify(resp)
|
||||
|
||||
return json['domain_record']
|
||||
|
||||
|
||||
|
@ -160,8 +172,11 @@ def core(module):
|
|||
if record['name'] == "@" and record['type'] == 'A':
|
||||
at_record = record
|
||||
|
||||
if not at_record['data'] == module.params.get('ip'):
|
||||
do_manager.edit_domain_record()
|
||||
if not at_record:
|
||||
do_manager.create_domain_record()
|
||||
module.exit_json(changed=True, domain=do_manager.find())
|
||||
elif not at_record['data'] == module.params.get('ip'):
|
||||
do_manager.edit_domain_record(at_record)
|
||||
module.exit_json(changed=True, domain=do_manager.find())
|
||||
else:
|
||||
module.exit_json(changed=False, domain=do_manager.domain_record())
|
||||
|
|
Loading…
Reference in a new issue