+ error_text_list = []
+ tasks_name_ok = []
+ reached_timeout = False
+ now = time()
+
+ while pending_tasks:
+ _timeout = max(1, self.timeout_create - (time() - now)) # ensure not negative with max
+ step = "Waiting for k8scluster init tasks"
+ done, pending_tasks = await asyncio.wait(pending_tasks, timeout=_timeout,
+ return_when=asyncio.FIRST_COMPLETED)
+ if not done:
+ # timeout. Set timeout is reached and process pending as if they hase been finished
+ done = pending_tasks
+ pending_tasks = None
+ reached_timeout = True
+ for task in done:
+ task_name = task2name[task]
+ if reached_timeout:
+ exc = "Timeout"
+ elif task.cancelled():
+ exc = "Cancelled"
+ else:
+ exc = task.exception()
+
+ if exc:
+ error_text_list.append("Failing init {}: {}".format(task_name, exc))
+ db_k8scluster_update["_admin.{}.error_msg".format(task_name)] = str(exc)
+ db_k8scluster_update["_admin.{}.id".format(task_name)] = None
+ db_k8scluster_update["_admin.{}.operationalState".format(task_name)] = "ERROR"
+ self.logger.error(logging_text + "{} init fail: {}".format(task_name, exc),
+ exc_info=not isinstance(exc, (N2VCException, str)))
+ else:
+ k8s_id, uninstall_sw = task.result()
+ tasks_name_ok.append(task_name)
+ self.logger.debug(logging_text + "{} init success. id={} created={}".format(
+ task_name, k8s_id, uninstall_sw))
+ db_k8scluster_update["_admin.{}.error_msg".format(task_name)] = None
+ db_k8scluster_update["_admin.{}.id".format(task_name)] = k8s_id
+ db_k8scluster_update["_admin.{}.created".format(task_name)] = uninstall_sw
+ db_k8scluster_update["_admin.{}.operationalState".format(task_name)] = "ENABLED"
+ # update database
+ step = "Updating database for " + task_name
+ self.update_db_2("k8sclusters", k8scluster_id, db_k8scluster_update)
+ if tasks_name_ok:
+ operation_details = "ready for " + ", ".join(tasks_name_ok)
+ operation_state = "COMPLETED"
+ db_k8scluster_update["_admin.operationalState"] = "ENABLED" if not error_text_list else "DEGRADED"
+ operation_details += "; " + ";".join(error_text_list)