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