f7a90a98acae2489ecb9c8b3dab56f4b97a19b8e
[osm/MON.git] / policy_module / osm_policy_module / core / database.py
1 import logging
2
3 from peewee import *
4 from playhouse.sqlite_ext import SqliteExtDatabase
5
6 from osm_policy_module.core.config import Config
7
8 log = logging.getLogger(__name__)
9 cfg = Config.instance()
10
11 db = SqliteExtDatabase('policy_module.db')
12
13
14 class BaseModel(Model):
15 class Meta:
16 database = db
17
18
19 class ScalingRecord(BaseModel):
20 nsr_id = CharField()
21 name = CharField()
22 content = TextField()
23
24
25 class ScalingAlarm(BaseModel):
26 alarm_id = CharField()
27 action = CharField()
28 scaling_record = ForeignKeyField(ScalingRecord, related_name='scaling_alarms')
29
30
31 class DatabaseManager:
32 def create_tables(self):
33 try:
34 db.connect()
35 db.create_tables([ScalingRecord, ScalingAlarm])
36 db.close()
37 except Exception as e:
38 log.exception("Error creating tables: ")