Added a host_overload db table
This commit is contained in:
parent
55d91f821c
commit
296a39c540
@ -31,9 +31,10 @@ class Database(object):
|
||||
hosts=Table,
|
||||
vms=Table,
|
||||
vm_resource_usage=Table,
|
||||
host_states=Table)
|
||||
host_states=Table,
|
||||
host_overload=Table)
|
||||
def __init__(self, connection, hosts, vms,
|
||||
vm_resource_usage, host_states):
|
||||
vm_resource_usage, host_states, host_overload):
|
||||
""" Initialize the database.
|
||||
|
||||
:param connection: A database connection table.
|
||||
@ -41,12 +42,14 @@ class Database(object):
|
||||
:param vms: The vms table.
|
||||
:param vm_resource_usage: The vm_resource_usage table.
|
||||
:param host_states: The host_states table.
|
||||
:param host_overload: The host_overload table.
|
||||
"""
|
||||
self.connection = connection
|
||||
self.hosts = hosts
|
||||
self.vms = vms
|
||||
self.vm_resource_usage = vm_resource_usage
|
||||
self.host_states = host_states
|
||||
self.host_overload = host_overload
|
||||
log.debug('Instantiated a Database object')
|
||||
|
||||
@contract
|
||||
|
@ -63,9 +63,17 @@ def init_db(sql_connection):
|
||||
Column('timestamp', DateTime, default=func.now()),
|
||||
Column('state', Integer, nullable=False))
|
||||
|
||||
host_overload = \
|
||||
Table('host_overload', metadata,
|
||||
Column('id', Integer, primary_key=True),
|
||||
Column('host_id', Integer, ForeignKey('hosts.id'), nullable=False),
|
||||
Column('timestamp', DateTime, default=func.now()),
|
||||
Column('overload', Integer, nullable=False))
|
||||
|
||||
metadata.create_all()
|
||||
connection = engine.connect()
|
||||
db = Database(connection, hosts, vms, vm_resource_usage, host_states)
|
||||
db = Database(connection, hosts, vms, vm_resource_usage,
|
||||
host_states, host_overload)
|
||||
|
||||
log.debug('Initialized a DB connection to %s', sql_connection)
|
||||
return db
|
||||
|
@ -46,3 +46,7 @@ class DbUtils(TestCase):
|
||||
['id', 'host_id', 'timestamp', 'state']
|
||||
assert list(db.host_states.foreign_keys)[0].target_fullname \
|
||||
== 'hosts.id'
|
||||
assert db.host_overload.c.keys() == \
|
||||
['id', 'host_id', 'timestamp', 'overload']
|
||||
assert list(db.host_overload.foreign_keys)[0].target_fullname \
|
||||
== 'hosts.id'
|
||||
|
Loading…
x
Reference in New Issue
Block a user