Added a vm_migrations DB table
This commit is contained in:
parent
c7f1adbca0
commit
9922d95b58
@ -31,16 +31,18 @@ class Database(object):
|
||||
hosts=Table,
|
||||
vms=Table,
|
||||
vm_resource_usage=Table,
|
||||
vm_migrations=Table,
|
||||
host_states=Table,
|
||||
host_overload=Table)
|
||||
def __init__(self, connection, hosts, vms,
|
||||
vm_resource_usage, host_states, host_overload):
|
||||
def __init__(self, connection, hosts, vms, vm_resource_usage,
|
||||
vm_migrations, host_states, host_overload):
|
||||
""" 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 vm_migrations: The vm_migrations table.
|
||||
:param host_states: The host_states table.
|
||||
:param host_overload: The host_overload table.
|
||||
"""
|
||||
@ -48,6 +50,7 @@ class Database(object):
|
||||
self.hosts = hosts
|
||||
self.vms = vms
|
||||
self.vm_resource_usage = vm_resource_usage
|
||||
self.vm_migrations = vm_migrations
|
||||
self.host_states = host_states
|
||||
self.host_overload = host_overload
|
||||
log.debug('Instantiated a Database object')
|
||||
|
@ -56,6 +56,13 @@ def init_db(sql_connection):
|
||||
Column('timestamp', DateTime, default=func.now()),
|
||||
Column('cpu_mhz', Integer, nullable=False))
|
||||
|
||||
vm_migrations = \
|
||||
Table('vm_migrations', metadata,
|
||||
Column('id', Integer, primary_key=True),
|
||||
Column('vm_id', Integer, ForeignKey('vms.id'), nullable=False),
|
||||
Column('timestamp', DateTime, default=func.now()),
|
||||
Column('hostname', String(255), nullable=False))
|
||||
|
||||
host_states = \
|
||||
Table('host_states', metadata,
|
||||
Column('id', Integer, primary_key=True),
|
||||
@ -73,7 +80,7 @@ def init_db(sql_connection):
|
||||
metadata.create_all()
|
||||
connection = engine.connect()
|
||||
db = Database(connection, hosts, vms, vm_resource_usage,
|
||||
host_states, host_overload)
|
||||
vm_migrations, host_states, host_overload)
|
||||
|
||||
log.debug('Initialized a DB connection to %s', sql_connection)
|
||||
return db
|
||||
|
@ -42,6 +42,10 @@ class DbUtils(TestCase):
|
||||
['id', 'vm_id', 'timestamp', 'cpu_mhz']
|
||||
assert list(db.vm_resource_usage.foreign_keys)[0].target_fullname \
|
||||
== 'vms.id'
|
||||
assert db.vm_migrations.c.keys() == \
|
||||
['id', 'vm_id', 'timestamp', 'hostname']
|
||||
assert list(db.vm_migrations.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 \
|
||||
|
Loading…
x
Reference in New Issue
Block a user