Skip to content

Instantly share code, notes, and snippets.

@antoviaque
Last active September 22, 2016 05:41
Show Gist options
  • Save antoviaque/216046586b051c3ae1265b54f2d02f71 to your computer and use it in GitHub Desktop.
Save antoviaque/216046586b051c3ae1265b54f2d02f71 to your computer and use it in GitHub Desktop.
OpenCraft IM - Automatically terminate old & failed VMs
# Ensure to disable auto-indent before pasting in ipython: %autoindent
from instance.models.appserver import Status
for instance in OpenEdXInstance.objects.all():
for appserver in instance.appserver_set.all():
if appserver.status == Status.ConfigurationFailed:
appserver.terminate_vm()
elif instance.active_appserver and appserver.created < instance.active_appserver.created:
appserver.terminate_vm()
@e-kolpakov
Copy link

@antoviaque Just one suggestion going forward (i.e. for automating it as part of OC IM) - we might want to keep most-recent-inactive-provisioned servers just to be sure we can rollback if something goes wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment