+ elif command == "deleted":
+ return # TODO cleaning of task just in case should be done
+ elif topic == "cluster":
+ if command != "get_creds":
+ op_id = params["operation_id"]
+ cluster_id = params["cluster_id"]
+ db_cluster = self.db.get_one("clusters", {"_id": cluster_id})
+ op_params = self.get_operation_params(db_cluster, op_id)
+ db_content = {
+ "cluster": db_cluster,
+ }
+ if command == "create" or command == "created":
+ self.logger.debug("cluster_id = {}".format(cluster_id))
+ # db_vim = self.db.get_one("vim_accounts", {"_id": db_cluster["vim_account"]})
+ db_vim = self.db.get_one(
+ "vim_accounts", {"name": db_cluster["vim_account"]}
+ )
+ db_content["vim_account"] = db_vim
+ task = asyncio.ensure_future(
+ self.cluster.create(op_id, op_params, db_content)
+ )
+ self.lcm_tasks.register(
+ "cluster", cluster_id, op_id, "cluster_create", task
+ )
+ return
+ elif command == "delete" or command == "deleted":
+ task = asyncio.ensure_future(
+ self.cluster.delete(op_id, op_params, db_content)
+ )
+ self.lcm_tasks.register(
+ "cluster", cluster_id, op_id, "cluster_delete", task
+ )
+ return
+ elif command == "add" or command == "added":
+ profile_type = params["profile_type"]
+ profile_collection = self.profile_collection_mapping[profile_type]
+ db_profile = self.db.get_one(
+ profile_collection, {"_id": params["profile_id"]}
+ )
+ db_profile["profile_type"] = profile_type
+ db_content["profile"] = db_profile
+ task = asyncio.ensure_future(
+ self.cluster.attach_profile(op_id, op_params, db_content)
+ )
+ self.lcm_tasks.register(
+ "cluster", cluster_id, op_id, "profile_add", task
+ )
+ return
+ elif command == "remove" or command == "removed":
+ profile_type = params["profile_type"]
+ profile_collection = self.profile_collection_mapping[profile_type]
+ db_profile = self.db.get_one(
+ profile_collection, {"_id": params["profile_id"]}
+ )
+ db_profile["profile_type"] = profile_type
+ db_content["profile"] = db_profile
+ task = asyncio.ensure_future(
+ self.cluster.detach_profile(op_id, op_params, db_content)
+ )
+ self.lcm_tasks.register(
+ "cluster", cluster_id, op_id, "profile_remove", task
+ )
+ return
+ elif command == "register" or command == "registered":
+ task = asyncio.ensure_future(
+ self.cluster.register(op_id, op_params, db_content)
+ )
+ self.lcm_tasks.register(
+ "cluster", cluster_id, op_id, "cluster_register", task
+ )
+ return
+ elif command == "deregister" or command == "deregistered":
+ task = asyncio.ensure_future(
+ self.cluster.deregister(op_id, op_params, db_content)
+ )
+ self.lcm_tasks.register(
+ "cluster", cluster_id, op_id, "cluster_deregister", task
+ )
+ return
+ elif command == "get_creds":
+ cluster_id = params["_id"]
+ db_cluster = self.db.get_one("clusters", {"_id": cluster_id})
+ task = asyncio.ensure_future(self.cluster.get_creds(db_cluster))
+ self.lcm_tasks.register(
+ "cluster", cluster_id, cluster_id, "cluster_get_credentials", task
+ )
+ return
+ elif command == "upgrade" or command == "scale":
+ # db_vim = self.db.get_one("vim_accounts", {"_id": db_cluster["vim_account"]})
+ db_vim = self.db.get_one(
+ "vim_accounts", {"name": db_cluster["vim_account"]}
+ )
+ db_content["vim_account"] = db_vim
+ task = asyncio.ensure_future(
+ self.cluster.update(op_id, op_params, db_content)
+ )
+ self.lcm_tasks.register(
+ "cluster", cluster_id, op_id, "cluster_update", task
+ )
+ return
+ elif topic == "k8s_app":
+ op_id = params["operation_id"]
+ profile_id = params["profile_id"]
+ db_profile = self.db.get_one("k8sapp", {"_id": profile_id})
+ db_profile["profile_type"] = "applications"
+ op_params = self.get_operation_params(db_profile, op_id)
+ if command == "profile_create" or command == "profile_created":
+ self.logger.debug("Create k8s_app_id = {}".format(profile_id))
+ task = asyncio.ensure_future(
+ self.k8s_app.create(op_id, op_params, db_profile)
+ )
+ self.lcm_tasks.register(
+ "k8s_app", profile_id, op_id, "k8s_app_create", task
+ )
+ return
+ elif command == "delete" or command == "deleted":
+ self.logger.debug("Delete k8s_app_id = {}".format(profile_id))
+ task = asyncio.ensure_future(
+ self.k8s_app.delete(op_id, op_params, db_profile)
+ )
+ self.lcm_tasks.register(
+ "k8s_app", profile_id, op_id, "k8s_app_delete", task
+ )
+ return
+ elif topic == "k8s_resource":
+ op_id = params["operation_id"]
+ profile_id = params["profile_id"]
+ db_profile = self.db.get_one("k8sresource", {"_id": profile_id})
+ db_profile["profile_type"] = "managed-resources"
+ op_params = self.get_operation_params(db_profile, op_id)
+ if command == "profile_create" or command == "profile_created":
+ self.logger.debug("Create k8s_resource_id = {}".format(profile_id))
+ task = asyncio.ensure_future(
+ self.k8s_resource.create(op_id, op_params, db_profile)
+ )
+ self.lcm_tasks.register(
+ "k8s_resource",
+ profile_id,
+ op_id,
+ "k8s_resource_create",
+ task,
+ )
+ return
+ elif command == "delete" or command == "deleted":
+ self.logger.debug("Delete k8s_resource_id = {}".format(profile_id))
+ task = asyncio.ensure_future(
+ self.k8s_resource.delete(op_id, op_params, db_profile)
+ )
+ self.lcm_tasks.register(
+ "k8s_resource",
+ profile_id,
+ op_id,
+ "k8s_resource_delete",
+ task,
+ )
+ return
+
+ elif topic == "k8s_infra_controller":
+ op_id = params["operation_id"]
+ profile_id = params["profile_id"]
+ db_profile = self.db.get_one("k8sinfra_controller", {"_id": profile_id})
+ db_profile["profile_type"] = "infra-controllers"
+ op_params = self.get_operation_params(db_profile, op_id)
+ if command == "profile_create" or command == "profile_created":
+ self.logger.debug(
+ "Create k8s_infra_controller_id = {}".format(profile_id)
+ )
+ task = asyncio.ensure_future(
+ self.k8s_infra_controller.create(op_id, op_params, db_profile)
+ )
+ self.lcm_tasks.register(
+ "k8s_infra_controller",
+ profile_id,
+ op_id,
+ "k8s_infra_controller_create",
+ task,
+ )
+ return
+ elif command == "delete" or command == "deleted":
+ self.logger.debug(
+ "Delete k8s_infra_controller_id = {}".format(profile_id)
+ )
+ task = asyncio.ensure_future(
+ self.k8s_infra_controller.delete(op_id, op_params, db_profile)
+ )
+ self.lcm_tasks.register(
+ "k8s_infra_controller",
+ profile_id,
+ op_id,
+ "k8s_infra_controller_delete",
+ task,
+ )
+ return
+
+ elif topic == "k8s_infra_config":
+ op_id = params["operation_id"]
+ profile_id = params["profile_id"]
+ db_profile = self.db.get_one("k8sinfra_config", {"_id": profile_id})
+ db_profile["profile_type"] = "infra-configs"
+ op_params = self.get_operation_params(db_profile, op_id)
+ if command == "profile_create" or command == "profile_created":
+ self.logger.debug("Create k8s_infra_config_id = {}".format(profile_id))
+ task = asyncio.ensure_future(
+ self.k8s_infra_config.create(op_id, op_params, db_profile)
+ )
+ self.lcm_tasks.register(
+ "k8s_infra_config",
+ profile_id,
+ op_id,
+ "k8s_infra_config_create",
+ task,
+ )
+ return
+ elif command == "delete" or command == "deleted":
+ self.logger.debug("Delete k8s_infra_config_id = {}".format(profile_id))
+ task = asyncio.ensure_future(
+ self.k8s_infra_config.delete(op_id, op_params, db_profile)
+ )
+ self.lcm_tasks.register(
+ "k8s_infra_config",
+ profile_id,
+ op_id,
+ "k8s_infra_config_delete",
+ task,
+ )
+ return
+ elif topic == "oka":
+ op_id = params["operation_id"]
+ oka_id = params["oka_id"]
+ db_oka = self.db.get_one("okas", {"_id": oka_id})
+ op_params = self.get_operation_params(db_oka, op_id)
+ if command == "create":
+ task = asyncio.ensure_future(self.oka.create(op_id, op_params, db_oka))
+ self.lcm_tasks.register("oka", oka_id, op_id, "oka_create", task)
+ return
+ elif command == "edit":
+ task = asyncio.ensure_future(self.oka.edit(op_id, op_params, db_oka))
+ self.lcm_tasks.register("oka", oka_id, op_id, "oka_edit", task)
+ return
+ elif command == "delete":
+ task = asyncio.ensure_future(self.oka.delete(op_id, op_params, db_oka))
+ self.lcm_tasks.register("oka", oka_id, op_id, "oka_delete", task)
+ return
+ elif topic == "ksu":
+ op_id = params["operation_id"]
+ op_params = None
+ db_content = None
+ if not (command == "clone" or command == "move"):
+ # op_params is a list
+ # db_content is a list of KSU
+ db_content = []
+ op_params = []
+ for ksu_id in params["ksus_list"]:
+ db_ksu = self.db.get_one("ksus", {"_id": ksu_id})
+ db_content.append(db_ksu)
+ ksu_params = {}
+ if command == "delete":
+ ksu_params["profile"] = {}
+ ksu_params["profile"]["profile_type"] = db_ksu["profile"][
+ "profile_type"
+ ]
+ ksu_params["profile"]["_id"] = db_ksu["profile"]["_id"]
+ else:
+ ksu_params = self.get_operation_params(db_ksu, op_id)
+ # Update ksu_params["profile"] with profile name and age-pubkey
+ profile_type = ksu_params["profile"]["profile_type"]
+ profile_id = ksu_params["profile"]["_id"]
+ profile_collection = self.profile_collection_mapping[profile_type]
+ db_profile = self.db.get_one(
+ profile_collection, {"_id": profile_id}
+ )
+ ksu_params["profile"]["name"] = db_profile["name"]
+ ksu_params["profile"]["age_pubkey"] = db_profile.get(
+ "age_pubkey", ""
+ )
+ if command == "create" or command == "edit" or command == "edited":
+ # Update ksu_params["oka"] with sw_catalog_path (when missing)
+ for oka in ksu_params["oka"]:
+ if "sw_catalog_path" not in oka:
+ oka_id = oka["_id"]
+ db_oka = self.db.get_one("okas", {"_id": oka_id})
+ oka[
+ "sw_catalog_path"
+ ] = f"infra-controllers/{db_oka['git_name']}"
+ op_params.append(ksu_params)
+ else:
+ # db_content and op_params are single items
+ db_content = self.db.get_one("ksus", {"_id": params["_id"]})
+ db_content = db_ksu
+ op_params = self.get_operation_params(db_ksu, op_id)
+ if command == "create":
+ task = asyncio.ensure_future(
+ self.ksu.create(op_id, op_params, db_content)
+ )
+ self.lcm_tasks.register("ksu", ksu_id, op_id, "ksu_create", task)
+ return
+ elif command == "edit" or command == "edited":
+ task = asyncio.ensure_future(
+ self.ksu.edit(op_id, op_params, db_content)
+ )
+ self.lcm_tasks.register("ksu", ksu_id, op_id, "ksu_edit", task)
+ return
+ elif command == "delete":
+ task = asyncio.ensure_future(
+ self.ksu.delete(op_id, op_params, db_content)
+ )
+ self.lcm_tasks.register("ksu", ksu_id, op_id, "ksu_delete", task)
+ return
+ elif command == "clone":
+ task = asyncio.ensure_future(
+ self.ksu.clone(op_id, op_params, db_content)
+ )
+ self.lcm_tasks.register("ksu", ksu_id, op_id, "ksu_clone", task)
+ return
+ elif command == "move":
+ task = asyncio.ensure_future(
+ self.ksu.move(op_id, op_params, db_content)
+ )
+ self.lcm_tasks.register("ksu", ksu_id, op_id, "ksu_move", task)
+ return
+