updated ovhapi module
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Paul 2022-12-11 13:46:51 +01:00
parent 287445d486
commit 0412f86d26

View File

@ -1,9 +1,5 @@
#!/usr/bin/python3 #!/usr/bin/python3
import salt.utils.dictupdate
import salt.utils.dictdiffer
def _error(ret, err_msg): def _error(ret, err_msg):
ret['result'] = False ret['result'] = False
ret['comment'] = err_msg ret['comment'] = err_msg
@ -17,11 +13,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=None,
zone="", zone=None,
recordname="", recordname=None,
recordtype="A", recordtype="A",
target="", target=None,
ttl=0): ttl=0):
res_output = "" res_output = ""
@ -32,47 +28,41 @@ def domain_record_present(name="",
'comment': 'Config is up to date' 'comment': 'Config is up to date'
} }
if not name: if type(name) is not str:
return _error(ret, 'Must provide name to ovhapi.domain_record_present') return _error(ret, 'Must provide name to ovhapi.domain_record_present')
if not zone: if type(zone) is not str:
return _error(ret, 'Must provide dns zone to ovhapi.domain_record_present') return _error(ret, 'Must provide dns zone to ovhapi.domain_record_present')
if not recordname: if type(recordname) is not str:
return _error(ret, 'Must provide record name to ovhapi.domain_record_present') return _error(ret, 'Must provide record name to ovhapi.domain_record_present')
if not recordtype: if type(recordtype) is not str:
return _error(ret, 'Must provide record type to ovhapi.domain_record_present') return _error(ret, 'Must provide record type to ovhapi.domain_record_present')
if not target: if type(target) is not str:
return _error(ret, 'Must provide target to ovhapi.domain_record_present') return _error(ret, 'Must provide target to ovhapi.domain_record_present')
cur_zone_state = __salt__['ovhapi.domain_get_zone'](zone=zone)
# check if record exists # check if record exists
cur_record = __salt__['ovhapi.domain_get_record'](zone=zone, cur_record = __salt__['ovhapi.domain_get_record'](zone=zone,
fieldType=recordtype, fieldType=recordtype,
subDomain=recordname, subDomain=recordname,
target=target) target=target)
if cur_record: if cur_record:
__salt__['ovhapi.domain_put_record'](zone=zone, new_record = __salt__['ovhapi.domain_put_record'](zone=zone,
fieldType=recordtype, fieldType=recordtype,
subDomain=recordname, subDomain=recordname,
target=target) target=target)
new_zone_state = __salt__['ovhapi.domain_get_zone'](zone=zone)
ret['changes'] = { ret['changes'] = {
"diff": salt.utils.stringutils.get_diff(_str_split(cur_zone_state), "diff": f"old record: {cur_record}, new record: {new_record}"
_str_split(new_zone_state))
} }
res_output = f"Updated record {recordname}" res_output = f"Updated record {recordname}"
else: else:
__salt__['ovhapi.domain_post_record'](zone=zone, new_record = __salt__['ovhapi.domain_post_record'](zone=zone,
subDomain=recordname, subDomain=recordname,
fieldType=recordtype, fieldType=recordtype,
target=target, target=target,
ttl=ttl) ttl=ttl)
new_zone_state = __salt__['ovhapi.domain_get_zone'](zone=zone)
ret['changes'] = { ret['changes'] = {
"diff": salt.utils.stringutils.get_diff(_str_split(cur_zone_state), "diff": f"new record: {new_record}"
_str_split(new_zone_state))
} }
res_output = f"Created record {recordname}" res_output = f"Created record {recordname}"