From 5fedd247c9e6f0050d0486b16792be1d5780a66a Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Tue, 9 Feb 2021 01:29:48 +0100 Subject: [PATCH] updated ovh modules --- states/_modules/ovhapi.py | 19 +++++++++---------- states/_states/ovhapi.py | 10 +++++----- states/ovh/domain.sls | 2 +- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/states/_modules/ovhapi.py b/states/_modules/ovhapi.py index 99f947a..0a64fd7 100644 --- a/states/_modules/ovhapi.py +++ b/states/_modules/ovhapi.py @@ -69,7 +69,6 @@ def domain_get_record(zone="", fieldType="", subDomain="", target=""): if zone == "": raise ArgumentValueError("Zone is not defined") - res = None client = _auth() try: 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}') if res['target'] == target: return res - return None except APIError: return "Query failed in OVH API" return None @@ -149,14 +147,15 @@ def domain_put_record(zone="", fieldType=fieldType, subDomain=subDomain) if len(records) > 0: - record = client.get(f'/domain/zone/{zone}/record/{records[0]}') - req = client.put(f'/domain/zone/{zone}/record/{record["id"]}', - subDomain=subDomain, - target=target, - ttl=ttl) - return req - else: - return "Error updating record" + for rec in records: + 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, + target=target, + ttl=ttl) + return req + return "Error updating record" except APIError: return "Query failed in OVH API" diff --git a/states/_states/ovhapi.py b/states/_states/ovhapi.py index 02c7b08..b47fb3e 100644 --- a/states/_states/ovhapi.py +++ b/states/_states/ovhapi.py @@ -17,11 +17,11 @@ def _str_split(string): return [e + delim for e in string.split(delim) if e] -def domain_record_present(name, - zone=None, - recordname=None, - recordtype=None, - target=None, +def domain_record_present(name="", + zone="", + recordname="", + recordtype="A", + target="", ttl=0): res_output = "" diff --git a/states/ovh/domain.sls b/states/ovh/domain.sls index 61fa5f1..b1b5983 100644 --- a/states/ovh/domain.sls +++ b/states/ovh/domain.sls @@ -6,7 +6,7 @@ ovh-domain-{{ domain }}-{{ "{}-{}-{}".format(record.name, record.type, record.ta ovhapi.domain_record_present: - name: ovh-domain-{{ domain }}-{{ "{}-{}-{}".format(record.name, record.type, record.target)|md5 }} - zone: {{ domain }} - - recordname: {{ record.name }} + - recordname: "{{ record.name }}" - recordtype: {{ record.type }} - target: {{ record.target }} - ttl: {{ record.ttl|default(0) }}