Coverity-CWE 330: Use of Insufficiently Random Values (137944 Cryptographically weak...
[osm/POL.git] / osm_policy_module / core / database.py
index 7bf11d8..6423b5e 100644 (file)
@@ -98,6 +98,10 @@ class VnfAlarm(BaseModel):
     nsr_id = CharField()
     vnf_member_index = CharField()
     vdu_name = CharField()
+    last_action = CharField(default="insufficient-data")
+    id_suffix = IntegerField()
+    ok_ack = BooleanField(default=False)
+    alarm_ack = BooleanField(default=False)
 
 
 class AlarmAction(BaseModel):
@@ -106,6 +110,22 @@ class AlarmAction(BaseModel):
     alarm = ForeignKeyField(VnfAlarm, related_name="actions", on_delete="CASCADE")
 
 
+class HealingAction(BaseModel):
+    alarm_id = CharField()
+    recovery_action = CharField()
+    alarm_uuid = CharField(unique=True)
+    nsr_id = CharField()
+    vnfinstance_id = CharField()
+    vnf_member_index = CharField()
+    vdur_name = CharField()
+    vdu_id = CharField()
+    cooldown_time = IntegerField()
+    count_index = IntegerField()
+    last_heal = DateTimeField(default=datetime.datetime.now)
+    last_status = CharField(default="insufficient-data")
+    day1 = BooleanField(default=False)
+
+
 class DatabaseManager:
     def __init__(self, config: Config):
         db.initialize(connect(config.get("sql", "database_uri")))
@@ -121,7 +141,7 @@ class DatabaseManager:
 class ScalingAlarmRepository:
     @staticmethod
     def list(*expressions) -> Iterable[ScalingAlarm]:
-        return ScalingAlarm.select().where(*expressions)
+        return ScalingAlarm.select().where(*expressions).__iter__()
 
     @staticmethod
     def get(*expressions, join_classes: List = None) -> ScalingAlarm:
@@ -139,7 +159,7 @@ class ScalingAlarmRepository:
 class ScalingGroupRepository:
     @staticmethod
     def list(*expressions) -> Iterable[ScalingGroup]:
-        return ScalingGroup.select().where(*expressions)
+        return ScalingGroup.select().where(*expressions).__iter__()
 
     @staticmethod
     def get(*expressions) -> ScalingGroup:
@@ -157,7 +177,7 @@ class ScalingPolicyRepository:
         if join_classes:
             for join_class in join_classes:
                 query = query.join(join_class)
-        return query.where(*expressions)
+        return query.where(*expressions).__iter__()
 
     @staticmethod
     def get(*expressions, join_classes: List = None) -> ScalingPolicy:
@@ -179,7 +199,7 @@ class ScalingCriteriaRepository:
         if join_classes:
             for join_class in join_classes:
                 query = query.join(join_class)
-        return query.where(*expressions)
+        return query.where(*expressions).__iter__()
 
     @staticmethod
     def get(*expressions, join_classes: List = None) -> ScalingCriteria:
@@ -197,7 +217,7 @@ class ScalingCriteriaRepository:
 class VnfAlarmRepository:
     @staticmethod
     def list(*expressions) -> Iterable[VnfAlarm]:
-        return VnfAlarm.select().where(*expressions)
+        return VnfAlarm.select().where(*expressions).__iter__()
 
     @staticmethod
     def get(*expressions) -> VnfAlarm:
@@ -211,7 +231,7 @@ class VnfAlarmRepository:
 class AlarmActionRepository:
     @staticmethod
     def list(*expressions) -> Iterable[AlarmAction]:
-        return AlarmAction.select().where(*expressions)
+        return AlarmAction.select().where(*expressions).__iter__()
 
     @staticmethod
     def get(*expressions) -> AlarmAction:
@@ -220,3 +240,22 @@ class AlarmActionRepository:
     @staticmethod
     def create(**query) -> AlarmAction:
         return AlarmAction.create(**query)
+
+
+class HealingActionRepository:
+    @staticmethod
+    def list(*expressions) -> Iterable[HealingAction]:
+        log.info(
+            "### Printing healing action db alarm {}".format(
+                HealingAction.select().where(*expressions)
+            )
+        )
+        return HealingAction.select().where(*expressions).__iter__()
+
+    @staticmethod
+    def get(*expressions) -> HealingAction:
+        return HealingAction.select().where(*expressions).get()
+
+    @staticmethod
+    def create(**query) -> HealingAction:
+        return HealingAction.create(**query)