Created
June 25, 2015 05:37
-
-
Save hurulu/0eb098b3c8e11f6641e2 to your computer and use it in GitHub Desktop.
get free vcpus in nova database
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
| #!/usr/bin/env python | |
| import sys,string | |
| import os | |
| import MySQLdb as mdb | |
| try: | |
| con = mdb.connect('db-server', 'username', 'password', 'dbname'); | |
| cur = con.cursor() | |
| cur.execute("select compute_nodes.hypervisor_hostname,sum(compute_nodes.vcpus),sum(compute_nodes.vcpus-compute_nodes.vcpus_used) as free_cores from compute_nodes join services on services.disabled=0 and services.topic='compute' and compute_nodes.service_id=services.id and compute_nodes.deleted_at is NULL;") | |
| result = cur.fetchone() | |
| print result[2] | |
| except mdb.Error, e: | |
| print "Error %d: %s" % (e.args[0],e.args[1]) | |
| sys.exit(1) | |
| finally: | |
| if con: | |
| con.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment