Created
January 26, 2017 22:50
-
-
Save mnaser/93d59ca4f5163d7a4a2ca0aa762da2dc to your computer and use it in GitHub Desktop.
Retrieve list of all VMs up longer than 24 hours
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
| from datetime import datetime | |
| NOW = datetime.utcnow() | |
| import os_client_config | |
| import prettytable | |
| import shade | |
| cloud_config = os_client_config.OpenStackConfig().get_all_clouds() | |
| for config in cloud_config: | |
| pt = prettytable.PrettyTable(['ID', 'Name', 'Status', 'Uptime'], caching=False) | |
| pt.align = 'l' | |
| print config.name | |
| cloud = shade.openstack_cloud(cloud=config.name) | |
| servers = cloud.list_servers() | |
| for s in servers: | |
| created = datetime.strptime(s.created, "%Y-%m-%dT%H:%M:%SZ") | |
| uptime = NOW - created | |
| if uptime.days < 1: | |
| continue | |
| pt.add_row([s.id, s.name, s.status, uptime]) | |
| print pt | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment