self.logger = logging.getLogger("lcm.vim")
self.loop = loop
self.lcm_tasks = lcm_tasks
- self.ro_config = config["ro_config"]
+ self.ro_config = config["RO"]
super().__init__(msg, self.logger)
self.logger = logging.getLogger("lcm.vim")
self.loop = loop
self.lcm_tasks = lcm_tasks
- self.ro_config = config["ro_config"]
+ self.ro_config = config["RO"]
super().__init__(msg, self.logger)
raise
else:
# nothing to delete
- self.logger.error(logging_text + "Nohing to remove at RO")
+ self.logger.error(logging_text + "Nothing to remove at RO")
self.db.del_one("wim_accounts", {"_id": wim_id})
db_wim = None
self.logger.debug(logging_text + "Exit Ok")
self.logger = logging.getLogger("lcm.sdn")
self.loop = loop
self.lcm_tasks = lcm_tasks
- self.ro_config = config["ro_config"]
+ self.ro_config = config["RO"]
super().__init__(msg, self.logger)
logging_text = "Task sdn_delete={} ".format(sdn_id)
self.logger.debug(logging_text + "Enter")
- db_sdn = None
+ db_sdn = {}
db_sdn_update = {}
exc = None
step = "Getting sdn from db"
logging_text + "Skipping. There is not RO information at database"
)
self.db.del_one("sdns", {"_id": sdn_id})
- db_sdn = None
+ db_sdn = {}
self.logger.debug("sdn_delete task sdn_id={} Exit Ok".format(sdn_id))
return
task2name = {}
init_target = deep_get(db_k8scluster, ("_admin", "init"))
step = "Launching k8scluster init tasks"
- for task_name in ("helm-chart", "juju-bundle", "helm-chart-v3"):
+
+ k8s_deploy_methods = db_k8scluster.get("deployment_methods", {})
+ # for backwards compatibility and all-false case
+ if not any(k8s_deploy_methods.values()):
+ k8s_deploy_methods = {
+ "helm-chart": True,
+ "juju-bundle": True,
+ "helm-chart-v3": True,
+ }
+ deploy_methods = tuple(filter(k8s_deploy_methods.get, k8s_deploy_methods))
+
+ for task_name in deploy_methods:
if init_target and task_name not in init_target:
continue
task = asyncio.ensure_future(
)
return db_vca
+ async def _validate_vca(self, db_vca_id: str) -> None:
+ task = asyncio.ensure_future(
+ asyncio.wait_for(
+ self.n2vc.validate_vca(db_vca_id),
+ timeout=self.timeout_create,
+ )
+ )
+ await asyncio.wait([task], return_when=asyncio.FIRST_COMPLETED)
+ if task.exception():
+ raise task.exception()
+
+ def _is_vca_config_update(self, update_options) -> bool:
+ return any(
+ word in update_options.keys()
+ for word in [
+ "cacert",
+ "endpoints",
+ "lxd-cloud",
+ "lxd-credentials",
+ "k8s-cloud",
+ "k8s-credentials",
+ "model-config",
+ "user",
+ "secret",
+ ]
+ )
+
async def create(self, vca_content, order_id):
op_id = vca_content.pop("op_id", None)
if not self.lcm_tasks.lock_HA("vca", "create", op_id):
vca_id = vca_content["_id"]
self.logger.debug("Task vca_create={} {}".format(vca_id, "Enter"))
- db_vca = None
db_vca_update = {}
+ operation_state = "FAILED"
+ operation_details = ""
try:
self.logger.debug(
"Task vca_create={} {}".format(vca_id, "Getting vca from db")
)
db_vca = self._get_vca_by_id(vca_id)
- task = asyncio.ensure_future(
- asyncio.wait_for(
- self.n2vc.validate_vca(db_vca["_id"]),
- timeout=self.timeout_create,
- )
- )
-
- await asyncio.wait([task], return_when=asyncio.FIRST_COMPLETED)
- if task.exception():
- raise task.exception()
+ await self._validate_vca(db_vca["_id"])
self.logger.debug(
"Task vca_create={} {}".format(
vca_id, "vca registered and validated successfully"
self.logger.error("Task vca_create={} {}".format(vca_id, error_msg))
db_vca_update["_admin.operationalState"] = "ERROR"
db_vca_update["_admin.detailed-status"] = error_msg
- operation_state = "FAILED"
operation_details = error_msg
finally:
try:
)
self.lcm_tasks.remove("vca", vca_id, order_id)
+ async def edit(self, vca_content, order_id):
+ op_id = vca_content.pop("op_id", None)
+ if not self.lcm_tasks.lock_HA("vca", "edit", op_id):
+ return
+
+ vca_id = vca_content["_id"]
+ self.logger.debug("Task vca_edit={} {}".format(vca_id, "Enter"))
+
+ db_vca = None
+ db_vca_update = {}
+
+ operation_state = "FAILED"
+ operation_details = ""
+ try:
+ self.logger.debug(
+ "Task vca_edit={} {}".format(vca_id, "Getting vca from db")
+ )
+ db_vca = self._get_vca_by_id(vca_id)
+ if self._is_vca_config_update(vca_content):
+ await self._validate_vca(db_vca["_id"])
+ self.logger.debug(
+ "Task vca_edit={} {}".format(
+ vca_id, "vca registered and validated successfully"
+ )
+ )
+ db_vca_update["_admin.operationalState"] = "ENABLED"
+ db_vca_update["_admin.detailed-status"] = "Connectivity: ok"
+
+ operation_details = "Edited"
+ operation_state = "COMPLETED"
+
+ self.logger.debug(
+ "Task vca_edit={} {}".format(
+ vca_id, "Done. Result: {}".format(operation_state)
+ )
+ )
+
+ except Exception as e:
+ error_msg = "Failed with exception: {}".format(e)
+ self.logger.error("Task vca_edit={} {}".format(vca_id, error_msg))
+ db_vca_update["_admin.operationalState"] = "ERROR"
+ db_vca_update["_admin.detailed-status"] = error_msg
+ operation_state = "FAILED"
+ operation_details = error_msg
+ finally:
+ try:
+ self.update_db_2("vca", vca_id, db_vca_update)
+
+ # Register the operation and unlock
+ self.lcm_tasks.unlock_HA(
+ "vca",
+ "edit",
+ op_id,
+ operationState=operation_state,
+ detailed_status=operation_details,
+ )
+ except DbException as e:
+ self.logger.error(
+ "Task vca_edit={} {}".format(
+ vca_id, "Cannot update database: {}".format(e)
+ )
+ )
+ self.lcm_tasks.remove("vca", vca_id, order_id)
+
async def delete(self, vca_content, order_id):
# HA tasks and backward compatibility:
db_vca_update = {}
vca_id = vca_content["_id"]
+ operation_state = "FAILED"
+ operation_details = ""
+
try:
self.logger.debug(
"Task vca_delete={} {}".format(vca_id, "Deleting vca from db")
self.logger.error("Task vca_delete={} {}".format(vca_id, error_msg))
db_vca_update["_admin.operationalState"] = "ERROR"
db_vca_update["_admin.detailed-status"] = error_msg
- operation_state = "FAILED"
operation_details = error_msg
finally:
try: