| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 12 | # implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | __author__ = ( |
| 17 | "Shrinithi R <shrinithi.r@tataelxsi.co.in>", |
| 18 | "Shahithya Y <shahithya.y@tataelxsi.co.in>", |
| 19 | ) |
| 20 | |
| rshri | c356494 | 2024-11-12 18:12:38 +0000 | [diff] [blame] | 21 | import copy |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 22 | import logging |
| yshah | d940c65 | 2024-10-17 06:11:12 +0000 | [diff] [blame] | 23 | from time import time |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 24 | import traceback |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 25 | from osm_lcm.lcm_utils import LcmBase |
| 26 | from copy import deepcopy |
| 27 | from osm_lcm import odu_workflows |
| 28 | from osm_lcm import vim_sdn |
| 29 | |
| 30 | |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 31 | class GitOpsLcm(LcmBase): |
| garciadeblas | ea865ff | 2024-11-20 12:42:49 +0100 | [diff] [blame] | 32 | db_collection = "gitops" |
| 33 | |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 34 | def __init__(self, msg, lcm_tasks, config): |
| 35 | self.logger = logging.getLogger("lcm.gitops") |
| 36 | self.lcm_tasks = lcm_tasks |
| 37 | self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config) |
| 38 | self._checkloop_kustomization_timeout = 900 |
| 39 | self._checkloop_resource_timeout = 900 |
| 40 | self._workflows = {} |
| 41 | super().__init__(msg, self.logger) |
| 42 | |
| 43 | async def check_dummy_operation(self, op_id, op_params, content): |
| 44 | self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") |
| 45 | return True, "OK" |
| 46 | |
| garciadeblas | ea865ff | 2024-11-20 12:42:49 +0100 | [diff] [blame] | 47 | def initialize_operation(self, item_id, op_id): |
| 48 | db_item = self.db.get_one(self.db_collection, {"_id": item_id}) |
| 49 | operation = next( |
| 50 | (op for op in db_item.get("operationHistory", []) if op["op_id"] == op_id), |
| 51 | None, |
| 52 | ) |
| 53 | operation["workflowState"] = "PROCESSING" |
| 54 | operation["resourceState"] = "NOT_READY" |
| 55 | operation["operationState"] = "IN_PROGRESS" |
| 56 | operation["gitOperationInfo"] = None |
| 57 | db_item["current_operation"] = operation["op_id"] |
| 58 | self.db.set_one(self.db_collection, {"_id": item_id}, db_item) |
| 59 | |
| garciadeblas | 7eae6f4 | 2024-11-08 10:41:38 +0100 | [diff] [blame] | 60 | def update_operation_history( |
| 61 | self, content, workflow_status=None, resource_status=None |
| 62 | ): |
| 63 | self.logger.info( |
| 64 | f"Update Operation History in DB. Workflow status: {workflow_status}. Resource status: {resource_status}" |
| 65 | ) |
| 66 | self.logger.debug(f"Content: {content}") |
| 67 | |
| 68 | op_id = content["current_operation"] |
| 69 | self.logger.debug("OP_id: {}".format(op_id)) |
| 70 | op_num = 0 |
| 71 | for operation in content["operationHistory"]: |
| 72 | self.logger.debug("Operations: {}".format(operation)) |
| 73 | if operation["op_id"] == op_id: |
| 74 | self.logger.debug("Found operation number: {}".format(op_num)) |
| 75 | now = time() |
| 76 | if workflow_status: |
| 77 | content["operationHistory"][op_num]["workflowState"] = "COMPLETED" |
| 78 | content["operationHistory"][op_num]["result"] = True |
| 79 | else: |
| 80 | content["operationHistory"][op_num]["workflowState"] = "ERROR" |
| 81 | content["operationHistory"][op_num]["operationState"] = "FAILED" |
| 82 | content["operationHistory"][op_num]["result"] = False |
| 83 | |
| 84 | if resource_status: |
| 85 | content["operationHistory"][op_num]["resourceState"] = "READY" |
| 86 | content["operationHistory"][op_num]["operationState"] = "COMPLETED" |
| 87 | content["operationHistory"][op_num]["result"] = True |
| 88 | else: |
| 89 | content["operationHistory"][op_num]["resourceState"] = "NOT_READY" |
| 90 | content["operationHistory"][op_num]["operationState"] = "FAILED" |
| 91 | content["operationHistory"][op_num]["result"] = False |
| 92 | |
| 93 | content["operationHistory"][op_num]["endDate"] = now |
| 94 | break |
| 95 | op_num += 1 |
| 96 | self.logger.debug("content: {}".format(content)) |
| 97 | |
| 98 | return content |
| 99 | |
| 100 | async def common_check_list(self, checkings_list, db_collection, db_item): |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 101 | try: |
| 102 | for checking in checkings_list: |
| 103 | if checking["enable"]: |
| 104 | status, message = await self.odu.readiness_loop( |
| 105 | item=checking["item"], |
| 106 | name=checking["name"], |
| 107 | namespace=checking["namespace"], |
| 108 | flag=checking["flag"], |
| 109 | timeout=checking["timeout"], |
| 110 | ) |
| 111 | if not status: |
| 112 | return status, message |
| garciadeblas | 7eae6f4 | 2024-11-08 10:41:38 +0100 | [diff] [blame] | 113 | else: |
| 114 | db_item["resourceState"] = checking["resourceState"] |
| 115 | db_item = self.update_operation_history( |
| 116 | db_item, "COMPLETED", checking["resourceState"] |
| 117 | ) |
| 118 | self.db.set_one(db_collection, {"_id": db_item["_id"]}, db_item) |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 119 | except Exception as e: |
| 120 | self.logger.debug(traceback.format_exc()) |
| 121 | self.logger.debug(f"Exception: {e}", exc_info=True) |
| 122 | return False, f"Unexpected exception: {e}" |
| 123 | return True, "OK" |
| 124 | |
| 125 | async def check_resource_status(self, key, op_id, op_params, content): |
| 126 | self.logger.info( |
| 127 | f"Check resource status. Key: {key}. Operation: {op_id}. Params: {op_params}. Content: {content}" |
| 128 | ) |
| 129 | check_resource_function = self._workflows.get(key, {}).get( |
| 130 | "check_resource_function" |
| 131 | ) |
| 132 | self.logger.info("check_resource function : {}".format(check_resource_function)) |
| 133 | if check_resource_function: |
| 134 | return await check_resource_function(op_id, op_params, content) |
| 135 | else: |
| 136 | return await self.check_dummy_operation(op_id, op_params, content) |
| 137 | |
| rshri | c356494 | 2024-11-12 18:12:38 +0000 | [diff] [blame] | 138 | def decrypting_key(self, content): |
| 139 | # This deep copy is for to be passed to ODU workflows. |
| 140 | cluster_copy = copy.deepcopy(content) |
| 141 | |
| 142 | # decrypting the key |
| 143 | self.db.encrypt_decrypt_fields( |
| 144 | cluster_copy, |
| 145 | "decrypt", |
| 146 | ["age_pubkey", "age_privkey"], |
| 147 | schema_version="1.11", |
| 148 | salt=cluster_copy["_id"], |
| 149 | ) |
| 150 | db_cluster_copy = { |
| 151 | "cluster": cluster_copy, |
| 152 | } |
| 153 | return db_cluster_copy |
| 154 | |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 155 | |
| 156 | class ClusterLcm(GitOpsLcm): |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 157 | db_collection = "clusters" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 158 | |
| 159 | def __init__(self, msg, lcm_tasks, config): |
| 160 | """ |
| 161 | Init, Connect to database, filesystem storage, and messaging |
| 162 | :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', |
| 163 | :return: None |
| 164 | """ |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 165 | super().__init__(msg, lcm_tasks, config) |
| 166 | self._workflows = { |
| 167 | "create_cluster": { |
| 168 | "check_resource_function": self.check_create_cluster, |
| 169 | }, |
| garciadeblas | b0a42c2 | 2024-11-13 16:00:10 +0100 | [diff] [blame] | 170 | "register_cluster": { |
| 171 | "check_resource_function": self.check_register_cluster, |
| 172 | }, |
| 173 | "update_cluster": { |
| 174 | "check_resource_function": self.check_update_cluster, |
| 175 | }, |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 176 | } |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 177 | self.regist = vim_sdn.K8sClusterLcm(msg, self.lcm_tasks, config) |
| 178 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 179 | async def create(self, op_id, op_params, content): |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 180 | self.logger.info("cluster Create Enter") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 181 | db_cluster = content["cluster"] |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 182 | |
| rshri | c356494 | 2024-11-12 18:12:38 +0000 | [diff] [blame] | 183 | db_cluster_copy = self.decrypting_key(db_cluster) |
| 184 | |
| 185 | # vim account details |
| 186 | db_vim = self.db.get_one("vim_accounts", {"name": db_cluster["vim_account"]}) |
| 187 | db_cluster_copy["vim_account"] = db_vim |
| 188 | |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 189 | _, workflow_name = await self.odu.launch_workflow( |
| rshri | c356494 | 2024-11-12 18:12:38 +0000 | [diff] [blame] | 190 | "create_cluster", op_id, op_params, db_cluster_copy |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 191 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 192 | self.logger.info("workflow_name is :{}".format(workflow_name)) |
| 193 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 194 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 195 | workflow_name |
| 196 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 197 | self.logger.info( |
| 198 | "workflow_status is :{} and workflow_msg is :{}".format( |
| 199 | workflow_status, workflow_msg |
| 200 | ) |
| 201 | ) |
| 202 | if workflow_status: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 203 | db_cluster["state"] = "CREATED" |
| 204 | db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 205 | else: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 206 | db_cluster["state"] = "FAILED_CREATION" |
| 207 | db_cluster["resourceState"] = "ERROR" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 208 | # has to call update_operation_history return content |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 209 | db_cluster = self.update_operation_history(db_cluster, workflow_status, None) |
| 210 | self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 211 | |
| garciadeblas | 28bff0f | 2024-09-16 12:53:07 +0200 | [diff] [blame] | 212 | # Clean items used in the workflow, no matter if the workflow succeeded |
| 213 | clean_status, clean_msg = await self.odu.clean_items_workflow( |
| rshri | c356494 | 2024-11-12 18:12:38 +0000 | [diff] [blame] | 214 | "create_cluster", op_id, op_params, db_cluster_copy |
| garciadeblas | 28bff0f | 2024-09-16 12:53:07 +0200 | [diff] [blame] | 215 | ) |
| 216 | self.logger.info( |
| 217 | f"clean_status is :{clean_status} and clean_msg is :{clean_msg}" |
| 218 | ) |
| 219 | |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 220 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 221 | resource_status, resource_msg = await self.check_resource_status( |
| rshri | c356494 | 2024-11-12 18:12:38 +0000 | [diff] [blame] | 222 | "create_cluster", op_id, op_params, db_cluster_copy |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 223 | ) |
| 224 | self.logger.info( |
| 225 | "resource_status is :{} and resource_msg is :{}".format( |
| 226 | resource_status, resource_msg |
| 227 | ) |
| 228 | ) |
| 229 | if resource_status: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 230 | db_cluster["resourceState"] = "READY" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 231 | else: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 232 | db_cluster["resourceState"] = "ERROR" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 233 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 234 | db_cluster["operatingState"] = "IDLE" |
| 235 | db_cluster = self.update_operation_history( |
| 236 | db_cluster, workflow_status, resource_status |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 237 | ) |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 238 | db_cluster["current_operation"] = None |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 239 | self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) |
| 240 | self.update_profile_state(db_cluster, workflow_status, resource_status) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 241 | return |
| 242 | |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 243 | async def check_create_cluster(self, op_id, op_params, content): |
| garciadeblas | 7eae6f4 | 2024-11-08 10:41:38 +0100 | [diff] [blame] | 244 | self.logger.info( |
| 245 | f"check_create_cluster Operation {op_id}. Params: {op_params}." |
| 246 | ) |
| 247 | # self.logger.debug(f"Content: {content}") |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 248 | db_cluster = content["cluster"] |
| 249 | cluster_name = db_cluster["git_name"].lower() |
| 250 | cluster_kustomization_name = cluster_name |
| 251 | db_vim_account = content["vim_account"] |
| 252 | cloud_type = db_vim_account["vim_type"] |
| 253 | nodepool_name = "" |
| 254 | if cloud_type == "aws": |
| 255 | nodepool_name = f"{cluster_name}-nodegroup" |
| 256 | cluster_name = f"{cluster_name}-cluster" |
| 257 | elif cloud_type == "gcp": |
| 258 | nodepool_name = f"nodepool-{cluster_name}" |
| 259 | bootstrap = op_params.get("bootstrap", True) |
| 260 | if cloud_type in ("azure", "gcp", "aws"): |
| 261 | checkings_list = [ |
| 262 | { |
| 263 | "item": "kustomization", |
| 264 | "name": cluster_kustomization_name, |
| 265 | "namespace": "managed-resources", |
| 266 | "flag": "Ready", |
| 267 | "timeout": self._checkloop_kustomization_timeout, |
| 268 | "enable": True, |
| garciadeblas | 7eae6f4 | 2024-11-08 10:41:38 +0100 | [diff] [blame] | 269 | "resourceState": "IN_PROGRESS.KUSTOMIZATION_READY", |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 270 | }, |
| 271 | { |
| 272 | "item": f"cluster_{cloud_type}", |
| 273 | "name": cluster_name, |
| 274 | "namespace": "", |
| 275 | "flag": "Synced", |
| 276 | "timeout": self._checkloop_resource_timeout, |
| 277 | "enable": True, |
| garciadeblas | 7eae6f4 | 2024-11-08 10:41:38 +0100 | [diff] [blame] | 278 | "resourceState": "IN_PROGRESS.RESOURCE_SYNCED.CLUSTER", |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 279 | }, |
| 280 | { |
| 281 | "item": f"cluster_{cloud_type}", |
| 282 | "name": cluster_name, |
| 283 | "namespace": "", |
| 284 | "flag": "Ready", |
| 285 | "timeout": self._checkloop_resource_timeout, |
| 286 | "enable": True, |
| garciadeblas | 7eae6f4 | 2024-11-08 10:41:38 +0100 | [diff] [blame] | 287 | "resourceState": "IN_PROGRESS.RESOURCE_READY.CLUSTER", |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 288 | }, |
| 289 | { |
| 290 | "item": "kustomization", |
| 291 | "name": f"{cluster_kustomization_name}-bstrp-fluxctrl", |
| 292 | "namespace": "managed-resources", |
| 293 | "flag": "Ready", |
| 294 | "timeout": self._checkloop_kustomization_timeout, |
| 295 | "enable": bootstrap, |
| garciadeblas | 7eae6f4 | 2024-11-08 10:41:38 +0100 | [diff] [blame] | 296 | "resourceState": "IN_PROGRESS.BOOTSTRAP_OK", |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 297 | }, |
| 298 | ] |
| 299 | else: |
| 300 | return False, "Not suitable VIM account to check cluster status" |
| 301 | if nodepool_name: |
| 302 | nodepool_check = { |
| 303 | "item": f"nodepool_{cloud_type}", |
| 304 | "name": nodepool_name, |
| 305 | "namespace": "", |
| 306 | "flag": "Ready", |
| 307 | "timeout": self._checkloop_resource_timeout, |
| 308 | "enable": True, |
| garciadeblas | 7eae6f4 | 2024-11-08 10:41:38 +0100 | [diff] [blame] | 309 | "resourceState": "IN_PROGRESS.RESOURCE_READY.NODEPOOL", |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 310 | } |
| 311 | checkings_list.insert(3, nodepool_check) |
| garciadeblas | 7eae6f4 | 2024-11-08 10:41:38 +0100 | [diff] [blame] | 312 | return await self.common_check_list(checkings_list, "clusters", db_cluster) |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 313 | |
| garciadeblas | b0a42c2 | 2024-11-13 16:00:10 +0100 | [diff] [blame] | 314 | async def check_register_cluster(self, op_id, op_params, content): |
| 315 | self.logger.info( |
| 316 | f"check_register_cluster Operation {op_id}. Params: {op_params}." |
| 317 | ) |
| 318 | # self.logger.debug(f"Content: {content}") |
| 319 | db_cluster = content["cluster"] |
| 320 | cluster_name = db_cluster["git_name"].lower() |
| 321 | cluster_kustomization_name = cluster_name |
| 322 | bootstrap = op_params.get("bootstrap", True) |
| 323 | checkings_list = [ |
| 324 | { |
| 325 | "item": "kustomization", |
| 326 | "name": f"{cluster_kustomization_name}-bstrp-fluxctrl", |
| 327 | "namespace": "managed-resources", |
| 328 | "flag": "Ready", |
| 329 | "timeout": self._checkloop_kustomization_timeout, |
| 330 | "enable": bootstrap, |
| 331 | "resourceState": "IN_PROGRESS.BOOTSTRAP_OK", |
| 332 | }, |
| 333 | ] |
| 334 | return await self.common_check_list(checkings_list, "clusters", db_cluster) |
| 335 | |
| 336 | async def check_update_cluster(self, op_id, op_params, content): |
| 337 | self.logger.info( |
| 338 | f"check_create_cluster Operation {op_id}. Params: {op_params}." |
| 339 | ) |
| 340 | # self.logger.debug(f"Content: {content}") |
| 341 | db_cluster = content["cluster"] |
| 342 | cluster_name = db_cluster["git_name"].lower() |
| 343 | cluster_kustomization_name = cluster_name |
| 344 | db_vim_account = content["vim_account"] |
| 345 | cloud_type = db_vim_account["vim_type"] |
| 346 | nodepool_name = "" |
| 347 | if cloud_type == "aws": |
| 348 | nodepool_name = f"{cluster_name}-nodegroup" |
| 349 | cluster_name = f"{cluster_name}-cluster" |
| 350 | elif cloud_type == "gcp": |
| 351 | nodepool_name = f"nodepool-{cluster_name}" |
| 352 | if cloud_type in ("azure", "gcp", "aws"): |
| 353 | checkings_list = [ |
| 354 | { |
| 355 | "item": "kustomization", |
| 356 | "name": cluster_kustomization_name, |
| 357 | "namespace": "managed-resources", |
| 358 | "flag": "Ready", |
| 359 | "timeout": self._checkloop_kustomization_timeout, |
| 360 | "enable": True, |
| 361 | "resourceState": "IN_PROGRESS.KUSTOMIZATION_READY", |
| 362 | }, |
| 363 | { |
| 364 | "item": f"cluster_{cloud_type}", |
| 365 | "name": cluster_name, |
| 366 | "namespace": "", |
| 367 | "flag": "Synced", |
| 368 | "timeout": self._checkloop_resource_timeout, |
| 369 | "enable": True, |
| 370 | "resourceState": "IN_PROGRESS.RESOURCE_SYNCED.CLUSTER", |
| 371 | }, |
| 372 | { |
| 373 | "item": f"cluster_{cloud_type}", |
| 374 | "name": cluster_name, |
| 375 | "namespace": "", |
| 376 | "flag": "Ready", |
| 377 | "timeout": self._checkloop_resource_timeout, |
| 378 | "enable": True, |
| 379 | "resourceState": "IN_PROGRESS.RESOURCE_READY.CLUSTER", |
| 380 | }, |
| 381 | ] |
| 382 | else: |
| 383 | return False, "Not suitable VIM account to check cluster status" |
| 384 | if nodepool_name: |
| 385 | nodepool_check = { |
| 386 | "item": f"nodepool_{cloud_type}", |
| 387 | "name": nodepool_name, |
| 388 | "namespace": "", |
| 389 | "flag": "Ready", |
| 390 | "timeout": self._checkloop_resource_timeout, |
| 391 | "enable": True, |
| 392 | "resourceState": "IN_PROGRESS.RESOURCE_READY.NODEPOOL", |
| 393 | } |
| 394 | checkings_list.append(nodepool_check) |
| 395 | return await self.common_check_list(checkings_list, "clusters", db_cluster) |
| 396 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 397 | def update_profile_state(self, db_cluster, workflow_status, resource_status): |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 398 | profiles = [ |
| 399 | "infra_controller_profiles", |
| 400 | "infra_config_profiles", |
| 401 | "app_profiles", |
| 402 | "resource_profiles", |
| 403 | ] |
| 404 | profiles_collection = { |
| 405 | "infra_controller_profiles": "k8sinfra_controller", |
| 406 | "infra_config_profiles": "k8sinfra_config", |
| 407 | "app_profiles": "k8sapp", |
| 408 | "resource_profiles": "k8sresource", |
| 409 | } |
| 410 | for profile_type in profiles: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 411 | profile_id = db_cluster[profile_type] |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 412 | self.logger.info("profile id is : {}".format(profile_id)) |
| 413 | db_collection = profiles_collection[profile_type] |
| 414 | self.logger.info("the db_collection is :{}".format(db_collection)) |
| 415 | db_profile = self.db.get_one(db_collection, {"_id": profile_id}) |
| 416 | self.logger.info("the db_profile is :{}".format(db_profile)) |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 417 | db_profile["state"] = db_cluster["state"] |
| 418 | db_profile["resourceState"] = db_cluster["resourceState"] |
| 419 | db_profile["operatingState"] = db_cluster["operatingState"] |
| rshri | c356494 | 2024-11-12 18:12:38 +0000 | [diff] [blame] | 420 | db_profile["age_pubkey"] = db_cluster["age_pubkey"] |
| 421 | db_profile["age_privkey"] = db_profile["age_privkey"] |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 422 | db_profile = self.update_operation_history( |
| 423 | db_profile, workflow_status, resource_status |
| 424 | ) |
| 425 | self.logger.info("the db_profile is :{}".format(db_profile)) |
| 426 | self.db.set_one(db_collection, {"_id": db_profile["_id"]}, db_profile) |
| 427 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 428 | async def delete(self, op_id, op_params, content): |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 429 | self.logger.info("cluster delete Enter") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 430 | db_cluster = content["cluster"] |
| garciadeblas | 1247081 | 2024-11-18 10:33:12 +0100 | [diff] [blame] | 431 | if db_cluster["created"] == "false": |
| 432 | return await self.deregister(op_id, op_params, content) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 433 | |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 434 | _, workflow_name = await self.odu.launch_workflow( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 435 | "delete_cluster", op_id, op_params, content |
| 436 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 437 | self.logger.info("workflow_name is :{}".format(workflow_name)) |
| 438 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 439 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 440 | workflow_name |
| 441 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 442 | self.logger.info( |
| 443 | "workflow_status is :{} and workflow_msg is :{}".format( |
| 444 | workflow_status, workflow_msg |
| 445 | ) |
| 446 | ) |
| 447 | if workflow_status: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 448 | db_cluster["state"] = "DELETED" |
| 449 | db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 450 | else: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 451 | db_cluster["state"] = "FAILED_DELETION" |
| 452 | db_cluster["resourceState"] = "ERROR" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 453 | # has to call update_operation_history return content |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 454 | db_cluster = self.update_operation_history(db_cluster, workflow_status, None) |
| 455 | self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 456 | |
| 457 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 458 | resource_status, resource_msg = await self.check_resource_status( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 459 | "delete_cluster", op_id, op_params, content |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 460 | ) |
| 461 | self.logger.info( |
| 462 | "resource_status is :{} and resource_msg is :{}".format( |
| 463 | resource_status, resource_msg |
| 464 | ) |
| 465 | ) |
| 466 | if resource_status: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 467 | db_cluster["resourceState"] = "READY" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 468 | else: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 469 | db_cluster["resourceState"] = "ERROR" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 470 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 471 | db_cluster["operatingState"] = "IDLE" |
| 472 | db_cluster = self.update_operation_history( |
| 473 | db_cluster, workflow_status, resource_status |
| 474 | ) |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 475 | db_cluster["current_operation"] = None |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 476 | self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 477 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 478 | # To delete it from DB |
| 479 | if db_cluster["state"] == "DELETED": |
| 480 | self.delete_cluster(db_cluster) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 481 | return |
| 482 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 483 | def delete_cluster(self, db_cluster): |
| 484 | # Actually, item_content is equal to db_cluster |
| 485 | # item_content = self.db.get_one("clusters", {"_id": db_cluster["_id"]}) |
| 486 | # self.logger.debug("item_content is : {}".format(item_content)) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 487 | |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 488 | # detach profiles |
| 489 | update_dict = None |
| 490 | profiles_to_detach = [ |
| 491 | "infra_controller_profiles", |
| 492 | "infra_config_profiles", |
| 493 | "app_profiles", |
| 494 | "resource_profiles", |
| 495 | ] |
| 496 | profiles_collection = { |
| 497 | "infra_controller_profiles": "k8sinfra_controller", |
| 498 | "infra_config_profiles": "k8sinfra_config", |
| 499 | "app_profiles": "k8sapp", |
| 500 | "resource_profiles": "k8sresource", |
| 501 | } |
| 502 | for profile_type in profiles_to_detach: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 503 | if db_cluster.get(profile_type): |
| garciadeblas | c255285 | 2024-10-22 12:39:32 +0200 | [diff] [blame] | 504 | self.logger.debug("the profile_type is :{}".format(profile_type)) |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 505 | profile_ids = db_cluster[profile_type] |
| garciadeblas | c255285 | 2024-10-22 12:39:32 +0200 | [diff] [blame] | 506 | self.logger.debug("the profile_ids is :{}".format(profile_ids)) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 507 | profile_ids_copy = deepcopy(profile_ids) |
| garciadeblas | c255285 | 2024-10-22 12:39:32 +0200 | [diff] [blame] | 508 | self.logger.debug( |
| 509 | "the profile_ids_copy is :{}".format(profile_ids_copy) |
| 510 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 511 | for profile_id in profile_ids_copy: |
| garciadeblas | c255285 | 2024-10-22 12:39:32 +0200 | [diff] [blame] | 512 | self.logger.debug("the profile_id is :{}".format(profile_id)) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 513 | db_collection = profiles_collection[profile_type] |
| garciadeblas | c255285 | 2024-10-22 12:39:32 +0200 | [diff] [blame] | 514 | self.logger.debug("the db_collection is :{}".format(db_collection)) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 515 | db_profile = self.db.get_one(db_collection, {"_id": profile_id}) |
| garciadeblas | c255285 | 2024-10-22 12:39:32 +0200 | [diff] [blame] | 516 | self.logger.debug("the db_profile is :{}".format(db_profile)) |
| 517 | self.logger.debug( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 518 | "the item_content name is :{}".format(db_cluster["name"]) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 519 | ) |
| garciadeblas | c255285 | 2024-10-22 12:39:32 +0200 | [diff] [blame] | 520 | self.logger.debug( |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 521 | "the db_profile name is :{}".format(db_profile["name"]) |
| 522 | ) |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 523 | if db_cluster["name"] == db_profile["name"]: |
| garciadeblas | c255285 | 2024-10-22 12:39:32 +0200 | [diff] [blame] | 524 | self.logger.debug("it is getting into if default") |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 525 | self.db.del_one(db_collection, {"_id": profile_id}) |
| 526 | else: |
| garciadeblas | c255285 | 2024-10-22 12:39:32 +0200 | [diff] [blame] | 527 | self.logger.debug("it is getting into else non default") |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 528 | profile_ids.remove(profile_id) |
| 529 | update_dict = {profile_type: profile_ids} |
| garciadeblas | c255285 | 2024-10-22 12:39:32 +0200 | [diff] [blame] | 530 | self.logger.debug(f"the update dict is :{update_dict}") |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 531 | self.db.set_one( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 532 | "clusters", {"_id": db_cluster["_id"]}, update_dict |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 533 | ) |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 534 | self.db.del_one("clusters", {"_id": db_cluster["_id"]}) |
| garciadeblas | c255285 | 2024-10-22 12:39:32 +0200 | [diff] [blame] | 535 | self.logger.debug("the id is :{}".format(db_cluster["_id"])) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 536 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 537 | async def attach_profile(self, op_id, op_params, content): |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 538 | self.logger.info("profile attach Enter") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 539 | db_cluster = content["cluster"] |
| 540 | db_profile = content["profile"] |
| 541 | profile_type = db_profile["profile_type"] |
| 542 | profile_id = db_profile["_id"] |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 543 | self.logger.info("profile type is : {}".format(profile_type)) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 544 | self.logger.info("profile id is : {}".format(profile_id)) |
| 545 | |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 546 | _, workflow_name = await self.odu.launch_workflow( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 547 | "attach_profile_to_cluster", op_id, op_params, content |
| 548 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 549 | self.logger.info("workflow_name is :{}".format(workflow_name)) |
| 550 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 551 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 552 | workflow_name |
| 553 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 554 | self.logger.info( |
| 555 | "workflow_status is :{} and workflow_msg is :{}".format( |
| 556 | workflow_status, workflow_msg |
| 557 | ) |
| 558 | ) |
| 559 | if workflow_status: |
| 560 | db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED" |
| 561 | else: |
| 562 | db_cluster["resourceState"] = "ERROR" |
| 563 | # has to call update_operation_history return content |
| 564 | db_cluster = self.update_operation_history(db_cluster, workflow_status, None) |
| 565 | self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) |
| 566 | |
| 567 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 568 | resource_status, resource_msg = await self.check_resource_status( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 569 | "attach_profile_to_cluster", op_id, op_params, content |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 570 | ) |
| 571 | self.logger.info( |
| 572 | "resource_status is :{} and resource_msg is :{}".format( |
| 573 | resource_status, resource_msg |
| 574 | ) |
| 575 | ) |
| 576 | if resource_status: |
| 577 | db_cluster["resourceState"] = "READY" |
| 578 | else: |
| 579 | db_cluster["resourceState"] = "ERROR" |
| 580 | |
| 581 | db_cluster["operatingState"] = "IDLE" |
| 582 | db_cluster = self.update_operation_history( |
| 583 | db_cluster, workflow_status, resource_status |
| 584 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 585 | profile_list = db_cluster[profile_type] |
| 586 | self.logger.info("profile list is : {}".format(profile_list)) |
| 587 | if resource_status: |
| 588 | self.logger.info("it is getting into resource status true") |
| 589 | profile_list.append(profile_id) |
| 590 | self.logger.info("profile list is : {}".format(profile_list)) |
| 591 | db_cluster[profile_type] = profile_list |
| 592 | self.logger.info("db cluster is : {}".format(db_cluster)) |
| 593 | # update_dict = {item: profile_list} |
| 594 | # self.logger.info("the update_dict is :{}".format(update_dict)) |
| 595 | # self.db.set_one(self.topic, filter_q, update_dict) |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 596 | db_cluster["current_operation"] = None |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 597 | self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) |
| 598 | |
| 599 | return |
| 600 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 601 | async def detach_profile(self, op_id, op_params, content): |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 602 | self.logger.info("profile dettach Enter") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 603 | db_cluster = content["cluster"] |
| 604 | db_profile = content["profile"] |
| 605 | profile_type = db_profile["profile_type"] |
| 606 | profile_id = db_profile["_id"] |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 607 | self.logger.info("profile type is : {}".format(profile_type)) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 608 | self.logger.info("profile id is : {}".format(profile_id)) |
| 609 | |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 610 | _, workflow_name = await self.odu.launch_workflow( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 611 | "detach_profile_from_cluster", op_id, op_params, content |
| 612 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 613 | self.logger.info("workflow_name is :{}".format(workflow_name)) |
| 614 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 615 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 616 | workflow_name |
| 617 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 618 | self.logger.info( |
| 619 | "workflow_status is :{} and workflow_msg is :{}".format( |
| 620 | workflow_status, workflow_msg |
| 621 | ) |
| 622 | ) |
| 623 | if workflow_status: |
| 624 | db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED" |
| 625 | else: |
| 626 | db_cluster["resourceState"] = "ERROR" |
| 627 | # has to call update_operation_history return content |
| 628 | db_cluster = self.update_operation_history(db_cluster, workflow_status, None) |
| 629 | self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) |
| 630 | |
| 631 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 632 | resource_status, resource_msg = await self.check_resource_status( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 633 | "detach_profile_from_cluster", op_id, op_params, content |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 634 | ) |
| 635 | self.logger.info( |
| 636 | "resource_status is :{} and resource_msg is :{}".format( |
| 637 | resource_status, resource_msg |
| 638 | ) |
| 639 | ) |
| 640 | if resource_status: |
| 641 | db_cluster["resourceState"] = "READY" |
| 642 | else: |
| 643 | db_cluster["resourceState"] = "ERROR" |
| 644 | |
| 645 | db_cluster["operatingState"] = "IDLE" |
| 646 | db_cluster = self.update_operation_history( |
| 647 | db_cluster, workflow_status, resource_status |
| 648 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 649 | profile_list = db_cluster[profile_type] |
| 650 | self.logger.info("profile list is : {}".format(profile_list)) |
| 651 | if resource_status: |
| 652 | self.logger.info("it is getting into resource status true") |
| 653 | profile_list.remove(profile_id) |
| 654 | self.logger.info("profile list is : {}".format(profile_list)) |
| 655 | db_cluster[profile_type] = profile_list |
| 656 | self.logger.info("db cluster is : {}".format(db_cluster)) |
| 657 | # update_dict = {item: profile_list} |
| 658 | # self.logger.info("the update_dict is :{}".format(update_dict)) |
| 659 | # self.db.set_one(self.topic, filter_q, update_dict) |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 660 | db_cluster["current_operation"] = None |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 661 | self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) |
| 662 | |
| 663 | return |
| 664 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 665 | async def register(self, op_id, op_params, content): |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 666 | self.logger.info("cluster register enter") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 667 | db_cluster = content["cluster"] |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 668 | |
| rshri | c356494 | 2024-11-12 18:12:38 +0000 | [diff] [blame] | 669 | db_cluster_copy = self.decrypting_key(db_cluster) |
| 670 | |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 671 | _, workflow_name = await self.odu.launch_workflow( |
| rshri | c356494 | 2024-11-12 18:12:38 +0000 | [diff] [blame] | 672 | "register_cluster", op_id, op_params, db_cluster_copy |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 673 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 674 | self.logger.info("workflow_name is :{}".format(workflow_name)) |
| 675 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 676 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 677 | workflow_name |
| 678 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 679 | self.logger.info( |
| 680 | "workflow_status is :{} and workflow_msg is :{}".format( |
| 681 | workflow_status, workflow_msg |
| 682 | ) |
| 683 | ) |
| 684 | if workflow_status: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 685 | db_cluster["state"] = "CREATED" |
| 686 | db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 687 | else: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 688 | db_cluster["state"] = "FAILED_CREATION" |
| 689 | db_cluster["resourceState"] = "ERROR" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 690 | # has to call update_operation_history return content |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 691 | db_cluster = self.update_operation_history(db_cluster, workflow_status, None) |
| 692 | self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 693 | |
| garciadeblas | dde3a31 | 2024-09-17 13:25:06 +0200 | [diff] [blame] | 694 | # Clean items used in the workflow, no matter if the workflow succeeded |
| 695 | clean_status, clean_msg = await self.odu.clean_items_workflow( |
| rshri | c356494 | 2024-11-12 18:12:38 +0000 | [diff] [blame] | 696 | "register_cluster", op_id, op_params, db_cluster_copy |
| garciadeblas | dde3a31 | 2024-09-17 13:25:06 +0200 | [diff] [blame] | 697 | ) |
| 698 | self.logger.info( |
| 699 | f"clean_status is :{clean_status} and clean_msg is :{clean_msg}" |
| 700 | ) |
| 701 | |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 702 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 703 | resource_status, resource_msg = await self.check_resource_status( |
| rshri | c356494 | 2024-11-12 18:12:38 +0000 | [diff] [blame] | 704 | "register_cluster", op_id, op_params, db_cluster_copy |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 705 | ) |
| 706 | self.logger.info( |
| 707 | "resource_status is :{} and resource_msg is :{}".format( |
| 708 | resource_status, resource_msg |
| 709 | ) |
| 710 | ) |
| 711 | if resource_status: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 712 | db_cluster["resourceState"] = "READY" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 713 | else: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 714 | db_cluster["resourceState"] = "ERROR" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 715 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 716 | db_cluster["operatingState"] = "IDLE" |
| 717 | db_cluster = self.update_operation_history( |
| 718 | db_cluster, workflow_status, resource_status |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 719 | ) |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 720 | db_cluster["current_operation"] = None |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 721 | self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 722 | return |
| 723 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 724 | async def deregister(self, op_id, op_params, content): |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 725 | self.logger.info("cluster deregister enter") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 726 | db_cluster = content["cluster"] |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 727 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 728 | self.logger.info("db_cluster is : {}".format(db_cluster)) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 729 | |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 730 | _, workflow_name = await self.odu.launch_workflow( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 731 | "deregister_cluster", op_id, op_params, content |
| 732 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 733 | self.logger.info("workflow_name is :{}".format(workflow_name)) |
| 734 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 735 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 736 | workflow_name |
| 737 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 738 | self.logger.info( |
| 739 | "workflow_status is :{} and workflow_msg is :{}".format( |
| 740 | workflow_status, workflow_msg |
| 741 | ) |
| 742 | ) |
| 743 | if workflow_status: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 744 | db_cluster["state"] = "DELETED" |
| 745 | db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 746 | else: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 747 | db_cluster["state"] = "FAILED_DELETION" |
| 748 | db_cluster["resourceState"] = "ERROR" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 749 | # has to call update_operation_history return content |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 750 | db_cluster = self.update_operation_history(db_cluster, workflow_status, None) |
| 751 | self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 752 | |
| garciadeblas | 91bb2c4 | 2024-11-12 11:17:12 +0100 | [diff] [blame] | 753 | # Clean items used in the workflow or in the cluster, no matter if the workflow succeeded |
| 754 | clean_status, clean_msg = await self.odu.clean_items_workflow( |
| 755 | "deregister_cluster", op_id, op_params, content |
| 756 | ) |
| 757 | self.logger.info( |
| 758 | f"clean_status is :{clean_status} and clean_msg is :{clean_msg}" |
| 759 | ) |
| 760 | |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 761 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 762 | resource_status, resource_msg = await self.check_resource_status( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 763 | "deregister_cluster", op_id, op_params, content |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 764 | ) |
| 765 | self.logger.info( |
| 766 | "resource_status is :{} and resource_msg is :{}".format( |
| 767 | resource_status, resource_msg |
| 768 | ) |
| 769 | ) |
| 770 | if resource_status: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 771 | db_cluster["resourceState"] = "READY" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 772 | else: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 773 | db_cluster["resourceState"] = "ERROR" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 774 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 775 | db_cluster["operatingState"] = "IDLE" |
| 776 | db_cluster = self.update_operation_history( |
| 777 | db_cluster, workflow_status, resource_status |
| 778 | ) |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 779 | db_cluster["current_operation"] = None |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 780 | self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 781 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 782 | # To delete it from DB |
| 783 | if db_cluster["state"] == "DELETED": |
| 784 | self.db.del_one("clusters", {"_id": db_cluster["_id"]}) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 785 | return |
| 786 | |
| yshah | d940c65 | 2024-10-17 06:11:12 +0000 | [diff] [blame] | 787 | async def get_creds(self, op_id, db_cluster): |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 788 | self.logger.info("Cluster get creds Enter") |
| 789 | result, cluster_creds = await self.odu.get_cluster_credentials(db_cluster) |
| 790 | if result: |
| 791 | db_cluster["credentials"] = cluster_creds |
| yshah | d940c65 | 2024-10-17 06:11:12 +0000 | [diff] [blame] | 792 | op_len = 0 |
| 793 | for operations in db_cluster["operationHistory"]: |
| 794 | if operations["op_id"] == op_id: |
| 795 | db_cluster["operationHistory"][op_len]["result"] = result |
| 796 | db_cluster["operationHistory"][op_len]["endDate"] = time() |
| 797 | op_len += 1 |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 798 | db_cluster["current_operation"] = None |
| yshah | d940c65 | 2024-10-17 06:11:12 +0000 | [diff] [blame] | 799 | self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 800 | return |
| 801 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 802 | async def update(self, op_id, op_params, content): |
| 803 | self.logger.info("Cluster update Enter") |
| 804 | db_cluster = content["cluster"] |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 805 | |
| rshri | c356494 | 2024-11-12 18:12:38 +0000 | [diff] [blame] | 806 | db_cluster_copy = self.decrypting_key(db_cluster) |
| 807 | |
| 808 | # vim account details |
| 809 | db_vim = self.db.get_one("vim_accounts", {"name": db_cluster["vim_account"]}) |
| 810 | db_cluster_copy["vim_account"] = db_vim |
| 811 | |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 812 | _, workflow_name = await self.odu.launch_workflow( |
| rshri | c356494 | 2024-11-12 18:12:38 +0000 | [diff] [blame] | 813 | "update_cluster", op_id, op_params, db_cluster_copy |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 814 | ) |
| 815 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 816 | workflow_name |
| 817 | ) |
| 818 | self.logger.info( |
| 819 | "Workflow Status: {} Workflow Message: {}".format( |
| 820 | workflow_status, workflow_msg |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 821 | ) |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 822 | ) |
| 823 | |
| 824 | if workflow_status: |
| 825 | db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED" |
| 826 | else: |
| 827 | db_cluster["resourceState"] = "ERROR" |
| 828 | |
| 829 | db_cluster = self.update_operation_history(db_cluster, workflow_status, None) |
| 830 | # self.logger.info("Db content: {}".format(db_content)) |
| 831 | # self.db.set_one(self.db_collection, {"_id": _id}, db_cluster) |
| 832 | self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) |
| 833 | |
| garciadeblas | 28bff0f | 2024-09-16 12:53:07 +0200 | [diff] [blame] | 834 | # Clean items used in the workflow, no matter if the workflow succeeded |
| 835 | clean_status, clean_msg = await self.odu.clean_items_workflow( |
| rshri | c356494 | 2024-11-12 18:12:38 +0000 | [diff] [blame] | 836 | "update_cluster", op_id, op_params, db_cluster_copy |
| garciadeblas | 28bff0f | 2024-09-16 12:53:07 +0200 | [diff] [blame] | 837 | ) |
| 838 | self.logger.info( |
| 839 | f"clean_status is :{clean_status} and clean_msg is :{clean_msg}" |
| 840 | ) |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 841 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 842 | resource_status, resource_msg = await self.check_resource_status( |
| rshri | c356494 | 2024-11-12 18:12:38 +0000 | [diff] [blame] | 843 | "update_cluster", op_id, op_params, db_cluster_copy |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 844 | ) |
| 845 | self.logger.info( |
| 846 | "Resource Status: {} Resource Message: {}".format( |
| 847 | resource_status, resource_msg |
| 848 | ) |
| 849 | ) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 850 | |
| 851 | if resource_status: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 852 | db_cluster["resourceState"] = "READY" |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 853 | else: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 854 | db_cluster["resourceState"] = "ERROR" |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 855 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 856 | db_cluster["operatingState"] = "IDLE" |
| 857 | db_cluster = self.update_operation_history( |
| 858 | db_cluster, workflow_status, resource_status |
| 859 | ) |
| 860 | # self.logger.info("db_cluster: {}".format(db_cluster)) |
| 861 | # TODO: verify enxtcondition |
| 862 | # For the moment, if the workflow completed successfully, then we update the db accordingly. |
| 863 | if workflow_status: |
| 864 | if "k8s_version" in op_params: |
| 865 | db_cluster["k8s_version"] = op_params["k8s_version"] |
| 866 | elif "node_count" in op_params: |
| 867 | db_cluster["node_count"] = op_params["node_count"] |
| 868 | # self.db.set_one(self.db_collection, {"_id": _id}, db_content) |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 869 | db_cluster["current_operation"] = None |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 870 | self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 871 | return |
| 872 | |
| 873 | |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 874 | class CloudCredentialsLcm(GitOpsLcm): |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 875 | db_collection = "vim_accounts" |
| 876 | |
| 877 | def __init__(self, msg, lcm_tasks, config): |
| 878 | """ |
| 879 | Init, Connect to database, filesystem storage, and messaging |
| 880 | :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', |
| 881 | :return: None |
| 882 | """ |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 883 | super().__init__(msg, lcm_tasks, config) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 884 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 885 | async def add(self, op_id, op_params, content): |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 886 | self.logger.info("Cloud Credentials create") |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 887 | _, workflow_name = await self.odu.launch_workflow( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 888 | "create_cloud_credentials", op_id, op_params, content |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 889 | ) |
| 890 | |
| 891 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 892 | workflow_name |
| 893 | ) |
| 894 | |
| 895 | self.logger.info( |
| 896 | "Workflow Status: {} Workflow Msg: {}".format(workflow_status, workflow_msg) |
| 897 | ) |
| 898 | |
| garciadeblas | 28bff0f | 2024-09-16 12:53:07 +0200 | [diff] [blame] | 899 | # Clean items used in the workflow, no matter if the workflow succeeded |
| 900 | clean_status, clean_msg = await self.odu.clean_items_workflow( |
| 901 | "create_cloud_credentials", op_id, op_params, content |
| 902 | ) |
| 903 | self.logger.info( |
| 904 | f"clean_status is :{clean_status} and clean_msg is :{clean_msg}" |
| 905 | ) |
| 906 | |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 907 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 908 | resource_status, resource_msg = await self.check_resource_status( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 909 | "create_cloud_credentials", op_id, op_params, content |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 910 | ) |
| 911 | self.logger.info( |
| 912 | "Resource Status: {} Resource Message: {}".format( |
| 913 | resource_status, resource_msg |
| 914 | ) |
| 915 | ) |
| garciadeblas | 15b8a30 | 2024-09-23 12:40:13 +0200 | [diff] [blame] | 916 | |
| 917 | content["_admin"]["operationalState"] = "ENABLED" |
| 918 | for operation in content["_admin"]["operations"]: |
| 919 | if operation["lcmOperationType"] == "create": |
| 920 | operation["operationState"] = "ENABLED" |
| 921 | self.logger.info("Content : {}".format(content)) |
| 922 | self.db.set_one("vim_accounts", {"_id": content["_id"]}, content) |
| 923 | |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 924 | return |
| 925 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 926 | async def edit(self, op_id, op_params, content): |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 927 | _, workflow_name = await self.odu.launch_workflow( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 928 | "update_cloud_credentials", op_id, op_params, content |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 929 | ) |
| 930 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 931 | workflow_name |
| 932 | ) |
| 933 | self.logger.info( |
| 934 | "Workflow Status: {} Workflow Msg: {}".format(workflow_status, workflow_msg) |
| 935 | ) |
| 936 | |
| garciadeblas | 28bff0f | 2024-09-16 12:53:07 +0200 | [diff] [blame] | 937 | # Clean items used in the workflow, no matter if the workflow succeeded |
| 938 | clean_status, clean_msg = await self.odu.clean_items_workflow( |
| 939 | "update_cloud_credentials", op_id, op_params, content |
| 940 | ) |
| 941 | self.logger.info( |
| 942 | f"clean_status is :{clean_status} and clean_msg is :{clean_msg}" |
| 943 | ) |
| 944 | |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 945 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 946 | resource_status, resource_msg = await self.check_resource_status( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 947 | "update_cloud_credentials", op_id, op_params, content |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 948 | ) |
| 949 | self.logger.info( |
| 950 | "Resource Status: {} Resource Message: {}".format( |
| 951 | resource_status, resource_msg |
| 952 | ) |
| 953 | ) |
| 954 | return |
| 955 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 956 | async def remove(self, op_id, op_params, content): |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 957 | self.logger.info("Cloud Credentials delete") |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 958 | _, workflow_name = await self.odu.launch_workflow( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 959 | "delete_cloud_credentials", op_id, op_params, content |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 960 | ) |
| 961 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 962 | workflow_name |
| 963 | ) |
| 964 | self.logger.info( |
| 965 | "Workflow Status: {} Workflow Msg: {}".format(workflow_status, workflow_msg) |
| 966 | ) |
| 967 | |
| 968 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 969 | resource_status, resource_msg = await self.check_resource_status( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 970 | "delete_cloud_credentials", op_id, op_params, content |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 971 | ) |
| 972 | self.logger.info( |
| 973 | "Resource Status: {} Resource Message: {}".format( |
| 974 | resource_status, resource_msg |
| 975 | ) |
| 976 | ) |
| 977 | self.db.del_one(self.db_collection, {"_id": content["_id"]}) |
| 978 | return |
| 979 | |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 980 | |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 981 | class K8sAppLcm(GitOpsLcm): |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 982 | def __init__(self, msg, lcm_tasks, config): |
| 983 | """ |
| 984 | Init, Connect to database, filesystem storage, and messaging |
| 985 | :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', |
| 986 | :return: None |
| 987 | """ |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 988 | super().__init__(msg, lcm_tasks, config) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 989 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 990 | async def create(self, op_id, op_params, content): |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 991 | self.logger.info("App Create Enter") |
| 992 | |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 993 | _, workflow_name = await self.odu.launch_workflow( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 994 | "create_profile", op_id, op_params, content |
| 995 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 996 | self.logger.info("workflow_name is :{}".format(workflow_name)) |
| 997 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 998 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 999 | workflow_name |
| 1000 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1001 | self.logger.info( |
| 1002 | "workflow_status is :{} and workflow_msg is :{}".format( |
| 1003 | workflow_status, workflow_msg |
| 1004 | ) |
| 1005 | ) |
| 1006 | if workflow_status: |
| 1007 | content["state"] = "CREATED" |
| 1008 | content["resourceState"] = "IN_PROGRESS.GIT_SYNCED" |
| 1009 | else: |
| 1010 | content["state"] = "FAILED_CREATION" |
| 1011 | content["resourceState"] = "ERROR" |
| 1012 | # has to call update_operation_history return content |
| 1013 | content = self.update_operation_history(content, workflow_status, None) |
| 1014 | self.db.set_one("k8sapp", {"_id": content["_id"]}, content) |
| 1015 | |
| 1016 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1017 | resource_status, resource_msg = await self.check_resource_status( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1018 | "create_profile", op_id, op_params, content |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1019 | ) |
| 1020 | self.logger.info( |
| 1021 | "resource_status is :{} and resource_msg is :{}".format( |
| 1022 | resource_status, resource_msg |
| 1023 | ) |
| 1024 | ) |
| 1025 | if resource_status: |
| 1026 | content["resourceState"] = "READY" |
| 1027 | else: |
| 1028 | content["resourceState"] = "ERROR" |
| 1029 | |
| 1030 | content["operatingState"] = "IDLE" |
| 1031 | content = self.update_operation_history( |
| 1032 | content, workflow_status, resource_status |
| 1033 | ) |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 1034 | content["current_operation"] = None |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1035 | self.db.set_one("k8sapp", {"_id": content["_id"]}, content) |
| 1036 | |
| 1037 | return |
| 1038 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1039 | async def delete(self, op_id, op_params, content): |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1040 | self.logger.info("App delete Enter") |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1041 | |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 1042 | _, workflow_name = await self.odu.launch_workflow( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1043 | "delete_profile", op_id, op_params, content |
| 1044 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1045 | self.logger.info("workflow_name is :{}".format(workflow_name)) |
| 1046 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1047 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 1048 | workflow_name |
| 1049 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1050 | self.logger.info( |
| 1051 | "workflow_status is :{} and workflow_msg is :{}".format( |
| 1052 | workflow_status, workflow_msg |
| 1053 | ) |
| 1054 | ) |
| 1055 | if workflow_status: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1056 | content["state"] = "DELETED" |
| 1057 | content["resourceState"] = "IN_PROGRESS.GIT_SYNCED" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1058 | else: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1059 | content["state"] = "FAILED_DELETION" |
| 1060 | content["resourceState"] = "ERROR" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1061 | # has to call update_operation_history return content |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1062 | content = self.update_operation_history(content, workflow_status, None) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1063 | self.db.set_one("k8sapp", {"_id": content["_id"]}, content) |
| 1064 | |
| 1065 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1066 | resource_status, resource_msg = await self.check_resource_status( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1067 | "delete_profile", op_id, op_params, content |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1068 | ) |
| 1069 | self.logger.info( |
| 1070 | "resource_status is :{} and resource_msg is :{}".format( |
| 1071 | resource_status, resource_msg |
| 1072 | ) |
| 1073 | ) |
| 1074 | if resource_status: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1075 | content["resourceState"] = "READY" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1076 | else: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1077 | content["resourceState"] = "ERROR" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1078 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1079 | content["operatingState"] = "IDLE" |
| 1080 | content = self.update_operation_history( |
| 1081 | content, workflow_status, resource_status |
| 1082 | ) |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 1083 | content["current_operation"] = None |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1084 | self.db.set_one("k8sapp", {"_id": content["_id"]}, content) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1085 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1086 | # To delete it from DB |
| 1087 | if content["state"] == "DELETED": |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1088 | self.db.del_one("k8sapp", {"_id": content["_id"]}) |
| 1089 | return |
| 1090 | |
| 1091 | |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1092 | class K8sResourceLcm(GitOpsLcm): |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1093 | def __init__(self, msg, lcm_tasks, config): |
| 1094 | """ |
| 1095 | Init, Connect to database, filesystem storage, and messaging |
| 1096 | :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', |
| 1097 | :return: None |
| 1098 | """ |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1099 | super().__init__(msg, lcm_tasks, config) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1100 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1101 | async def create(self, op_id, op_params, content): |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1102 | self.logger.info("Resource Create Enter") |
| 1103 | |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 1104 | _, workflow_name = await self.odu.launch_workflow( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1105 | "create_profile", op_id, op_params, content |
| 1106 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1107 | self.logger.info("workflow_name is :{}".format(workflow_name)) |
| 1108 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1109 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 1110 | workflow_name |
| 1111 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1112 | self.logger.info( |
| 1113 | "workflow_status is :{} and workflow_msg is :{}".format( |
| 1114 | workflow_status, workflow_msg |
| 1115 | ) |
| 1116 | ) |
| 1117 | if workflow_status: |
| 1118 | content["state"] = "CREATED" |
| 1119 | content["resourceState"] = "IN_PROGRESS.GIT_SYNCED" |
| 1120 | else: |
| 1121 | content["state"] = "FAILED_CREATION" |
| 1122 | content["resourceState"] = "ERROR" |
| 1123 | # has to call update_operation_history return content |
| 1124 | content = self.update_operation_history(content, workflow_status, None) |
| 1125 | self.db.set_one("k8sresource", {"_id": content["_id"]}, content) |
| 1126 | |
| 1127 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1128 | resource_status, resource_msg = await self.check_resource_status( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1129 | "create_profile", op_id, op_params, content |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1130 | ) |
| 1131 | self.logger.info( |
| 1132 | "resource_status is :{} and resource_msg is :{}".format( |
| 1133 | resource_status, resource_msg |
| 1134 | ) |
| 1135 | ) |
| 1136 | if resource_status: |
| 1137 | content["resourceState"] = "READY" |
| 1138 | else: |
| 1139 | content["resourceState"] = "ERROR" |
| 1140 | |
| 1141 | content["operatingState"] = "IDLE" |
| 1142 | content = self.update_operation_history( |
| 1143 | content, workflow_status, resource_status |
| 1144 | ) |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 1145 | content["current_operation"] = None |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1146 | self.db.set_one("k8sresource", {"_id": content["_id"]}, content) |
| 1147 | |
| 1148 | return |
| 1149 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1150 | async def delete(self, op_id, op_params, content): |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1151 | self.logger.info("Resource delete Enter") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1152 | content = self.db.get_one("k8sresource", {"_id": content["_id"]}) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1153 | |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 1154 | _, workflow_name = await self.odu.launch_workflow( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1155 | "delete_profile", op_id, op_params, content |
| 1156 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1157 | self.logger.info("workflow_name is :{}".format(workflow_name)) |
| 1158 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1159 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 1160 | workflow_name |
| 1161 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1162 | self.logger.info( |
| 1163 | "workflow_status is :{} and workflow_msg is :{}".format( |
| 1164 | workflow_status, workflow_msg |
| 1165 | ) |
| 1166 | ) |
| 1167 | if workflow_status: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1168 | content["state"] = "DELETED" |
| 1169 | content["resourceState"] = "IN_PROGRESS.GIT_SYNCED" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1170 | else: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1171 | content["state"] = "FAILED_DELETION" |
| 1172 | content["resourceState"] = "ERROR" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1173 | # has to call update_operation_history return content |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1174 | content = self.update_operation_history(content, workflow_status, None) |
| 1175 | self.db.set_one("k8sresource", {"_id": content["_id"]}, content) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1176 | |
| 1177 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1178 | resource_status, resource_msg = await self.check_resource_status( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1179 | "delete_profile", op_id, op_params, content |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1180 | ) |
| 1181 | self.logger.info( |
| 1182 | "resource_status is :{} and resource_msg is :{}".format( |
| 1183 | resource_status, resource_msg |
| 1184 | ) |
| 1185 | ) |
| 1186 | if resource_status: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1187 | content["resourceState"] = "READY" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1188 | else: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1189 | content["resourceState"] = "ERROR" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1190 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1191 | content["operatingState"] = "IDLE" |
| 1192 | content = self.update_operation_history( |
| 1193 | content, workflow_status, resource_status |
| 1194 | ) |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 1195 | content["current_operation"] = None |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1196 | self.db.set_one("k8sresource", {"_id": content["_id"]}, content) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1197 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1198 | # To delete it from DB |
| 1199 | if content["state"] == "DELETED": |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1200 | self.db.del_one("k8sresource", {"_id": content["_id"]}) |
| 1201 | return |
| 1202 | |
| 1203 | |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1204 | class K8sInfraControllerLcm(GitOpsLcm): |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1205 | def __init__(self, msg, lcm_tasks, config): |
| 1206 | """ |
| 1207 | Init, Connect to database, filesystem storage, and messaging |
| 1208 | :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', |
| 1209 | :return: None |
| 1210 | """ |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1211 | super().__init__(msg, lcm_tasks, config) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1212 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1213 | async def create(self, op_id, op_params, content): |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1214 | self.logger.info("Infra controller Create Enter") |
| 1215 | |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 1216 | _, workflow_name = await self.odu.launch_workflow( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1217 | "create_profile", op_id, op_params, content |
| 1218 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1219 | self.logger.info("workflow_name is :{}".format(workflow_name)) |
| 1220 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1221 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 1222 | workflow_name |
| 1223 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1224 | self.logger.info( |
| 1225 | "workflow_status is :{} and workflow_msg is :{}".format( |
| 1226 | workflow_status, workflow_msg |
| 1227 | ) |
| 1228 | ) |
| 1229 | if workflow_status: |
| 1230 | content["state"] = "CREATED" |
| 1231 | content["resourceState"] = "IN_PROGRESS.GIT_SYNCED" |
| 1232 | else: |
| 1233 | content["state"] = "FAILED_CREATION" |
| 1234 | content["resourceState"] = "ERROR" |
| 1235 | # has to call update_operation_history return content |
| 1236 | content = self.update_operation_history(content, workflow_status, None) |
| 1237 | self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content) |
| 1238 | |
| 1239 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1240 | resource_status, resource_msg = await self.check_resource_status( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1241 | "create_profile", op_id, op_params, content |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1242 | ) |
| 1243 | self.logger.info( |
| 1244 | "resource_status is :{} and resource_msg is :{}".format( |
| 1245 | resource_status, resource_msg |
| 1246 | ) |
| 1247 | ) |
| 1248 | if resource_status: |
| 1249 | content["resourceState"] = "READY" |
| 1250 | else: |
| 1251 | content["resourceState"] = "ERROR" |
| 1252 | |
| 1253 | content["operatingState"] = "IDLE" |
| 1254 | content = self.update_operation_history( |
| 1255 | content, workflow_status, resource_status |
| 1256 | ) |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 1257 | content["current_operation"] = None |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1258 | self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content) |
| 1259 | |
| 1260 | return |
| 1261 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1262 | async def delete(self, op_id, op_params, content): |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1263 | self.logger.info("Infra controller delete Enter") |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1264 | |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 1265 | _, workflow_name = await self.odu.launch_workflow( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1266 | "delete_profile", op_id, op_params, content |
| 1267 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1268 | self.logger.info("workflow_name is :{}".format(workflow_name)) |
| 1269 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1270 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 1271 | workflow_name |
| 1272 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1273 | self.logger.info( |
| 1274 | "workflow_status is :{} and workflow_msg is :{}".format( |
| 1275 | workflow_status, workflow_msg |
| 1276 | ) |
| 1277 | ) |
| 1278 | if workflow_status: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1279 | content["state"] = "DELETED" |
| 1280 | content["resourceState"] = "IN_PROGRESS.GIT_SYNCED" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1281 | else: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1282 | content["state"] = "FAILED_DELETION" |
| 1283 | content["resourceState"] = "ERROR" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1284 | # has to call update_operation_history return content |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1285 | content = self.update_operation_history(content, workflow_status, None) |
| 1286 | self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1287 | |
| 1288 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1289 | resource_status, resource_msg = await self.check_resource_status( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1290 | "delete_profile", op_id, op_params, content |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1291 | ) |
| 1292 | self.logger.info( |
| 1293 | "resource_status is :{} and resource_msg is :{}".format( |
| 1294 | resource_status, resource_msg |
| 1295 | ) |
| 1296 | ) |
| 1297 | if resource_status: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1298 | content["resourceState"] = "READY" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1299 | else: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1300 | content["resourceState"] = "ERROR" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1301 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1302 | content["operatingState"] = "IDLE" |
| 1303 | content = self.update_operation_history( |
| 1304 | content, workflow_status, resource_status |
| 1305 | ) |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 1306 | content["current_operation"] = None |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1307 | self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1308 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1309 | # To delete it from DB |
| 1310 | if content["state"] == "DELETED": |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1311 | self.db.del_one("k8sinfra_controller", {"_id": content["_id"]}) |
| 1312 | return |
| 1313 | |
| 1314 | |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1315 | class K8sInfraConfigLcm(GitOpsLcm): |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1316 | def __init__(self, msg, lcm_tasks, config): |
| 1317 | """ |
| 1318 | Init, Connect to database, filesystem storage, and messaging |
| 1319 | :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', |
| 1320 | :return: None |
| 1321 | """ |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1322 | super().__init__(msg, lcm_tasks, config) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1323 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1324 | async def create(self, op_id, op_params, content): |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1325 | self.logger.info("Infra config Create Enter") |
| 1326 | |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 1327 | _, workflow_name = await self.odu.launch_workflow( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1328 | "create_profile", op_id, op_params, content |
| 1329 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1330 | self.logger.info("workflow_name is :{}".format(workflow_name)) |
| 1331 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1332 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 1333 | workflow_name |
| 1334 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1335 | self.logger.info( |
| 1336 | "workflow_status is :{} and workflow_msg is :{}".format( |
| 1337 | workflow_status, workflow_msg |
| 1338 | ) |
| 1339 | ) |
| 1340 | if workflow_status: |
| 1341 | content["state"] = "CREATED" |
| 1342 | content["resourceState"] = "IN_PROGRESS.GIT_SYNCED" |
| 1343 | else: |
| 1344 | content["state"] = "FAILED_CREATION" |
| 1345 | content["resourceState"] = "ERROR" |
| 1346 | # has to call update_operation_history return content |
| 1347 | content = self.update_operation_history(content, workflow_status, None) |
| 1348 | self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content) |
| 1349 | |
| 1350 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1351 | resource_status, resource_msg = await self.check_resource_status( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1352 | "create_profile", op_id, op_params, content |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1353 | ) |
| 1354 | self.logger.info( |
| 1355 | "resource_status is :{} and resource_msg is :{}".format( |
| 1356 | resource_status, resource_msg |
| 1357 | ) |
| 1358 | ) |
| 1359 | if resource_status: |
| 1360 | content["resourceState"] = "READY" |
| 1361 | else: |
| 1362 | content["resourceState"] = "ERROR" |
| 1363 | |
| 1364 | content["operatingState"] = "IDLE" |
| 1365 | content = self.update_operation_history( |
| 1366 | content, workflow_status, resource_status |
| 1367 | ) |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 1368 | content["current_operation"] = None |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1369 | self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content) |
| 1370 | |
| 1371 | return |
| 1372 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1373 | async def delete(self, op_id, op_params, content): |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1374 | self.logger.info("Infra config delete Enter") |
| 1375 | |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 1376 | _, workflow_name = await self.odu.launch_workflow( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1377 | "delete_profile", op_id, op_params, content |
| 1378 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1379 | self.logger.info("workflow_name is :{}".format(workflow_name)) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1380 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1381 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 1382 | workflow_name |
| 1383 | ) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1384 | self.logger.info( |
| 1385 | "workflow_status is :{} and workflow_msg is :{}".format( |
| 1386 | workflow_status, workflow_msg |
| 1387 | ) |
| 1388 | ) |
| 1389 | if workflow_status: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1390 | content["state"] = "DELETED" |
| 1391 | content["resourceState"] = "IN_PROGRESS.GIT_SYNCED" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1392 | else: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1393 | content["state"] = "FAILED_DELETION" |
| 1394 | content["resourceState"] = "ERROR" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1395 | # has to call update_operation_history return content |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1396 | content = self.update_operation_history(content, workflow_status, None) |
| 1397 | self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1398 | |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1399 | resource_status, resource_msg = await self.check_resource_status( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1400 | "delete_profile", op_id, op_params, content |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1401 | ) |
| 1402 | self.logger.info( |
| 1403 | "resource_status is :{} and resource_msg is :{}".format( |
| 1404 | resource_status, resource_msg |
| 1405 | ) |
| 1406 | ) |
| 1407 | if resource_status: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1408 | content["resourceState"] = "READY" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1409 | else: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1410 | content["resourceState"] = "ERROR" |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1411 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1412 | content["operatingState"] = "IDLE" |
| 1413 | content = self.update_operation_history( |
| 1414 | content, workflow_status, resource_status |
| 1415 | ) |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 1416 | content["current_operation"] = None |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1417 | self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content) |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1418 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1419 | # To delete it from DB |
| 1420 | if content["state"] == "DELETED": |
| rshri | 932105f | 2024-07-05 15:11:55 +0000 | [diff] [blame] | 1421 | self.db.del_one("k8sinfra_config", {"_id": content["_id"]}) |
| 1422 | return |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1423 | |
| 1424 | |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1425 | class OkaLcm(GitOpsLcm): |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1426 | db_collection = "okas" |
| 1427 | |
| 1428 | def __init__(self, msg, lcm_tasks, config): |
| 1429 | """ |
| 1430 | Init, Connect to database, filesystem storage, and messaging |
| 1431 | :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', |
| 1432 | :return: None |
| 1433 | """ |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1434 | super().__init__(msg, lcm_tasks, config) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1435 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1436 | async def create(self, op_id, op_params, content): |
| 1437 | self.logger.info("OKA Create Enter") |
| 1438 | db_content = content |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1439 | |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 1440 | _, workflow_name = await self.odu.launch_workflow( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1441 | "create_oka", op_id, op_params, db_content |
| 1442 | ) |
| 1443 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 1444 | workflow_name |
| 1445 | ) |
| 1446 | self.logger.info( |
| 1447 | "Workflow Status: {} Workflow Message: {}".format( |
| 1448 | workflow_status, workflow_msg |
| 1449 | ) |
| 1450 | ) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1451 | |
| 1452 | if workflow_status: |
| 1453 | db_content["state"] = "CREATED" |
| 1454 | db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED" |
| 1455 | else: |
| 1456 | db_content["state"] = "FAILED_CREATION" |
| 1457 | db_content["resourceState"] = "ERROR" |
| 1458 | |
| 1459 | db_content = self.update_operation_history(db_content, workflow_status, None) |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1460 | self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1461 | |
| 1462 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1463 | resource_status, resource_msg = await self.check_resource_status( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1464 | "create_oka", op_id, op_params, db_content |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1465 | ) |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1466 | self.logger.info( |
| 1467 | "Resource Status: {} Resource Message: {}".format( |
| 1468 | resource_status, resource_msg |
| 1469 | ) |
| 1470 | ) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1471 | |
| 1472 | if resource_status: |
| 1473 | db_content["resourceState"] = "READY" |
| 1474 | else: |
| 1475 | db_content["resourceState"] = "ERROR" |
| 1476 | |
| 1477 | # self.logger.info("Db content: {}".format(db_content)) |
| 1478 | db_content = self.update_operation_history( |
| 1479 | db_content, workflow_status, resource_status |
| 1480 | ) |
| 1481 | |
| 1482 | db_content["operatingState"] = "IDLE" |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 1483 | db_content["current_operation"] = None |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1484 | self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1485 | |
| 1486 | return |
| 1487 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1488 | async def edit(self, op_id, op_params, content): |
| 1489 | self.logger.info("OKA Edit Enter") |
| 1490 | db_content = content |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1491 | |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 1492 | _, workflow_name = await self.odu.launch_workflow( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1493 | "update_oka", op_id, op_params, content |
| 1494 | ) |
| 1495 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 1496 | workflow_name |
| 1497 | ) |
| 1498 | self.logger.info( |
| 1499 | "Workflow Status: {} Workflow Message: {}".format( |
| 1500 | workflow_status, workflow_msg |
| 1501 | ) |
| 1502 | ) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1503 | |
| 1504 | if workflow_status: |
| 1505 | db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED" |
| 1506 | else: |
| 1507 | db_content["resourceState"] = "ERROR" |
| 1508 | |
| 1509 | db_content = self.update_operation_history(db_content, workflow_status, None) |
| 1510 | # self.logger.info("Db content: {}".format(db_content)) |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1511 | self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1512 | |
| 1513 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1514 | resource_status, resource_msg = await self.check_resource_status( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1515 | "update_oka", op_id, op_params, db_content |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1516 | ) |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1517 | self.logger.info( |
| 1518 | "Resource Status: {} Resource Message: {}".format( |
| 1519 | resource_status, resource_msg |
| 1520 | ) |
| 1521 | ) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1522 | |
| 1523 | if resource_status: |
| 1524 | db_content["resourceState"] = "READY" |
| 1525 | else: |
| 1526 | db_content["resourceState"] = "ERROR" |
| 1527 | |
| 1528 | db_content = self.update_operation_history( |
| 1529 | db_content, workflow_status, resource_status |
| 1530 | ) |
| 1531 | |
| 1532 | db_content["operatingState"] = "IDLE" |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 1533 | db_content["current_operation"] = None |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1534 | self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1535 | return |
| 1536 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1537 | async def delete(self, op_id, op_params, content): |
| 1538 | self.logger.info("OKA delete Enter") |
| 1539 | db_content = content |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1540 | |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 1541 | _, workflow_name = await self.odu.launch_workflow( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1542 | "delete_oka", op_id, op_params, content |
| 1543 | ) |
| 1544 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 1545 | workflow_name |
| 1546 | ) |
| 1547 | self.logger.info( |
| 1548 | "Workflow Status: {} Workflow Message: {}".format( |
| 1549 | workflow_status, workflow_msg |
| 1550 | ) |
| 1551 | ) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1552 | |
| 1553 | if workflow_status: |
| 1554 | db_content["state"] = "DELETED" |
| 1555 | db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED" |
| 1556 | else: |
| 1557 | db_content["state"] = "FAILED_DELETION" |
| 1558 | db_content["resourceState"] = "ERROR" |
| 1559 | |
| 1560 | db_content = self.update_operation_history(db_content, workflow_status, None) |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1561 | self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1562 | |
| 1563 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1564 | resource_status, resource_msg = await self.check_resource_status( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1565 | "delete_oka", op_id, op_params, db_content |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1566 | ) |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1567 | self.logger.info( |
| 1568 | "Resource Status: {} Resource Message: {}".format( |
| 1569 | resource_status, resource_msg |
| 1570 | ) |
| 1571 | ) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1572 | |
| 1573 | if resource_status: |
| 1574 | db_content["resourceState"] = "READY" |
| 1575 | else: |
| 1576 | db_content["resourceState"] = "ERROR" |
| 1577 | |
| 1578 | db_content = self.update_operation_history( |
| 1579 | db_content, workflow_status, resource_status |
| 1580 | ) |
| 1581 | |
| 1582 | db_content["operatingState"] = "IDLE" |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 1583 | db_content["current_operation"] = None |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1584 | self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1585 | |
| 1586 | if db_content["state"] == "DELETED": |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1587 | self.db.del_one(self.db_collection, {"_id": db_content["_id"]}) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1588 | return |
| 1589 | |
| 1590 | |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1591 | class KsuLcm(GitOpsLcm): |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1592 | db_collection = "ksus" |
| 1593 | |
| 1594 | def __init__(self, msg, lcm_tasks, config): |
| 1595 | """ |
| 1596 | Init, Connect to database, filesystem storage, and messaging |
| 1597 | :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', |
| 1598 | :return: None |
| 1599 | """ |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1600 | super().__init__(msg, lcm_tasks, config) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1601 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1602 | async def create(self, op_id, op_params, content): |
| 1603 | self.logger.info("ksu Create Enter") |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1604 | |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 1605 | _, workflow_name = await self.odu.launch_workflow( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1606 | "create_ksus", op_id, op_params, content |
| 1607 | ) |
| 1608 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 1609 | workflow_name |
| 1610 | ) |
| 1611 | self.logger.info( |
| 1612 | "Workflow Status: {} Workflow Message: {}".format( |
| 1613 | workflow_status, workflow_msg |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1614 | ) |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1615 | ) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1616 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1617 | for db_ksu in content: |
| 1618 | if workflow_status: |
| 1619 | db_ksu["state"] = "CREATED" |
| 1620 | db_ksu["resourceState"] = "IN_PROGRESS.GIT_SYNCED" |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1621 | else: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1622 | db_ksu["state"] = "FAILED_CREATION" |
| 1623 | db_ksu["resourceState"] = "ERROR" |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1624 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1625 | db_ksu = self.update_operation_history(db_ksu, workflow_status, None) |
| 1626 | self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu) |
| 1627 | |
| garciadeblas | d842985 | 2024-10-17 15:30:30 +0200 | [diff] [blame] | 1628 | # Clean items used in the workflow, no matter if the workflow succeeded |
| 1629 | clean_status, clean_msg = await self.odu.clean_items_workflow( |
| 1630 | "create_ksus", op_id, op_params, content |
| 1631 | ) |
| 1632 | self.logger.info( |
| 1633 | f"clean_status is :{clean_status} and clean_msg is :{clean_msg}" |
| 1634 | ) |
| 1635 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1636 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1637 | resource_status, resource_msg = await self.check_resource_status( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1638 | "create_ksus", op_id, op_params, content |
| 1639 | ) |
| 1640 | self.logger.info( |
| 1641 | "Resource Status: {} Resource Message: {}".format( |
| 1642 | resource_status, resource_msg |
| 1643 | ) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1644 | ) |
| 1645 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1646 | for db_ksu in content: |
| 1647 | if resource_status: |
| 1648 | db_ksu["resourceState"] = "READY" |
| 1649 | else: |
| 1650 | db_ksu["resourceState"] = "ERROR" |
| 1651 | |
| 1652 | db_ksu = self.update_operation_history( |
| 1653 | db_ksu, workflow_status, resource_status |
| 1654 | ) |
| 1655 | |
| 1656 | for db_ksu in content: |
| 1657 | db_ksu["operatingState"] = "IDLE" |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 1658 | db_ksu["current_operation"] = None |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1659 | self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1660 | |
| 1661 | return |
| 1662 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1663 | async def edit(self, op_id, op_params, content): |
| 1664 | self.logger.info("ksu edit Enter") |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1665 | |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 1666 | _, workflow_name = await self.odu.launch_workflow( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1667 | "update_ksus", op_id, op_params, content |
| 1668 | ) |
| 1669 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 1670 | workflow_name |
| 1671 | ) |
| 1672 | self.logger.info( |
| 1673 | "Workflow Status: {} Workflow Message: {}".format( |
| 1674 | workflow_status, workflow_msg |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1675 | ) |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1676 | ) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1677 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1678 | for db_ksu in content: |
| 1679 | if workflow_status: |
| 1680 | db_ksu["resourceState"] = "IN_PROGRESS.GIT_SYNCED" |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1681 | else: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1682 | db_ksu["resourceState"] = "ERROR" |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1683 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1684 | db_ksu = self.update_operation_history(db_ksu, workflow_status, None) |
| 1685 | self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu) |
| 1686 | |
| garciadeblas | d842985 | 2024-10-17 15:30:30 +0200 | [diff] [blame] | 1687 | # Clean items used in the workflow, no matter if the workflow succeeded |
| 1688 | clean_status, clean_msg = await self.odu.clean_items_workflow( |
| 1689 | "create_ksus", op_id, op_params, content |
| 1690 | ) |
| 1691 | self.logger.info( |
| 1692 | f"clean_status is :{clean_status} and clean_msg is :{clean_msg}" |
| 1693 | ) |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1694 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1695 | resource_status, resource_msg = await self.check_resource_status( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1696 | "update_ksus", op_id, op_params, content |
| 1697 | ) |
| 1698 | self.logger.info( |
| 1699 | "Resource Status: {} Resource Message: {}".format( |
| 1700 | resource_status, resource_msg |
| 1701 | ) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1702 | ) |
| 1703 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1704 | for db_ksu in content: |
| 1705 | if resource_status: |
| 1706 | db_ksu["resourceState"] = "READY" |
| 1707 | else: |
| 1708 | db_ksu["resourceState"] = "ERROR" |
| 1709 | |
| 1710 | db_ksu = self.update_operation_history( |
| 1711 | db_ksu, workflow_status, resource_status |
| 1712 | ) |
| 1713 | |
| 1714 | for db_ksu, ksu_params in zip(content, op_params): |
| 1715 | db_ksu["operatingState"] = "IDLE" |
| 1716 | if workflow_status: |
| 1717 | db_ksu["name"] = ksu_params["name"] |
| 1718 | db_ksu["description"] = ksu_params["description"] |
| 1719 | db_ksu["profile"]["profile_type"] = ksu_params["profile"][ |
| 1720 | "profile_type" |
| 1721 | ] |
| 1722 | db_ksu["profile"]["_id"] = ksu_params["profile"]["_id"] |
| 1723 | db_ksu["oka"] = ksu_params["oka"] |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 1724 | db_ksu["current_operation"] = None |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1725 | self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu) |
| 1726 | |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1727 | return |
| 1728 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1729 | async def delete(self, op_id, op_params, content): |
| 1730 | self.logger.info("ksu delete Enter") |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1731 | |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 1732 | _, workflow_name = await self.odu.launch_workflow( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1733 | "delete_ksus", op_id, op_params, content |
| 1734 | ) |
| 1735 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 1736 | workflow_name |
| 1737 | ) |
| 1738 | self.logger.info( |
| 1739 | "Workflow Status: {} Workflow Message: {}".format( |
| 1740 | workflow_status, workflow_msg |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1741 | ) |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1742 | ) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1743 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1744 | for db_ksu in content: |
| 1745 | if workflow_status: |
| 1746 | db_ksu["state"] = "DELETED" |
| 1747 | db_ksu["resourceState"] = "IN_PROGRESS.GIT_SYNCED" |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1748 | else: |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1749 | db_ksu["state"] = "FAILED_DELETION" |
| 1750 | db_ksu["resourceState"] = "ERROR" |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1751 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1752 | db_ksu = self.update_operation_history(db_ksu, workflow_status, None) |
| 1753 | self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu) |
| 1754 | |
| 1755 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1756 | resource_status, resource_msg = await self.check_resource_status( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1757 | "delete_ksus", op_id, op_params, content |
| 1758 | ) |
| 1759 | self.logger.info( |
| 1760 | "Resource Status: {} Resource Message: {}".format( |
| 1761 | resource_status, resource_msg |
| 1762 | ) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1763 | ) |
| 1764 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1765 | for db_ksu in content: |
| 1766 | if resource_status: |
| 1767 | db_ksu["resourceState"] = "READY" |
| 1768 | else: |
| 1769 | db_ksu["resourceState"] = "ERROR" |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1770 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1771 | db_ksu = self.update_operation_history( |
| 1772 | db_ksu, workflow_status, resource_status |
| 1773 | ) |
| 1774 | |
| 1775 | for db_ksu in content: |
| 1776 | db_ksu["operatingState"] = "IDLE" |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 1777 | db_ksu["current_operation"] = None |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1778 | self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu) |
| 1779 | |
| 1780 | if db_ksu["state"] == "DELETED": |
| 1781 | self.db.del_one(self.db_collection, {"_id": db_ksu["_id"]}) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1782 | return |
| 1783 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1784 | async def clone(self, op_id, op_params, db_content): |
| 1785 | self.logger.info("ksu clone Enter") |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1786 | |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 1787 | _, workflow_name = await self.odu.launch_workflow( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1788 | "clone_ksus", op_id, op_params, db_content |
| 1789 | ) |
| 1790 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 1791 | workflow_name |
| 1792 | ) |
| 1793 | self.logger.info( |
| 1794 | "Workflow Status: {} Workflow Message: {}".format( |
| 1795 | workflow_status, workflow_msg |
| 1796 | ) |
| 1797 | ) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1798 | |
| 1799 | if workflow_status: |
| 1800 | db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED" |
| 1801 | else: |
| 1802 | db_content["resourceState"] = "ERROR" |
| 1803 | |
| 1804 | db_content = self.update_operation_history(db_content, workflow_status, None) |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1805 | self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1806 | |
| 1807 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1808 | resource_status, resource_msg = await self.check_resource_status( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1809 | "clone_ksus", op_id, op_params, db_content |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1810 | ) |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1811 | self.logger.info( |
| 1812 | "Resource Status: {} Resource Message: {}".format( |
| 1813 | resource_status, resource_msg |
| 1814 | ) |
| 1815 | ) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1816 | |
| 1817 | if resource_status: |
| 1818 | db_content["resourceState"] = "READY" |
| 1819 | else: |
| 1820 | db_content["resourceState"] = "ERROR" |
| 1821 | |
| 1822 | db_content = self.update_operation_history( |
| 1823 | db_content, workflow_status, resource_status |
| 1824 | ) |
| 1825 | |
| 1826 | db_content["operatingState"] = "IDLE" |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 1827 | db_content["current_operation"] = None |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1828 | self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1829 | return |
| 1830 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1831 | async def move(self, op_id, op_params, db_content): |
| 1832 | self.logger.info("ksu move Enter") |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1833 | |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 1834 | _, workflow_name = await self.odu.launch_workflow( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1835 | "move_ksus", op_id, op_params, db_content |
| 1836 | ) |
| 1837 | workflow_status, workflow_msg = await self.odu.check_workflow_status( |
| 1838 | workflow_name |
| 1839 | ) |
| 1840 | self.logger.info( |
| 1841 | "Workflow Status: {} Workflow Message: {}".format( |
| 1842 | workflow_status, workflow_msg |
| 1843 | ) |
| 1844 | ) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1845 | |
| 1846 | if workflow_status: |
| 1847 | db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED" |
| 1848 | else: |
| 1849 | db_content["resourceState"] = "ERROR" |
| 1850 | |
| 1851 | db_content = self.update_operation_history(db_content, workflow_status, None) |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1852 | self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1853 | |
| 1854 | if workflow_status: |
| garciadeblas | 7241228 | 2024-11-07 12:41:54 +0100 | [diff] [blame] | 1855 | resource_status, resource_msg = await self.check_resource_status( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1856 | "move_ksus", op_id, op_params, db_content |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1857 | ) |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1858 | self.logger.info( |
| 1859 | "Resource Status: {} Resource Message: {}".format( |
| 1860 | resource_status, resource_msg |
| 1861 | ) |
| 1862 | ) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1863 | if resource_status: |
| 1864 | db_content["resourceState"] = "READY" |
| 1865 | else: |
| 1866 | db_content["resourceState"] = "ERROR" |
| 1867 | |
| 1868 | db_content = self.update_operation_history( |
| 1869 | db_content, workflow_status, resource_status |
| 1870 | ) |
| 1871 | |
| 1872 | db_content["operatingState"] = "IDLE" |
| shahithya | 70a3fc9 | 2024-11-12 11:01:05 +0000 | [diff] [blame^] | 1873 | db_content["current_operation"] = None |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1874 | self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content) |
| yshah | 771dea8 | 2024-07-05 15:11:49 +0000 | [diff] [blame] | 1875 | return |