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