Last active
September 22, 2016 14:34
-
-
Save antoviaque/443c8a507d52aaccf76b18a46258da56 to your computer and use it in GitHub Desktop.
OpenCraft IM - Terminate VMs on instances linked to a closed/merged PR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 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
@antoviaque: does it also make sense to delete the instance itself?