updated ovh modules

This commit is contained in:
Paul 2021-02-09 01:29:48 +01:00
parent e133fc3f5f
commit 5fedd247c9
3 changed files with 15 additions and 16 deletions

View File

@ -69,7 +69,6 @@ def domain_get_record(zone="", fieldType="", subDomain="", target=""):
if zone == "": if zone == "":
raise ArgumentValueError("Zone is not defined") raise ArgumentValueError("Zone is not defined")
res = None
client = _auth() client = _auth()
try: try:
records = client.get(f'/domain/zone/{zone}/record', records = client.get(f'/domain/zone/{zone}/record',
@ -80,7 +79,6 @@ def domain_get_record(zone="", fieldType="", subDomain="", target=""):
res = client.get(f'/domain/zone/{zone}/record/{rec}') res = client.get(f'/domain/zone/{zone}/record/{rec}')
if res['target'] == target: if res['target'] == target:
return res return res
return None
except APIError: except APIError:
return "Query failed in OVH API" return "Query failed in OVH API"
return None return None
@ -149,13 +147,14 @@ def domain_put_record(zone="",
fieldType=fieldType, fieldType=fieldType,
subDomain=subDomain) subDomain=subDomain)
if len(records) > 0: if len(records) > 0:
record = client.get(f'/domain/zone/{zone}/record/{records[0]}') for rec in records:
req = client.put(f'/domain/zone/{zone}/record/{record["id"]}', res = client.get(f'/domain/zone/{zone}/record/{rec}')
if res['target'] == target:
req = client.put(f'/domain/zone/{zone}/record/{rec["id"]}',
subDomain=subDomain, subDomain=subDomain,
target=target, target=target,
ttl=ttl) ttl=ttl)
return req return req
else:
return "Error updating record" return "Error updating record"
except APIError: except APIError:
return "Query failed in OVH API" return "Query failed in OVH API"

View File

@ -17,11 +17,11 @@ def _str_split(string):
return [e + delim for e in string.split(delim) if e] return [e + delim for e in string.split(delim) if e]
def domain_record_present(name, def domain_record_present(name="",
zone=None, zone="",
recordname=None, recordname="",
recordtype=None, recordtype="A",
target=None, target="",
ttl=0): ttl=0):
res_output = "" res_output = ""

View File

@ -6,7 +6,7 @@ ovh-domain-{{ domain }}-{{ "{}-{}-{}".format(record.name, record.type, record.ta
ovhapi.domain_record_present: ovhapi.domain_record_present:
- name: ovh-domain-{{ domain }}-{{ "{}-{}-{}".format(record.name, record.type, record.target)|md5 }} - name: ovh-domain-{{ domain }}-{{ "{}-{}-{}".format(record.name, record.type, record.target)|md5 }}
- zone: {{ domain }} - zone: {{ domain }}
- recordname: {{ record.name }} - recordname: "{{ record.name }}"
- recordtype: {{ record.type }} - recordtype: {{ record.type }}
- target: {{ record.target }} - target: {{ record.target }}
- ttl: {{ record.ttl|default(0) }} - ttl: {{ record.ttl|default(0) }}