+ step = "Checking kdu from vnf: {} - member-vnf-index: {}".format(vnfd_ref, member_vnf_index)
+ self.logger.debug(logging_text + step)
+ if vnfd.get("kdu"):
+ step = "vnf: {} has kdus".format(vnfd_ref)
+ self.logger.debug(logging_text + step)
+ for vnfr_name, vnfr_data in db_vnfrs.items():
+ if vnfr_data["vnfd-ref"] == vnfd["id"]:
+ if vnfr_data.get("additionalParamsForVnf"):
+ desc_params = self._format_additional_params(vnfr_data["additionalParamsForVnf"])
+ break
+ else:
+ raise LcmException("VNF descriptor not found with id: {}".format(vnfr_data["vnfd-ref"]))
+ self.logger.debug(logging_text + step)
+
+ for kdur in vnfr.get("kdur"):
+ index = 0
+ for k8scluster in db_k8scluster:
+ if kdur["k8s-cluster"]["id"] == k8scluster["_id"]:
+ cluster_uuid = k8scluster["cluster-uuid"]
+ break
+ else:
+ raise LcmException("K8scluster not found with id: {}".format(kdur["k8s-cluster"]["id"]))
+ self.logger.debug(logging_text + step)
+
+ step = "Instantiate KDU {} in k8s cluster {}".format(kdur["kdu-name"], cluster_uuid)
+ self.logger.debug(logging_text + step)
+ for kdu in vnfd.get("kdu"):
+ if kdu.get("name") == kdur["kdu-name"]:
+ break
+ else:
+ raise LcmException("KDU not found with name: {} in VNFD {}".format(kdur["kdu-name"],
+ vnfd["name"]))
+ self.logger.debug(logging_text + step)
+ kdumodel = None
+ k8sclustertype = None
+ if kdu.get("helm-chart"):
+ kdumodel = kdu["helm-chart"]
+ k8sclustertype = "chart"
+ elif kdu.get("juju-bundle"):
+ kdumodel = kdu["juju-bundle"]
+ k8sclustertype = "juju"
+ k8s_instace_info = {"kdu-instance": None, "k8scluster-uuid": cluster_uuid,
+ "vnfr-id": vnfr["id"], "k8scluster-type": k8sclustertype,
+ "kdu-name": kdur["kdu-name"], "kdu-model": kdumodel}
+ db_nsr_update["_admin.deployed.K8s"].append(k8s_instace_info)
+ db_dict = {"collection": "nsrs", "filter": {"_id": nsr_id}, "path": "_admin.deployed.K8s."
+ "{}".format(index)}
+ if k8sclustertype == "chart":
+ task = self.k8sclusterhelm.install(cluster_uuid=cluster_uuid,
+ kdu_model=kdumodel, atomic=True, params=desc_params,
+ db_dict=db_dict, timeout=300)
+ else:
+ # TODO I need the juju connector in place
+ pass
+ task_list.append(task)
+ index += 1
+ self.update_db_2("nsrs", nsr_id, db_nsr_update)
+ done = None
+ pending = None
+ if len(task_list) > 0:
+ self.logger.debug('Waiting for terminate pending tasks...')
+ done, pending = await asyncio.wait(task_list, timeout=3600)
+ if not pending:
+ for fut in done:
+ k8s_instance = fut.result()
+ k8s_instace_info = {"kdu-instance": k8s_instance, "k8scluster-uuid": cluster_uuid,
+ "vnfr-id": vnfr["id"], "k8scluster-type": k8sclustertype,
+ "kdu-name": kdur["kdu-name"], "kdu-model": kdumodel}
+ vnf_update.append(k8s_instace_info)
+ self.logger.debug('All tasks finished...')
+ else:
+ self.logger.info('There are pending tasks: {}'.format(pending))
+
+ db_nsr_update["_admin.deployed.K8s"] = vnf_update
+ except Exception as e:
+ self.logger.critical(logging_text + "Exit Exception {} while '{}': {}".format(type(e).__name__, step, e))
+ raise LcmException("{} Exit Exception {} while '{}': {}".format(logging_text, type(e).__name__, step, e))
+ finally:
+ # TODO Write in data base
+ if db_nsr_update:
+ self.update_db_2("nsrs", nsr_id, db_nsr_update)
+ def _deploy_n2vc(self, logging_text, db_nsr, db_vnfr, nslcmop_id, nsr_id, nsi_id, vnfd_id, vdu_id,
+ kdu_name, member_vnf_index, vdu_index, vdu_name, deploy_params, descriptor_config,
+ base_folder, task_instantiation_list):
+ # launch instantiate_N2VC in a asyncio task and register task object
+ # Look where information of this charm is at database <nsrs>._admin.deployed.VCA
+ # if not found, create one entry and update database
+
+ # fill db_nsr._admin.deployed.VCA.<index>
+ vca_index = -1
+ for vca_index, vca_deployed in enumerate(db_nsr["_admin"]["deployed"]["VCA"]):
+ if not vca_deployed:
+ continue
+ if vca_deployed.get("member-vnf-index") == member_vnf_index and \
+ vca_deployed.get("vdu_id") == vdu_id and \
+ vca_deployed.get("kdu_name") == kdu_name and \
+ vca_deployed.get("vdu_count_index", 0) == vdu_index:
+ break
+ else:
+ # not found, create one.
+ vca_deployed = {
+ "member-vnf-index": member_vnf_index,
+ "vdu_id": vdu_id,
+ "kdu_name": kdu_name,
+ "vdu_count_index": vdu_index,
+ "operational-status": "init", # TODO revise
+ "detailed-status": "", # TODO revise
+ "step": "initial-deploy", # TODO revise
+ "vnfd_id": vnfd_id,
+ "vdu_name": vdu_name,
+ }
+ vca_index += 1
+ self.update_db_2("nsrs", nsr_id, {"_admin.deployed.VCA.{}".format(vca_index): vca_deployed})
+ db_nsr["_admin"]["deployed"]["VCA"].append(vca_deployed)
+
+ # Launch task
+ task_n2vc = asyncio.ensure_future(
+ self.instantiate_N2VC(
+ logging_text=logging_text,
+ vca_index=vca_index,
+ nsi_id=nsi_id,
+ db_nsr=db_nsr,
+ db_vnfr=db_vnfr,
+ vdu_id=vdu_id,
+ kdu_name=kdu_name,
+ vdu_index=vdu_index,
+ deploy_params=deploy_params,
+ config_descriptor=descriptor_config,
+ base_folder=base_folder,
+ )
+ )
+ self.lcm_tasks.register("ns", nsr_id, nslcmop_id, "instantiate_N2VC-{}".format(vca_index), task_n2vc)
+ task_instantiation_list.append(task_n2vc)