Feature 10986: Autoheal switch and Autoscale switch
[osm/POL.git] / osm_policy_module / healing / service.py
index 7c6739c..4376852 100644 (file)
@@ -238,45 +238,48 @@ class HealingService:
         database.db.connect()
         try:
             if status == "alarm":
-                with database.db.atomic():
-                    alarm = HealingActionRepository.get(
-                        HealingAction.alarm_uuid == alarm_uuid
-                    )
-                    vnf_member_index = alarm.vnf_member_index
-                    vdur_name = alarm.vdur_name
-                    vdu_id = alarm.vdu_id
-                    nsr_id = alarm.nsr_id
-                    heal_type = alarm.recovery_action
-                    cooldown_time = alarm.cooldown_time
-                    count_index = alarm.count_index
-                    last_heal = alarm.last_heal
-                    day1 = alarm.day1
-                    vnfinstance_id = alarm.vnfinstance_id
-                    alarms = HealingActionRepository.list(
-                        HealingAction.vnf_member_index == vnf_member_index,
-                        HealingAction.vdur_name == vdur_name,
-                    )
-                    statuses = []
+                if self.conf.get("autoheal", "enabled") == "True":
+                    with database.db.atomic():
+                        alarm = HealingActionRepository.get(
+                            HealingAction.alarm_uuid == alarm_uuid
+                        )
+                        vnf_member_index = alarm.vnf_member_index
+                        vdur_name = alarm.vdur_name
+                        vdu_id = alarm.vdu_id
+                        nsr_id = alarm.nsr_id
+                        heal_type = alarm.recovery_action
+                        cooldown_time = alarm.cooldown_time
+                        count_index = alarm.count_index
+                        last_heal = alarm.last_heal
+                        day1 = alarm.day1
+                        vnfinstance_id = alarm.vnfinstance_id
+                        alarms = HealingActionRepository.list(
+                            HealingAction.vnf_member_index == vnf_member_index,
+                            HealingAction.vdur_name == vdur_name,
+                        )
+                        statuses = []
 
-                    for alarm in alarms:
-                        statuses.append(alarm.last_status)
-                    if (set(statuses) == {"alarm"}) or ("alarm" in statuses):
-                        delta = datetime.datetime.now() - last_heal
-                        if delta.total_seconds() > cooldown_time:
-                            await self.lcm_client.heal(
-                                nsr_id,
-                                vnfinstance_id,
-                                vdur_name,
-                                vdu_id,
-                                vnf_member_index,
-                                heal_type,
-                                day1,
-                                count_index,
-                            )
-                            last_heal = datetime.datetime.now()
-                            log.info("datetime.datetime.now %s", datetime.datetime.now)
-                            alarm.last_heal = last_heal
-                            alarm.save()
+                        for alarm in alarms:
+                            statuses.append(alarm.last_status)
+                        if (set(statuses) == {"alarm"}) or ("alarm" in statuses):
+                            delta = datetime.datetime.now() - last_heal
+                            if delta.total_seconds() > cooldown_time:
+                                await self.lcm_client.heal(
+                                    nsr_id,
+                                    vnfinstance_id,
+                                    vdur_name,
+                                    vdu_id,
+                                    vnf_member_index,
+                                    heal_type,
+                                    day1,
+                                    count_index,
+                                )
+                                last_heal = datetime.datetime.now()
+                                log.info(
+                                    "datetime.datetime.now %s", datetime.datetime.now
+                                )
+                                alarm.last_heal = last_heal
+                                alarm.save()
 
         except HealingAction.DoesNotExist:
             log.info("There is no healing action configured for alarm %s.", alarm_uuid)