Added a host_states table
This commit is contained in:
parent
55254c2fdc
commit
601ac8c64b
@ -30,19 +30,23 @@ class Database(object):
|
||||
@contract(connection=Connection,
|
||||
hosts=Table,
|
||||
vms=Table,
|
||||
vm_resource_usage=Table)
|
||||
def __init__(self, connection, hosts, vms, vm_resource_usage):
|
||||
vm_resource_usage=Table,
|
||||
host_states=Table)
|
||||
def __init__(self, connection, hosts, vms,
|
||||
vm_resource_usage, host_states):
|
||||
""" Initialize the database.
|
||||
|
||||
:param connection: A database connection table.
|
||||
:param hosts: The hosts table.
|
||||
:param vms: The vms table.
|
||||
:param vm_resource_usage: The vm_resource_usage table.
|
||||
:param host_states: The host_states table.
|
||||
"""
|
||||
self.connection = connection
|
||||
self.hosts = hosts
|
||||
self.vms = vms
|
||||
self.vm_resource_usage = vm_resource_usage
|
||||
self.host_states = host_states
|
||||
log.debug('Instantiated a Database object')
|
||||
|
||||
@contract
|
||||
|
@ -56,9 +56,16 @@ def init_db(sql_connection):
|
||||
Column('timestamp', DateTime, default=func.now()),
|
||||
Column('cpu_mhz', Integer, nullable=False))
|
||||
|
||||
host_states = \
|
||||
Table('host_states', metadata,
|
||||
Column('id', Integer, primary_key=True),
|
||||
Column('host_id', Integer, ForeignKey('hosts.id'), nullable=False),
|
||||
Column('timestamp', DateTime, default=func.now()),
|
||||
Column('state', Integer, nullable=False))
|
||||
|
||||
metadata.create_all()
|
||||
connection = engine.connect()
|
||||
db = Database(connection, hosts, vms, vm_resource_usage)
|
||||
db = Database(connection, hosts, vms, vm_resource_usage, host_states)
|
||||
|
||||
log.debug('Initialized a DB connection to %s', sql_connection)
|
||||
return db
|
||||
|
@ -33,6 +33,7 @@ class DbUtils(TestCase):
|
||||
assert isinstance(db.hosts, Table)
|
||||
assert isinstance(db.vms, Table)
|
||||
assert isinstance(db.vm_resource_usage, Table)
|
||||
assert isinstance(db.host_states, Table)
|
||||
assert db.hosts.c.keys() == \
|
||||
['id', 'hostname', 'cpu_mhz', 'cpu_cores', 'ram']
|
||||
assert db.vms.c.keys() == \
|
||||
@ -41,3 +42,7 @@ class DbUtils(TestCase):
|
||||
['id', 'vm_id', 'timestamp', 'cpu_mhz']
|
||||
assert list(db.vm_resource_usage.foreign_keys)[0].target_fullname \
|
||||
== 'vms.id'
|
||||
assert db.host_states.c.keys() == \
|
||||
['id', 'host_id', 'timestamp', 'state']
|
||||
assert list(db.host_states.foreign_keys)[0].target_fullname \
|
||||
== 'hosts.id'
|
||||
|
Loading…
x
Reference in New Issue
Block a user