From e133fc3f5f4622479f9185f5dfff8964d8298ff1 Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Sun, 7 Feb 2021 16:18:16 +0100 Subject: [PATCH] updated ovh api scripts --- states/_modules/ovhapi.py | 15 ++++++++++----- states/_states/ovhapi.py | 3 ++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/states/_modules/ovhapi.py b/states/_modules/ovhapi.py index cac27df..99f947a 100644 --- a/states/_modules/ovhapi.py +++ b/states/_modules/ovhapi.py @@ -53,7 +53,7 @@ def domain_get_zone(zone=""): return results -def domain_get_record(zone="", fieldType="", subDomain=""): +def domain_get_record(zone="", fieldType="", subDomain="", target=""): ''' Record of the zone @@ -63,6 +63,8 @@ def domain_get_record(zone="", fieldType="", subDomain=""): Filter the value of fieldType property (like) subDomain Filter the value of subDomain property (like) + target + Resource record target ''' if zone == "": @@ -70,12 +72,15 @@ def domain_get_record(zone="", fieldType="", subDomain=""): res = None client = _auth() try: - record = client.get(f'/domain/zone/{zone}/record', + records = client.get(f'/domain/zone/{zone}/record', fieldType=fieldType, subDomain=subDomain) - if len(record) > 0: - req = client.get(f'/domain/zone/{zone}/record/{record}') - return req + if len(records) > 0: + for rec in records: + 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 diff --git a/states/_states/ovhapi.py b/states/_states/ovhapi.py index 8294c1a..02c7b08 100644 --- a/states/_states/ovhapi.py +++ b/states/_states/ovhapi.py @@ -48,7 +48,8 @@ def domain_record_present(name, # check if record exists cur_record = __salt__['ovhapi.domain_get_record'](zone=zone, fieldType=recordtype, - subDomain=recordname) + subDomain=recordname, + target=target) if cur_record is not None: res = __salt__['ovhapi.domain_put_record'](zone=zone, fieldType=recordtype,