Update from master
[osm/NBI.git] / osm_nbi / instance_topics.py
index 2eefb96..f553d64 100644 (file)
@@ -48,6 +48,7 @@ from osm_nbi import utils
 from re import (
     match,
 )  # For checking that additional parameter names are valid Jinja2 identifiers
+from osm_nbi.temporal.nbi_temporal import NbiTemporal
 
 __author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
 
@@ -413,7 +414,7 @@ class NsrTopic(BaseTopic):
         rollback.append({"topic": "nsrs", "_id": nsr_descriptor["id"]})
 
     def _add_vnfr_to_db(self, vnfr_descriptor, rollback, session):
-        self.format_on_new(
+        BaseTopic.format_on_new(
             vnfr_descriptor, session["project_id"], make_public=session["public"]
         )
         self.db.create("vnfrs", vnfr_descriptor)
@@ -885,7 +886,7 @@ class NsrTopic(BaseTopic):
                     # Name, mac-address and interface position is taken from VNFD
                     # and included into VNFR. By this way RO can process this information
                     # while creating the VDU.
-                    iface_fields = ("name", "mac-address", "position")
+                    iface_fields = ("name", "mac-address", "position", "ip-address")
                     vdu_iface = {
                         x: iface[x] for x in iface_fields if iface.get(x) is not None
                     }
@@ -1173,6 +1174,7 @@ class NsLcmOpTopic(BaseTopic):
     def __init__(self, db, fs, msg, auth):
         BaseTopic.__init__(self, db, fs, msg, auth)
         self.nsrtopic = NsrTopic(db, fs, msg, auth)
+        self.temporal = NbiTemporal()
 
     def _check_ns_operation(self, session, nsr, operation, indata):
         """
@@ -1313,7 +1315,6 @@ class NsLcmOpTopic(BaseTopic):
                 vnfd_id_2update = indata["changeVnfPackageData"]["vnfdId"]
 
                 if vnf_instance_id not in nsr["constituent-vnfr-ref"]:
-
                     raise EngineException(
                         f"Error in validating ns-update request: vnf {vnf_instance_id} does not "
                         f"belong to NS {ns_instance_id}",
@@ -1333,7 +1334,6 @@ class NsLcmOpTopic(BaseTopic):
 
                 # Check the given vnfd-id belongs to given vnf instance
                 if constituent_vnfd_id and (vnfd_id_2update != constituent_vnfd_id):
-
                     raise EngineException(
                         f"Error in validating ns-update request: vnfd-id {vnfd_id_2update} does not "
                         f"match with the vnfd-id: {constituent_vnfd_id} of VNF instance: {vnf_instance_id}",
@@ -1537,8 +1537,8 @@ class NsLcmOpTopic(BaseTopic):
             ivld.get("id"): set()
             for ivld in get_iterable(vnfd.get("int-virtual-link-desc"))
         }
-        for vdu in get_iterable(vnfd.get("vdu")):
-            for cpd in get_iterable(vnfd.get("int-cpd")):
+        for vdu in vnfd.get("vdu", {}):
+            for cpd in vdu.get("int-cpd", {}):
                 if cpd.get("int-virtual-link-desc"):
                     vnfd_ivlds_cpds[cpd.get("int-virtual-link-desc")] = cpd.get("id")
 
@@ -2327,8 +2327,21 @@ class NsLcmOpTopic(BaseTopic):
             self.db.create("nslcmops", nslcmop_desc)
             rollback.append({"topic": "nslcmops", "_id": _id})
             if not slice_object:
+                if "instantiate_params" in nsr:
+                    if "vimAccountId" in nsr["instantiate_params"]:
+                        vim = self._get_vim_account(
+                            vim_id=nsr["instantiate_params"]["vimAccountId"],
+                            session=session,
+                        )
+                        if vim["vim_type"] == "paas":
+                            self.logger.info("Starting {} workflow".format(operation))
+                            self.temporal.start_ns_workflow(nslcmop_desc)
+                            return _id, None
                 self.msg.write("ns", operation, nslcmop_desc)
             return _id, None
+        except ValidationError as e:  # TODO remove try Except, it is captured at nbi.py
+            raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY)
+            return _id, None
         except ValidationError as e:  # TODO remove try Except, it is captured at nbi.py
             raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY)
         # except DbException as e: