Created
January 15, 2015 17:20
-
-
Save mgagne/bc54c3434a119246a88d to your computer and use it in GitHub Desktop.
Nova flavor slots
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
#!/usr/bin/env python | |
import argparse | |
import os | |
import prettytable | |
from novaclient.v1_1 import client as novaclient | |
OS_USERNAME = os.environ['OS_USERNAME'] | |
OS_PASSWORD = os.environ['OS_PASSWORD'] | |
OS_AUTH_URL = os.environ['OS_AUTH_URL'] | |
OS_TENANT_NAME = os.environ['OS_TENANT_NAME'] | |
OS_REGION_NAME = os.environ['OS_REGION_NAME'] | |
def nova(): | |
return novaclient.Client( | |
username=OS_USERNAME, | |
api_key=OS_PASSWORD, | |
project_id=OS_TENANT_NAME, | |
auth_url=OS_AUTH_URL, | |
region_name=OS_REGION_NAME) | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--flavor', required=True, help='Flavor.') | |
args = parser.parse_args() | |
nova = nova() | |
flavor = nova.flavors.find(name=args.flavor) | |
hypervisors = nova.hypervisors.list() | |
hypervisor_stats = [] | |
for hypervisor in hypervisors: | |
vcpus_available = hypervisor.vcpus - hypervisor.vcpus_used | |
ram_available = (hypervisor.memory_mb - hypervisor.memory_mb_used) | |
free_slots = min(vcpus_available / flavor.vcpus, | |
ram_available / flavor.ram) | |
hypervisor_stats.append([ | |
hypervisor.service.get('host'), | |
vcpus_available, | |
ram_available / 1024, | |
free_slots, | |
]) | |
fields = ['Hypervisor', 'Free VCPUs', 'Free RAM', 'Free Slots'] | |
pt = prettytable.PrettyTable([f for f in fields], caching=False) | |
[pt.add_row(s) for s in hypervisor_stats] | |
print pt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment