This is a great library. Thanks!
I wrote this function which i find useful, thought others might too:
if you are doing a lot of additions/updates it is better to generate exist first and pass it in rather than have each call get the existing records.
def add_or_update(domain, ip, value, record_type='A', exist=None):
if not exist:
exist = client.get_records(domain, record_type=record_type)
names = [x['name'] for x in exist]
if value in names:
if exist[names.index(value)]['data'] != ip:
client.update_record_ip(ip, domain,value,record_type)
print(f'Updated {value}.{domain} to point to {ip}.')
else:
print(f'{value}.{domain} already points to {ip}. Not changing anything.')
else:
client.add_record(domain,
{
'data': ip,
'name': value,
'ttl':3600,
'type':record_type
})
print(f'Added record for {value}.{domain} to point to {ip}.')
This is a great library. Thanks!
I wrote this function which i find useful, thought others might too:
if you are doing a lot of additions/updates it is better to generate
existfirst and pass it in rather than have each call get the existing records.