Adds use of OSMPOL_SQL_DATABASE_URI config param to connect to DB
[osm/POL.git] / osm_policy_module / core / database.py
index 212c13b..e522b8d 100644 (file)
 # For those usages not covered by the Apache License, Version 2.0 please
 # contact: bdiaz@whitestack.com or glavado@whitestack.com
 ##
+import datetime
 import logging
 
-from peewee import CharField, IntegerField, ForeignKeyField, Model, TextField, AutoField
-from playhouse.sqlite_ext import SqliteExtDatabase
+from peewee import CharField, IntegerField, ForeignKeyField, Model, TextField, AutoField, DateTimeField
+from playhouse.db_url import connect
 
 from osm_policy_module.core.config import Config
 
 log = logging.getLogger(__name__)
 cfg = Config.instance()
 
-db = SqliteExtDatabase('policy_module.db')
+db = connect(cfg.OSMPOL_SQL_DATABASE_URI)
 
 
 class BaseModel(Model):
@@ -43,12 +44,15 @@ class BaseModel(Model):
 
 class ScalingGroup(BaseModel):
     nsr_id = CharField()
+    vnf_member_index = IntegerField()
     name = CharField()
     content = TextField()
 
 
 class ScalingPolicy(BaseModel):
     name = CharField()
+    cooldown_time = IntegerField()
+    last_scale = DateTimeField(default=datetime.datetime.now)
     scaling_group = ForeignKeyField(ScalingGroup, related_name='scaling_policies')