diff --git a/neat/db.py b/neat/db.py index 987b73d..170624f 100644 --- a/neat/db.py +++ b/neat/db.py @@ -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 diff --git a/neat/db_utils.py b/neat/db_utils.py index 37e2721..4808e74 100644 --- a/neat/db_utils.py +++ b/neat/db_utils.py @@ -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 diff --git a/tests/test_db_utils.py b/tests/test_db_utils.py index b2cfb8e..b84283d 100644 --- a/tests/test_db_utils.py +++ b/tests/test_db_utils.py @@ -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'