- 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))
+ pending_tasks[task] = "_admin.deployed.K8s.{}.".format(index)
+ index += 1
+ if not pending_tasks:
+ return
+ self.logger.debug(logging_text + 'Waiting for terminate pending tasks...')
+ pending_list = list(pending_tasks.keys())
+ while pending_list:
+ done_list, pending_list = await asyncio.wait(pending_list, timeout=30*60,
+ return_when=asyncio.FIRST_COMPLETED)
+ if not done_list: # timeout
+ for task in pending_list:
+ db_nsr_update[pending_tasks(task) + "detailed-status"] = "Timeout"
+ break
+ for task in done_list:
+ exc = task.exception()
+ if exc:
+ db_nsr_update[pending_tasks[task] + "detailed-status"] = "{}".format(exc)
+ else:
+ db_nsr_update[pending_tasks[task] + "kdu-instance"] = task.result()