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