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