else:
return await self.check_dummy_operation(op_id, op_params, content)
- def decrypting_key(self, content):
- # This deep copy is for to be passed to ODU workflows.
- cluster_copy = copy.deepcopy(content)
+ def decrypted_copy(self, content, fields=["age_pubkey", "age_privkey"]):
+ # This deep copy is intended to be passed to ODU workflows.
+ content_copy = copy.deepcopy(content)
# decrypting the key
self.db.encrypt_decrypt_fields(
- cluster_copy,
+ content_copy,
"decrypt",
- ["age_pubkey", "age_privkey"],
+ fields,
schema_version="1.11",
- salt=cluster_copy["_id"],
+ salt=content_copy["_id"],
)
- db_cluster_copy = {
- "cluster": cluster_copy,
- }
- return db_cluster_copy
+ return content_copy
class ClusterLcm(GitOpsLcm):
async def create(self, params, order_id):
self.logger.info("cluster Create Enter")
- # To get the cluster details
+ # To get the cluster and op ids
cluster_id = params["cluster_id"]
- db_cluster = self.db.get_one("clusters", {"_id": cluster_id})
-
- # To get the operation params details
op_id = params["operation_id"]
- op_params = self.get_operation_params(db_cluster, op_id)
# To initialize the operation states
self.initialize_operation(cluster_id, op_id)
- # To copy the cluster content and decrypting the key to use in workflows
- db_cluster_copy = self.decrypting_key(db_cluster)
+ # To get the cluster
+ db_cluster = self.db.get_one("clusters", {"_id": cluster_id})
+
+ # To get the operation params details
+ op_params = self.get_operation_params(db_cluster, op_id)
+
+ # To copy the cluster content and decrypting fields to use in workflows
+ workflow_content = {
+ "cluster": self.decrypted_copy(db_cluster),
+ }
# To get the vim account details
db_vim = self.db.get_one("vim_accounts", {"name": db_cluster["vim_account"]})
- db_cluster_copy["vim_account"] = db_vim
+ workflow_content["vim_account"] = db_vim
_, workflow_name = await self.odu.launch_workflow(
- "create_cluster", op_id, op_params, db_cluster_copy
+ "create_cluster", op_id, op_params, workflow_content
)
self.logger.info("workflow_name is :{}".format(workflow_name))
# Clean items used in the workflow, no matter if the workflow succeeded
clean_status, clean_msg = await self.odu.clean_items_workflow(
- "create_cluster", op_id, op_params, db_cluster_copy
+ "create_cluster", op_id, op_params, workflow_content
)
self.logger.info(
f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
if workflow_status:
resource_status, resource_msg = await self.check_resource_status(
- "create_cluster", op_id, op_params, db_cluster_copy
+ "create_cluster", op_id, op_params, workflow_content
)
self.logger.info(
"resource_status is :{} and resource_msg is :{}".format(
async def delete(self, params, order_id):
self.logger.info("cluster delete Enter")
- # To get the cluster details
+ # To get the cluster and op ids
cluster_id = params["cluster_id"]
- db_cluster = self.db.get_one("clusters", {"_id": cluster_id})
-
- # To get the operation params details
op_id = params["operation_id"]
- op_params = self.get_operation_params(db_cluster, op_id)
# To initialize the operation states
self.initialize_operation(cluster_id, op_id)
- # To copy the cluster content and decrypting the key to use in workflows
- db_cluster_copy = self.decrypting_key(db_cluster)
+ # To get the cluster
+ db_cluster = self.db.get_one("clusters", {"_id": cluster_id})
+
+ # To get the operation params details
+ op_params = self.get_operation_params(db_cluster, op_id)
+
+ # To copy the cluster content and decrypting fields to use in workflows
+ workflow_content = {
+ "cluster": self.decrypted_copy(db_cluster),
+ }
# TODO: workaround until NBI rejects cluster deletion requests for registered clusters
# This if clause will be removed
return await self.deregister(params, order_id)
_, workflow_name = await self.odu.launch_workflow(
- "delete_cluster", op_id, op_params, db_cluster_copy
+ "delete_cluster", op_id, op_params, workflow_content
)
self.logger.info("workflow_name is :{}".format(workflow_name))
# Clean items used in the workflow or in the cluster, no matter if the workflow succeeded
clean_status, clean_msg = await self.odu.clean_items_workflow(
- "delete_cluster", op_id, op_params, db_cluster_copy
+ "delete_cluster", op_id, op_params, workflow_content
)
self.logger.info(
f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
if workflow_status:
resource_status, resource_msg = await self.check_resource_status(
- "delete_cluster", op_id, op_params, db_cluster_copy
+ "delete_cluster", op_id, op_params, workflow_content
)
self.logger.info(
"resource_status is :{} and resource_msg is :{}".format(
async def attach_profile(self, params, order_id):
self.logger.info("profile attach Enter")
- # To get the cluster details
+ # To get the cluster and op ids
cluster_id = params["cluster_id"]
- db_cluster = self.db.get_one("clusters", {"_id": cluster_id})
- # content = {
- # "cluster": db_cluster,
- # }
-
- # To get the operation params details
op_id = params["operation_id"]
- op_params = self.get_operation_params(db_cluster, op_id)
# To initialize the operation states
self.initialize_operation(cluster_id, op_id)
- # To copy the cluster content and decrypting the key to use in workflows
- db_cluster_copy = self.decrypting_key(db_cluster)
+ # To get the cluster
+ db_cluster = self.db.get_one("clusters", {"_id": cluster_id})
+
+ # To get the operation params details
+ op_params = self.get_operation_params(db_cluster, op_id)
+
+ # To copy the cluster content and decrypting fields to use in workflows
+ workflow_content = {
+ "cluster": self.decrypted_copy(db_cluster),
+ }
# To get the profile details
profile_id = params["profile_id"]
db_profile = self.db.get_one(profile_collection, {"_id": profile_id})
db_profile["profile_type"] = profile_type
# content["profile"] = db_profile
- db_cluster_copy["profile"] = db_profile
+ workflow_content["profile"] = db_profile
_, workflow_name = await self.odu.launch_workflow(
- "attach_profile_to_cluster", op_id, op_params, db_cluster_copy
+ "attach_profile_to_cluster", op_id, op_params, workflow_content
)
self.logger.info("workflow_name is :{}".format(workflow_name))
if workflow_status:
resource_status, resource_msg = await self.check_resource_status(
- "attach_profile_to_cluster", op_id, op_params, db_cluster_copy
+ "attach_profile_to_cluster", op_id, op_params, workflow_content
)
self.logger.info(
"resource_status is :{} and resource_msg is :{}".format(
async def detach_profile(self, params, order_id):
self.logger.info("profile dettach Enter")
- # To get the cluster details
+ # To get the cluster and op ids
cluster_id = params["cluster_id"]
- db_cluster = self.db.get_one("clusters", {"_id": cluster_id})
- # content = {
- # "cluster": db_cluster,
- # }
-
- # To get the operation params details
op_id = params["operation_id"]
- op_params = self.get_operation_params(db_cluster, op_id)
# To initialize the operation states
self.initialize_operation(cluster_id, op_id)
- # To copy the cluster content and decrypting the key to use in workflows
- db_cluster_copy = self.decrypting_key(db_cluster)
+ # To get the cluster
+ db_cluster = self.db.get_one("clusters", {"_id": cluster_id})
+
+ # To get the operation params details
+ op_params = self.get_operation_params(db_cluster, op_id)
+
+ # To copy the cluster content and decrypting fields to use in workflows
+ workflow_content = {
+ "cluster": self.decrypted_copy(db_cluster),
+ }
# To get the profile details
profile_id = params["profile_id"]
db_profile = self.db.get_one(profile_collection, {"_id": profile_id})
db_profile["profile_type"] = profile_type
# content["profile"] = db_profile
- db_cluster_copy["profile"] = db_profile
+ workflow_content["profile"] = db_profile
_, workflow_name = await self.odu.launch_workflow(
- "detach_profile_from_cluster", op_id, op_params, db_cluster_copy
+ "detach_profile_from_cluster", op_id, op_params, workflow_content
)
self.logger.info("workflow_name is :{}".format(workflow_name))
if workflow_status:
resource_status, resource_msg = await self.check_resource_status(
- "detach_profile_from_cluster", op_id, op_params, db_cluster_copy
+ "detach_profile_from_cluster", op_id, op_params, workflow_content
)
self.logger.info(
"resource_status is :{} and resource_msg is :{}".format(
async def register(self, params, order_id):
self.logger.info("cluster register enter")
- # To get the cluster details
+ # To get the cluster and op ids
cluster_id = params["cluster_id"]
- db_cluster = self.db.get_one("clusters", {"_id": cluster_id})
- # content = {
- # "cluster": db_cluster,
- # }
-
- # To get the operation params details
op_id = params["operation_id"]
- op_params = self.get_operation_params(db_cluster, op_id)
# To initialize the operation states
self.initialize_operation(cluster_id, op_id)
- # To copy the cluster content and decrypting the key to use in workflows
- db_cluster_copy = self.decrypting_key(db_cluster)
+ # To get the cluster
+ db_cluster = self.db.get_one("clusters", {"_id": cluster_id})
+
+ # To get the operation params details
+ op_params = self.get_operation_params(db_cluster, op_id)
+
+ # To copy the cluster content and decrypting fields to use in workflows
+ workflow_content = {
+ "cluster": self.decrypted_copy(db_cluster),
+ }
_, workflow_name = await self.odu.launch_workflow(
- "register_cluster", op_id, op_params, db_cluster_copy
+ "register_cluster", op_id, op_params, workflow_content
)
self.logger.info("workflow_name is :{}".format(workflow_name))
# Clean items used in the workflow, no matter if the workflow succeeded
clean_status, clean_msg = await self.odu.clean_items_workflow(
- "register_cluster", op_id, op_params, db_cluster_copy
+ "register_cluster", op_id, op_params, workflow_content
)
self.logger.info(
f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
if workflow_status:
resource_status, resource_msg = await self.check_resource_status(
- "register_cluster", op_id, op_params, db_cluster_copy
+ "register_cluster", op_id, op_params, workflow_content
)
self.logger.info(
"resource_status is :{} and resource_msg is :{}".format(
async def deregister(self, params, order_id):
self.logger.info("cluster deregister enter")
- # To get the cluster details
+ # To get the cluster and op ids
cluster_id = params["cluster_id"]
- db_cluster = self.db.get_one("clusters", {"_id": cluster_id})
- # content = {
- # "cluster": db_cluster,
- # }
-
- # To get the operation params details
op_id = params["operation_id"]
- op_params = self.get_operation_params(db_cluster, op_id)
# To initialize the operation states
self.initialize_operation(cluster_id, op_id)
- # To copy the cluster content and decrypting the key to use in workflows
- db_cluster_copy = self.decrypting_key(db_cluster)
+ # To get the cluster
+ db_cluster = self.db.get_one("clusters", {"_id": cluster_id})
+
+ # To get the operation params details
+ op_params = self.get_operation_params(db_cluster, op_id)
+
+ # To copy the cluster content and decrypting fields to use in workflows
+ workflow_content = {
+ "cluster": self.decrypted_copy(db_cluster),
+ }
_, workflow_name = await self.odu.launch_workflow(
- "deregister_cluster", op_id, op_params, db_cluster_copy
+ "deregister_cluster", op_id, op_params, workflow_content
)
self.logger.info("workflow_name is :{}".format(workflow_name))
# Clean items used in the workflow or in the cluster, no matter if the workflow succeeded
clean_status, clean_msg = await self.odu.clean_items_workflow(
- "deregister_cluster", op_id, op_params, db_cluster_copy
+ "deregister_cluster", op_id, op_params, workflow_content
)
self.logger.info(
f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
if workflow_status:
resource_status, resource_msg = await self.check_resource_status(
- "deregister_cluster", op_id, op_params, db_cluster_copy
+ "deregister_cluster", op_id, op_params, workflow_content
)
self.logger.info(
"resource_status is :{} and resource_msg is :{}".format(
op_id = params["operation_id"]
op_params = self.get_operation_params(db_cluster, op_id)
- db_cluster_copy = self.decrypting_key(db_cluster)
+ # To copy the cluster content and decrypting fields to use in workflows
+ workflow_content = {
+ "cluster": self.decrypted_copy(db_cluster),
+ }
# vim account details
db_vim = self.db.get_one("vim_accounts", {"name": db_cluster["vim_account"]})
- db_cluster_copy["vim_account"] = db_vim
+ workflow_content["vim_account"] = db_vim
_, workflow_name = await self.odu.launch_workflow(
- "update_cluster", op_id, op_params, db_cluster_copy
+ "update_cluster", op_id, op_params, workflow_content
)
workflow_status, workflow_msg = await self.odu.check_workflow_status(
workflow_name
# Clean items used in the workflow, no matter if the workflow succeeded
clean_status, clean_msg = await self.odu.clean_items_workflow(
- "update_cluster", op_id, op_params, db_cluster_copy
+ "update_cluster", op_id, op_params, workflow_content
)
self.logger.info(
f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
)
if workflow_status:
resource_status, resource_msg = await self.check_resource_status(
- "update_cluster", op_id, op_params, db_cluster_copy
+ "update_cluster", op_id, op_params, workflow_content
)
self.logger.info(
"Resource Status: {} Resource Message: {}".format(