Commit e972eaaf authored by Varac's avatar Varac

Merge branch 'speedup-terminate-droplets' into 'master'

speedup terminate-droplets command

See merge request !3
parents 70b665bf a8f195af
......@@ -298,14 +298,29 @@ def terminate_droplets_by_name(name_regex: str, ndays: int = 0,
if 'NO_TERMINATE_DROPLETS' in os.environ:
noterminate_droplets = os.environ['NO_TERMINATE_DROPLETS'].split(',')
# List of droplets that will be terminated
terminate_droplets = []
for droplet in all_droplets:
if droplet['name'] not in noterminate_droplets:
if re.match(name_regex, droplet['name']):
if droplet['created_at'] < threshold_time:
delete_domain_records_by_name(
domain, r'^\*.'+droplet['name'])
delete_domain_records_by_name(domain, '^'+droplet['name'])
terminate_droplet(droplet['id'])
terminate_droplets.append(droplet)
# First stop all droplets
for droplet in terminate_droplets:
shutdown_droplet(droplet['id'])
# Then delete all domain names associated with the droplets
for droplet in terminate_droplets:
delete_domain_records_by_name(
domain, r'^\*.'+droplet['name'])
delete_domain_records_by_name(domain, '^'+droplet['name'])
# Lastly delete all droplets:
for droplet in terminate_droplets:
wait_for_state(droplet['id'], 'stopped')
delete_droplet(droplet['id'])
def wait_for_ssh(droplet_ip: str):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment