OSMENG-992 - Implement create model activity

in NS Workflow.

An exception is raised if model already exists

Change-Id: I84dd89850b28287dfefb1abc0d158cc72cd4eb34
Signed-off-by: Patricia Reinoso <patricia.reinoso@canonical.com>
Signed-off-by: Mark Beierl <mark.beierl@canonical.com>
diff --git a/osm_lcm/temporal/ns_activities.py b/osm_lcm/temporal/ns_activities.py
index 1a2925c..6834eec 100644
--- a/osm_lcm/temporal/ns_activities.py
+++ b/osm_lcm/temporal/ns_activities.py
@@ -18,12 +18,14 @@
 from time import time
 from temporalio import activity
 from osm_common.temporal_constants import (
-    ACTIVITY_UPDATE_NS_STATE,
     ACTIVITY_CHECK_NS_INSTANTIATION_FINISHED,
-    ACTIVITY_PREPARE_VNF_RECORDS,
     ACTIVITY_DEPLOY_NS,
+    ACTIVITY_GET_MODEL_INFO,
+    ACTIVITY_PREPARE_VNF_RECORDS,
+    ACTIVITY_UPDATE_NS_STATE,
 )
 from osm_common.dataclasses.temporal_dataclasses import (
+    ModelInfo,
     NsInstantiateInput,
     UpdateNsStateInput,
     VduInstantiateInput,
@@ -45,7 +47,7 @@
 
     async def deploy_vnf(self, vnfr: dict):
         vim_id = vnfr.get("vim-account-id")
-        model_name = vnfr.get("namespace")
+        model_name = "model-name"
         vnfd_id = vnfr["vnfd-id"]
         vnfd = self.db.get_one("vnfds", {"_id": vnfd_id})
         sw_image_descs = vnfd.get("sw-image-desc")
@@ -106,6 +108,32 @@
         for vnfr in vnfrs:
             self._prepare_vnf_record(vnfr)
 
+    @activity.defn(name=ACTIVITY_GET_MODEL_INFO)
+    async def get_model_info(
+        self, ns_instantiate_input: NsInstantiateInput
+    ) -> ModelInfo:
+        """Returns a ModelInfo. Contains VIM ID and model name.
+
+        Collaborators:
+            DB Read:           nsrs
+
+        Raises  (Retryable):
+            DbException         If the target DB record does not exist or DB is not reachable.
+
+        Activity Lifecycle:
+            This activity will not report a heartbeat due to its
+            short-running nature.
+
+            As this is a direct DB update, it is not recommended to have
+            any specific retry policy
+
+        """
+        ns_uuid = ns_instantiate_input.ns_uuid
+        nsr = self.db.get_one("nsrs", {"_id": ns_uuid})
+        vim_uuid = nsr.get("datacenter")
+        model_name = self._get_namespace(ns_uuid, vim_uuid)
+        return ModelInfo(vim_uuid, model_name)
+
     def _get_namespace(self, ns_id: str, vim_id: str) -> str:
         """The NS namespace is the combination if the NS ID and the VIM ID."""
         return ns_id[-12:] + "-" + vim_id[-12:]