Created
March 20, 2017 22:09
-
-
Save elnygren/bdc262f0465772f55f80621e7e45fc8d to your computer and use it in GitHub Desktop.
Destroy all VMs on UpCloud in parallel
This file contains hidden or 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
| """ | |
| 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