droplets: Garbage collect A records before creating droplet.

This commit is contained in:
Vishnu Ks 2017-11-06 01:53:50 +05:30 committed by Tim Abbott
parent dec4b9ed93
commit c5ff020246
1 changed files with 11 additions and 1 deletions

View File

@ -156,9 +156,19 @@ def create_droplet(my_token, template_id, username, tags, user_data):
def create_dns_record(my_token, username, ip_address):
# type: (str, str, str) -> None
print("Creating A record for {0}.zulipdev.org that points to {1}.".format(username, ip_address))
domain = digitalocean.Domain(token=my_token, name='zulipdev.org')
domain.load()
records = domain.get_records()
count = 0
for record in records:
if record.name == username and record.domain == 'zulipdev.org' and record.type == 'A':
record.destroy()
count = count + 1
if count:
print("Deleted {0} existing A records for {1}.zulipdev.org.".format(count, username))
print("Creating new A record for {0}.zulipdev.org that points to {1}.".format(username, ip_address))
domain.create_new_domain_record(type='A', name=username, data=ip_address)
def print_completion(username):