Skip to content

Instantly share code, notes, and snippets.

@antoviaque
Last active September 22, 2016 14:34
Show Gist options
  • Save antoviaque/443c8a507d52aaccf76b18a46258da56 to your computer and use it in GitHub Desktop.
Save antoviaque/443c8a507d52aaccf76b18a46258da56 to your computer and use it in GitHub Desktop.
OpenCraft IM - Terminate VMs on instances linked to a closed/merged PR
# Ensure to disable auto-indent before pasting in ipython: %autoindent
# TODO: Disable monitoring
# TODO: Hide from UX (archive)
from pr_watch import github
for instance in OpenEdXInstance.objects.filter(watchedpullrequest__isnull=False):
pr = github.get_object_from_url('https://api.github.com/repos/{}/pulls/{}'.format(
instance.watchedpullrequest.target_fork_name,
instance.watchedpullrequest.github_pr_number
))
if pr['state'] == 'closed':
for appserver in instance.appserver_set.all():
appserver.terminate_vm()
@e-kolpakov
Copy link

@antoviaque: does it also make sense to delete the instance itself?

@antoviaque
Copy link
Author

@e-kolpakov We should probably find a way to hide it from the UX (archiving?) when it doesn't have any active appserver anymore, but for record-keeping purposes we probably don't want to delete the objects themselves.

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