Feature 10916 Remove VNF Instance from NS - NS Update
[osm/POL.git] / osm_policy_module / core / agent.py
index 95cc830..a73cd5b 100644 (file)
@@ -36,7 +36,7 @@ from osm_policy_module.core.config import Config
 
 log = logging.getLogger(__name__)
 
-ALLOWED_KAFKA_KEYS = ["instantiated", "scaled", "terminated", "notify_alarm"]
+ALLOWED_KAFKA_KEYS = ["instantiated", "scaled", "terminated", "notify_alarm", "vnf_terminated"]
 
 
 class PolicyModuleAgent:
@@ -78,6 +78,9 @@ class PolicyModuleAgent:
 
                 if key == "notify_alarm":
                     await self._handle_alarm_notification(msg)
+
+                if key == "vnf_terminated":
+                    await self._handle_vnf_terminated(msg)
             else:
                 log.debug("Key %s is not in ALLOWED_KAFKA_KEYS", key)
         except peewee.PeeweeException:
@@ -151,3 +154,21 @@ class PolicyModuleAgent:
                 "Current state is %s. Skipping...",
                 content["operationState"],
             )
+
+    async def _handle_vnf_terminated(self, content):
+        nsr_id = content['nsr_id']
+        vnf_member_index = content['vnf_member_index']
+        if (
+            content["operationState"] == "COMPLETED"
+            or content["operationState"] == "PARTIALLY_COMPLETED"
+        ):
+            log.info(
+                "Deleting policies of VNF with nsr_id: %s and vnf-member-index: %s"
+                % (nsr_id, vnf_member_index))
+            await self.autoscaling_service.delete_scaling_groups(nsr_id, vnf_member_index)
+            await self.alarming_service.delete_vnf_alarms(nsr_id, vnf_member_index)
+        else:
+            log.info(
+                "Network service is not in COMPLETED or PARTIALLY_COMPLETED state. "
+                "Current state is %s. Skipping...",
+                content['operationState'])