catch ovh_update errors

This commit is contained in:
Gilles Grandou 2019-11-12 12:23:26 +01:00
parent 5aa8575127
commit 79eb79f46c

View File

@ -152,39 +152,43 @@ def ovh_update_zone(domain, update_zone_list, delete_zone_list):
if not len(update_zone_list) and not len(delete_zone_list): if not len(update_zone_list) and not len(delete_zone_list):
return False return False
client = ovh.Client() try:
client = ovh.Client()
for host, fieldtype, target in delete_zone_list: for host, fieldtype, target in delete_zone_list:
result = client.get('/domain/zone/%s/record' % domain, result = client.get('/domain/zone/%s/record' % domain,
fieldType=fieldtype, fieldType=fieldtype,
subDomain=host) subDomain=host)
for id in result: for id in result:
r = client.get('/domain/zone/%s/record/%d' % (domain, id)) r = client.get('/domain/zone/%s/record/%d' % (domain, id))
if r['fieldType'] == fieldtype and r['target'] == target: if r['fieldType'] == fieldtype and r['target'] == target:
#print("Delete entry for %s %s %s" % (host, fieldtype, target)) #print("Delete entry for %s %s %s" % (host, fieldtype, target))
client.delete('/domain/zone/%s/record/%d' % (domain, id)) client.delete('/domain/zone/%s/record/%d' % (domain, id))
for host, fieldtype, target in update_zone_list: for host, fieldtype, target in update_zone_list:
result = client.get('/domain/zone/%s/record' % domain, result = client.get('/domain/zone/%s/record' % domain,
fieldType=fieldtype, fieldType=fieldtype,
subDomain=host) subDomain=host)
skip = False skip = False
for id in result: for id in result:
r = client.get('/domain/zone/%s/record/%d' % (domain, id)) r = client.get('/domain/zone/%s/record/%d' % (domain, id))
if r['fieldType'] == fieldtype and r['target'] == target: if r['fieldType'] == fieldtype and r['target'] == target:
skip = True skip = True
if skip: if skip:
continue continue
#print("Create new entry for %s %s %s" % (host, fieldtype, target)) #print("Create new entry for %s %s %s" % (host, fieldtype, target))
client.post('/domain/zone/%s/record' % domain, client.post('/domain/zone/%s/record' % domain,
fieldType=fieldtype, fieldType=fieldtype,
subDomain=host, subDomain=host,
target=target, target=target,
ttl=60) ttl=60)
#print("Refresh zone %s" % domain) #print("Refresh zone %s" % domain)
client.post('/domain/zone/%s/refresh' % domain) client.post('/domain/zone/%s/refresh' % domain)
return True return True
except:
print('OVH update error\n')
return False
def send_update_mail(mail_to, mail_from, zone_domain, update_zone_list, delete_zone_list, mail_ignore_list, wan): def send_update_mail(mail_to, mail_from, zone_domain, update_zone_list, delete_zone_list, mail_ignore_list, wan):