From 8170ebddd1b7211dc8984e19e1603483e9b56301 Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Sun, 24 Jan 2021 19:01:14 +0100 Subject: [PATCH] updated modules --- states/_modules/ovhapi.py | 2 +- states/_states/ovhapi.py | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/states/_modules/ovhapi.py b/states/_modules/ovhapi.py index 2c8aae1..cac27df 100644 --- a/states/_modules/ovhapi.py +++ b/states/_modules/ovhapi.py @@ -145,7 +145,7 @@ def domain_put_record(zone="", subDomain=subDomain) if len(records) > 0: record = client.get(f'/domain/zone/{zone}/record/{records[0]}') - req = client.put(f'/domain/zone/{zone}/record/{records[0]["id"]}', + req = client.put(f'/domain/zone/{zone}/record/{record["id"]}', subDomain=subDomain, target=target, ttl=ttl) diff --git a/states/_states/ovhapi.py b/states/_states/ovhapi.py index 1198837..c629d41 100644 --- a/states/_states/ovhapi.py +++ b/states/_states/ovhapi.py @@ -53,24 +53,29 @@ def domain_record_present(name, res = __salt__['ovhapi.domain_put_record'](zone=zone, fieldType=recordtype, subDomain=recordname) - res_output = f"Updated record {recordname}, output: {res_output}" + new_zone_state = __salt__['ovhapi.domain_get_zone'](zone=zone) + ret['changes'] = { + "diff": salt.utils.stringutils.get_diff(_str_split(cur_zone_state), + _str_split(new_zone_state)) + } + res_output = f"Updated record {recordname}" else: res = __salt__['ovhapi.domain_post_record'](zone=zone, subDomain=recordname, fieldType=recordtype, target=target, ttl=ttl) - res_output = f"Updated record {recordname}, output: {res_output}" + new_zone_state = __salt__['ovhapi.domain_get_zone'](zone=zone) - new_zone_state = __salt__['ovhapi.domain_get_zone'](zone=zone) + ret['changes'] = { + "diff": salt.utils.stringutils.get_diff(_str_split(cur_zone_state), + _str_split(new_zone_state)) + } + res_output = f"Created record {recordname}" cur_zone_refresh = __salt__['ovhapi.domain_refresh_zone'](zone=zone) - ret['changes'] = { - "diff": salt.utils.stringutils.get_diff(_str_split(cur_zone_state), - _str_split(new_zone_state)) - } - ret['comment'] = f'Result is {res_output}, refresh {cur_zone_refresh}' + ret['comment'] = f'Result is {res_output}' return ret