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