Skip to content

Instantly share code, notes, and snippets.

@elnygren
Created March 20, 2017 22:09
Show Gist options
  • Select an option

  • Save elnygren/bdc262f0465772f55f80621e7e45fc8d to your computer and use it in GitHub Desktop.

Select an option

Save elnygren/bdc262f0465772f55f80621e7e45fc8d to your computer and use it in GitHub Desktop.
Destroy all VMs on UpCloud in parallel
"""
I use this for DevOps.
...ya know, when you test stuff, and need to bring everything down after.
"""
import os
import upcloud_api
import multiprocessing
manager = upcloud_api.CloudManager(os.environ.get('UPCLOUD_API_USER'), os.environ.get('UPCLOUD_API_PASSWD'))
def destroy(server):
"""Destroy a server and it's storates."""
print('destroying {} ({})'.format(server.hostname, server.title))
server.stop_and_destroy()
# halt and catch fire, in parallel
pool = multiprocessing.Pool()
pool.map(destroy, manager.get_servers())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment