Skip to content
Snippets Groups Projects
Verified Commit a8f195af authored by Maarten de Waard's avatar Maarten de Waard :angel:
Browse files

speedup terminate-droplets command

parent 70b665bf
No related branches found
No related tags found
1 merge request!3speedup terminate-droplets command
......@@ -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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment