Added select_host_ids, started working on insert_host_states

This commit is contained in:
Anton Beloglazov 2012-10-15 15:21:54 +11:00
parent 601ac8c64b
commit 66536cf938
2 changed files with 28 additions and 0 deletions

View File

@ -186,6 +186,16 @@ class Database(object):
hosts_ram[hostname] = int(x[4])
return hosts_cpu_mhz, hosts_cpu_cores, hosts_ram
@contract
def select_host_ids(self):
""" Select the IDs of all the hosts.
:return: A dict of host names to IDs.
:rtype: dict(str: int)
"""
return dict((str(x[1]), int(x[0]))
for x in self.hosts.select().execute().fetchall())
@contract(datetime_threshold=datetime.datetime)
def cleanup_vm_resource_usage(self, datetime_threshold):
""" Delete VM resource usage data older than the threshold.
@ -197,3 +207,11 @@ class Database(object):
self.vm_resource_usage.delete().where(
self.vm_resource_usage.c.timestamp < datetime_threshold))
@contract
def insert_host_states(self, hosts):
""" Insert host states for a set of hosts.
:param hosts: A dict of hostnames to states (0, 1).
:type hosts: dict(str: int)
"""
pass

View File

@ -142,6 +142,15 @@ class Db(TestCase):
{'host1': 4, 'host2': 8},
{'host1': 4000, 'host2': 8000})
@qc(1)
def select_host_ids():
db = db_utils.init_db('sqlite:///:memory:')
assert db.select_host_ids() == {}
hosts = {}
hosts['host1'] = db.update_host('host1', 1, 1, 1)
hosts['host2'] = db.update_host('host2', 1, 1, 1)
assert db.select_host_ids() == hosts
@qc(1)
def cleanup_vm_resource_usage(
uuid=str_(of='abc123-', min_length=36, max_length=36)
@ -158,3 +167,4 @@ class Db(TestCase):
assert db.select_cpu_mhz_for_vm(uuid, 100) == range(10)
db.cleanup_vm_resource_usage(time.replace(second=5))
assert db.select_cpu_mhz_for_vm(uuid, 100) == range(5, 10)