- if self.ng_ro:
- return await self._instantiate_ng_ro(logging_text, nsr_id, nsd, db_nsr, db_nslcmop, db_vnfrs,
- db_vnfds_ref, n2vc_key_list, stage, start_deploy,
- timeout_ns_deploy)
- # deploy RO
- # get vnfds, instantiate at RO
- for c_vnf in nsd.get("constituent-vnfd", ()):
- member_vnf_index = c_vnf["member-vnf-index"]
- vnfd = db_vnfds_ref[c_vnf['vnfd-id-ref']]
- vnfd_ref = vnfd["id"]
-
- stage[2] = "Creating vnfd='{}' member_vnf_index='{}' at RO".format(vnfd_ref, member_vnf_index)
- db_nsr_update["detailed-status"] = " ".join(stage)
- self.update_db_2("nsrs", nsr_id, db_nsr_update)
- self._write_op_status(nslcmop_id, stage)
-
- # self.logger.debug(logging_text + stage[2])
- vnfd_id_RO = "{}.{}.{}".format(nsr_id, RO_descriptor_number, member_vnf_index[:23])
- vnf_index_2_RO_id[member_vnf_index] = vnfd_id_RO
- RO_descriptor_number += 1
-
- # look position at deployed.RO.vnfd if not present it will be appended at the end
- for index, vnf_deployed in enumerate(db_nsr["_admin"]["deployed"]["RO"]["vnfd"]):
- if vnf_deployed["member-vnf-index"] == member_vnf_index:
- break
- else:
- index = len(db_nsr["_admin"]["deployed"]["RO"]["vnfd"])
- db_nsr["_admin"]["deployed"]["RO"]["vnfd"].append(None)
-
- # look if present
- RO_update = {"member-vnf-index": member_vnf_index}
- vnfd_list = await self.RO.get_list("vnfd", filter_by={"osm_id": vnfd_id_RO})
- if vnfd_list:
- RO_update["id"] = vnfd_list[0]["uuid"]
- self.logger.debug(logging_text + "vnfd='{}' member_vnf_index='{}' exists at RO. Using RO_id={}".
- format(vnfd_ref, member_vnf_index, vnfd_list[0]["uuid"]))
- else:
- vnfd_RO = self.vnfd2RO(vnfd, vnfd_id_RO, db_vnfrs[c_vnf["member-vnf-index"]].
- get("additionalParamsForVnf"), nsr_id)
- desc = await self.RO.create("vnfd", descriptor=vnfd_RO)
- RO_update["id"] = desc["uuid"]
- self.logger.debug(logging_text + "vnfd='{}' member_vnf_index='{}' created at RO. RO_id={}".format(
- vnfd_ref, member_vnf_index, desc["uuid"]))
- db_nsr_update["_admin.deployed.RO.vnfd.{}".format(index)] = RO_update
- db_nsr["_admin"]["deployed"]["RO"]["vnfd"][index] = RO_update
-
- # create nsd at RO
- nsd_ref = nsd["id"]
-
- stage[2] = "Creating nsd={} at RO".format(nsd_ref)
- db_nsr_update["detailed-status"] = " ".join(stage)
- self.update_db_2("nsrs", nsr_id, db_nsr_update)
- self._write_op_status(nslcmop_id, stage)
-
- # self.logger.debug(logging_text + stage[2])
- RO_osm_nsd_id = "{}.{}.{}".format(nsr_id, RO_descriptor_number, nsd_ref[:23])
- RO_descriptor_number += 1
- nsd_list = await self.RO.get_list("nsd", filter_by={"osm_id": RO_osm_nsd_id})
- if nsd_list:
- db_nsr_update["_admin.deployed.RO.nsd_id"] = RO_nsd_uuid = nsd_list[0]["uuid"]
- self.logger.debug(logging_text + "nsd={} exists at RO. Using RO_id={}".format(
- nsd_ref, RO_nsd_uuid))
- else:
- nsd_RO = deepcopy(nsd)
- nsd_RO["id"] = RO_osm_nsd_id
- nsd_RO.pop("_id", None)
- nsd_RO.pop("_admin", None)
- for c_vnf in nsd_RO.get("constituent-vnfd", ()):
- member_vnf_index = c_vnf["member-vnf-index"]
- c_vnf["vnfd-id-ref"] = vnf_index_2_RO_id[member_vnf_index]
- for c_vld in nsd_RO.get("vld", ()):
- for cp in c_vld.get("vnfd-connection-point-ref", ()):
- member_vnf_index = cp["member-vnf-index-ref"]
- cp["vnfd-id-ref"] = vnf_index_2_RO_id[member_vnf_index]
-
- desc = await self.RO.create("nsd", descriptor=nsd_RO)
- db_nsr_update["_admin.nsState"] = "INSTANTIATED"
- db_nsr_update["_admin.deployed.RO.nsd_id"] = RO_nsd_uuid = desc["uuid"]
- self.logger.debug(logging_text + "nsd={} created at RO. RO_id={}".format(nsd_ref, RO_nsd_uuid))
- self.update_db_2("nsrs", nsr_id, db_nsr_update)
-
- # Crate ns at RO
- stage[2] = "Creating nsd={} at RO".format(nsd_ref)
- db_nsr_update["detailed-status"] = " ".join(stage)
- self.update_db_2("nsrs", nsr_id, db_nsr_update)
- self._write_op_status(nslcmop_id, stage)
-
- # if present use it unless in error status
- RO_nsr_id = deep_get(db_nsr, ("_admin", "deployed", "RO", "nsr_id"))
- if RO_nsr_id:
- try:
- stage[2] = "Looking for existing ns at RO"
- db_nsr_update["detailed-status"] = " ".join(stage)
- self.update_db_2("nsrs", nsr_id, db_nsr_update)
- self._write_op_status(nslcmop_id, stage)
- # self.logger.debug(logging_text + stage[2] + " RO_ns_id={}".format(RO_nsr_id))
- desc = await self.RO.show("ns", RO_nsr_id)
-
- except ROclient.ROClientException as e:
- if e.http_code != HTTPStatus.NOT_FOUND:
- raise
- RO_nsr_id = db_nsr_update["_admin.deployed.RO.nsr_id"] = None
- if RO_nsr_id:
- ns_status, ns_status_info = self.RO.check_ns_status(desc)
- db_nsr_update["_admin.deployed.RO.nsr_status"] = ns_status
- if ns_status == "ERROR":
- stage[2] = "Deleting ns at RO. RO_ns_id={}".format(RO_nsr_id)
- self.logger.debug(logging_text + stage[2])
- await self.RO.delete("ns", RO_nsr_id)
- RO_nsr_id = db_nsr_update["_admin.deployed.RO.nsr_id"] = None
- if not RO_nsr_id:
- stage[2] = "Checking dependencies"
- db_nsr_update["detailed-status"] = " ".join(stage)
- self.update_db_2("nsrs", nsr_id, db_nsr_update)
- self._write_op_status(nslcmop_id, stage)
- # self.logger.debug(logging_text + stage[2])
-
- # check if VIM is creating and wait look if previous tasks in process
- task_name, task_dependency = self.lcm_tasks.lookfor_related("vim_account", ns_params["vimAccountId"])
- if task_dependency:
- stage[2] = "Waiting for related tasks '{}' to be completed".format(task_name)
- self.logger.debug(logging_text + stage[2])
- await asyncio.wait(task_dependency, timeout=3600)
- if ns_params.get("vnf"):
- for vnf in ns_params["vnf"]:
- if "vimAccountId" in vnf:
- task_name, task_dependency = self.lcm_tasks.lookfor_related("vim_account",
- vnf["vimAccountId"])
- if task_dependency:
- stage[2] = "Waiting for related tasks '{}' to be completed.".format(task_name)
- self.logger.debug(logging_text + stage[2])
- await asyncio.wait(task_dependency, timeout=3600)
-
- stage[2] = "Checking instantiation parameters."
- RO_ns_params = self._ns_params_2_RO(ns_params, nsd, db_vnfds_ref, db_vnfrs, n2vc_key_list)
- stage[2] = "Deploying ns at VIM."
- db_nsr_update["detailed-status"] = " ".join(stage)
- self.update_db_2("nsrs", nsr_id, db_nsr_update)
- self._write_op_status(nslcmop_id, stage)
-
- desc = await self.RO.create("ns", descriptor=RO_ns_params, name=db_nsr["name"], scenario=RO_nsd_uuid)
- RO_nsr_id = db_nsr_update["_admin.deployed.RO.nsr_id"] = desc["uuid"]
- db_nsr_update["_admin.nsState"] = "INSTANTIATED"
- db_nsr_update["_admin.deployed.RO.nsr_status"] = "BUILD"
- self.logger.debug(logging_text + "ns created at RO. RO_id={}".format(desc["uuid"]))
-
- # wait until NS is ready
- stage[2] = "Waiting VIM to deploy ns."
- db_nsr_update["detailed-status"] = " ".join(stage)
- self.update_db_2("nsrs", nsr_id, db_nsr_update)
- self._write_op_status(nslcmop_id, stage)
- detailed_status_old = None
- self.logger.debug(logging_text + stage[2] + " RO_ns_id={}".format(RO_nsr_id))
-
- old_desc = None
- while time() <= start_deploy + timeout_ns_deploy:
- desc = await self.RO.show("ns", RO_nsr_id)