X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Fcore%2Fdatabase.py;h=e763a5b73f18dbab830d6422be05549ea088daab;hb=326907a0151bed5641a9e9e241bc3b05bf0b71b9;hp=1d66264223f7891db81163728013199686faff30;hpb=341c33b98b4951c5d617e040cf856d4011a09266;p=osm%2FMON.git diff --git a/osm_mon/core/database.py b/osm_mon/core/database.py index 1d66264..e763a5b 100644 --- a/osm_mon/core/database.py +++ b/osm_mon/core/database.py @@ -25,14 +25,15 @@ import logging from peewee import * -from playhouse.sqlite_ext import SqliteExtDatabase +from playhouse.db_url import connect -from osm_mon.plugins.OpenStack.settings import Config +from osm_mon.core.settings import Config log = logging.getLogger(__name__) cfg = Config.instance() +cfg.read_environ() -db = SqliteExtDatabase('mon.db') +db = connect(cfg.DATABASE) class BaseModel(Model): @@ -48,11 +49,17 @@ class VimCredentials(BaseModel): user = CharField() password = CharField() tenant_name = CharField() - config = TextField(null=True) + config = TextField(default='{}') class Alarm(BaseModel): alarm_id = CharField() + threshold = FloatField() + operation = CharField() + metric_name = CharField() + vdu_name = CharField() + vnf_member_index = CharField() + ns_id = CharField() credentials = ForeignKeyField(VimCredentials, backref='alarms') @@ -82,12 +89,26 @@ class DatabaseManager: .where(VimCredentials.type == vim_type).get() return alarm.credentials - def save_alarm(self, alarm_id, vim_uuid): + def get_alarm(self, alarm_id, vim_type): + alarm = Alarm.select() \ + .where(Alarm.alarm_id == alarm_id) \ + .join(VimCredentials) \ + .where(VimCredentials.type == vim_type).get() + return alarm + + def save_alarm(self, alarm_id, vim_uuid, threshold=None, operation=None, metric_name=None, vdu_name=None, + vnf_member_index=None, ns_id=None): """Saves alarm. If a record with same id and vim_uuid exists, overwrite it.""" alarm = Alarm() alarm.alarm_id = alarm_id creds = VimCredentials.get(VimCredentials.uuid == vim_uuid) alarm.credentials = creds + alarm.threshold = threshold + alarm.operation = operation + alarm.metric_name = metric_name + alarm.vdu_name = vdu_name + alarm.vnf_member_index = vnf_member_index + alarm.ns_id = ns_id exists = Alarm.select(Alarm.alarm_id == alarm.alarm_id) \ .join(VimCredentials) \ .where(VimCredentials.uuid == vim_uuid)