blob: 6074155b75369ccbfd79bd8a78c3adad816eaab1 [file] [log] [blame]
rshri932105f2024-07-05 15:11:55 +00001# -*- 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
21import logging
22from osm_lcm.lcm_utils import LcmBase
23from copy import deepcopy
24from osm_lcm import odu_workflows
25from osm_lcm import vim_sdn
26
27
28class ClusterLcm(LcmBase):
garciadeblas96b94f52024-07-08 16:18:21 +020029 db_collection = "clusters"
rshri932105f2024-07-05 15:11:55 +000030
31 def __init__(self, msg, lcm_tasks, config):
32 """
33 Init, Connect to database, filesystem storage, and messaging
34 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
35 :return: None
36 """
37
garciadeblas40539872024-09-11 14:28:38 +020038 self.logger = logging.getLogger("lcm.gitops")
rshri932105f2024-07-05 15:11:55 +000039 self.lcm_tasks = lcm_tasks
40 self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config)
41 self.regist = vim_sdn.K8sClusterLcm(msg, self.lcm_tasks, config)
42
43 super().__init__(msg, self.logger)
44
garciadeblas96b94f52024-07-08 16:18:21 +020045 async def create(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +000046 self.logger.info("cluster Create Enter")
garciadeblas96b94f52024-07-08 16:18:21 +020047 db_cluster = content["cluster"]
rshri932105f2024-07-05 15:11:55 +000048
garciadeblas96b94f52024-07-08 16:18:21 +020049 workflow_name = await self.odu.launch_workflow(
50 "create_cluster", op_id, op_params, content
51 )
rshri932105f2024-07-05 15:11:55 +000052 self.logger.info("workflow_name is :{}".format(workflow_name))
53
garciadeblas96b94f52024-07-08 16:18:21 +020054 workflow_status, workflow_msg = await self.odu.check_workflow_status(
55 workflow_name
56 )
rshri932105f2024-07-05 15:11:55 +000057 self.logger.info(
58 "workflow_status is :{} and workflow_msg is :{}".format(
59 workflow_status, workflow_msg
60 )
61 )
62 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +020063 db_cluster["state"] = "CREATED"
64 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +000065 else:
garciadeblas96b94f52024-07-08 16:18:21 +020066 db_cluster["state"] = "FAILED_CREATION"
67 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +000068 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +020069 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
70 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
rshri932105f2024-07-05 15:11:55 +000071
garciadeblas28bff0f2024-09-16 12:53:07 +020072 # Clean items used in the workflow, no matter if the workflow succeeded
73 clean_status, clean_msg = await self.odu.clean_items_workflow(
74 "create_cluster", op_id, op_params, content
75 )
76 self.logger.info(
77 f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
78 )
79
rshri932105f2024-07-05 15:11:55 +000080 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +020081 resource_status, resource_msg = await self.odu.check_resource_status(
82 "create_cluster", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +000083 )
84 self.logger.info(
85 "resource_status is :{} and resource_msg is :{}".format(
86 resource_status, resource_msg
87 )
88 )
89 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +020090 db_cluster["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +000091 else:
garciadeblas96b94f52024-07-08 16:18:21 +020092 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +000093
garciadeblas96b94f52024-07-08 16:18:21 +020094 db_cluster["operatingState"] = "IDLE"
95 db_cluster = self.update_operation_history(
96 db_cluster, workflow_status, resource_status
rshri932105f2024-07-05 15:11:55 +000097 )
garciadeblas96b94f52024-07-08 16:18:21 +020098 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
99 self.update_profile_state(db_cluster, workflow_status, resource_status)
rshri932105f2024-07-05 15:11:55 +0000100 return
101
garciadeblas96b94f52024-07-08 16:18:21 +0200102 def update_profile_state(self, db_cluster, workflow_status, resource_status):
rshri932105f2024-07-05 15:11:55 +0000103 profiles = [
104 "infra_controller_profiles",
105 "infra_config_profiles",
106 "app_profiles",
107 "resource_profiles",
108 ]
109 profiles_collection = {
110 "infra_controller_profiles": "k8sinfra_controller",
111 "infra_config_profiles": "k8sinfra_config",
112 "app_profiles": "k8sapp",
113 "resource_profiles": "k8sresource",
114 }
115 for profile_type in profiles:
garciadeblas96b94f52024-07-08 16:18:21 +0200116 profile_id = db_cluster[profile_type]
rshri932105f2024-07-05 15:11:55 +0000117 self.logger.info("profile id is : {}".format(profile_id))
118 db_collection = profiles_collection[profile_type]
119 self.logger.info("the db_collection is :{}".format(db_collection))
120 db_profile = self.db.get_one(db_collection, {"_id": profile_id})
121 self.logger.info("the db_profile is :{}".format(db_profile))
garciadeblas96b94f52024-07-08 16:18:21 +0200122 db_profile["state"] = db_cluster["state"]
123 db_profile["resourceState"] = db_cluster["resourceState"]
124 db_profile["operatingState"] = db_cluster["operatingState"]
rshri932105f2024-07-05 15:11:55 +0000125 db_profile = self.update_operation_history(
126 db_profile, workflow_status, resource_status
127 )
128 self.logger.info("the db_profile is :{}".format(db_profile))
129 self.db.set_one(db_collection, {"_id": db_profile["_id"]}, db_profile)
130
garciadeblas96b94f52024-07-08 16:18:21 +0200131 async def delete(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000132 self.logger.info("cluster delete Enter")
garciadeblas96b94f52024-07-08 16:18:21 +0200133 db_cluster = content["cluster"]
rshri932105f2024-07-05 15:11:55 +0000134
garciadeblas96b94f52024-07-08 16:18:21 +0200135 workflow_name = await self.odu.launch_workflow(
136 "delete_cluster", op_id, op_params, content
137 )
rshri932105f2024-07-05 15:11:55 +0000138 self.logger.info("workflow_name is :{}".format(workflow_name))
139
garciadeblas96b94f52024-07-08 16:18:21 +0200140 workflow_status, workflow_msg = await self.odu.check_workflow_status(
141 workflow_name
142 )
rshri932105f2024-07-05 15:11:55 +0000143 self.logger.info(
144 "workflow_status is :{} and workflow_msg is :{}".format(
145 workflow_status, workflow_msg
146 )
147 )
148 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200149 db_cluster["state"] = "DELETED"
150 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +0000151 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200152 db_cluster["state"] = "FAILED_DELETION"
153 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000154 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +0200155 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
156 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
rshri932105f2024-07-05 15:11:55 +0000157
158 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200159 resource_status, resource_msg = await self.odu.check_resource_status(
160 "delete_cluster", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000161 )
162 self.logger.info(
163 "resource_status is :{} and resource_msg is :{}".format(
164 resource_status, resource_msg
165 )
166 )
167 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200168 db_cluster["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +0000169 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200170 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000171
garciadeblas96b94f52024-07-08 16:18:21 +0200172 db_cluster["operatingState"] = "IDLE"
173 db_cluster = self.update_operation_history(
174 db_cluster, workflow_status, resource_status
175 )
176 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
rshri932105f2024-07-05 15:11:55 +0000177
garciadeblas96b94f52024-07-08 16:18:21 +0200178 # To delete it from DB
179 if db_cluster["state"] == "DELETED":
180 self.delete_cluster(db_cluster)
rshri932105f2024-07-05 15:11:55 +0000181 return
182
garciadeblas96b94f52024-07-08 16:18:21 +0200183 def delete_cluster(self, db_cluster):
184 # Actually, item_content is equal to db_cluster
185 # item_content = self.db.get_one("clusters", {"_id": db_cluster["_id"]})
186 # self.logger.debug("item_content is : {}".format(item_content))
rshri932105f2024-07-05 15:11:55 +0000187
rshri932105f2024-07-05 15:11:55 +0000188 # detach profiles
189 update_dict = None
190 profiles_to_detach = [
191 "infra_controller_profiles",
192 "infra_config_profiles",
193 "app_profiles",
194 "resource_profiles",
195 ]
196 profiles_collection = {
197 "infra_controller_profiles": "k8sinfra_controller",
198 "infra_config_profiles": "k8sinfra_config",
199 "app_profiles": "k8sapp",
200 "resource_profiles": "k8sresource",
201 }
202 for profile_type in profiles_to_detach:
garciadeblas96b94f52024-07-08 16:18:21 +0200203 if db_cluster.get(profile_type):
garciadeblasc2552852024-10-22 12:39:32 +0200204 self.logger.debug("the profile_type is :{}".format(profile_type))
garciadeblas96b94f52024-07-08 16:18:21 +0200205 profile_ids = db_cluster[profile_type]
garciadeblasc2552852024-10-22 12:39:32 +0200206 self.logger.debug("the profile_ids is :{}".format(profile_ids))
rshri932105f2024-07-05 15:11:55 +0000207 profile_ids_copy = deepcopy(profile_ids)
garciadeblasc2552852024-10-22 12:39:32 +0200208 self.logger.debug(
209 "the profile_ids_copy is :{}".format(profile_ids_copy)
210 )
rshri932105f2024-07-05 15:11:55 +0000211 for profile_id in profile_ids_copy:
garciadeblasc2552852024-10-22 12:39:32 +0200212 self.logger.debug("the profile_id is :{}".format(profile_id))
rshri932105f2024-07-05 15:11:55 +0000213 db_collection = profiles_collection[profile_type]
garciadeblasc2552852024-10-22 12:39:32 +0200214 self.logger.debug("the db_collection is :{}".format(db_collection))
rshri932105f2024-07-05 15:11:55 +0000215 db_profile = self.db.get_one(db_collection, {"_id": profile_id})
garciadeblasc2552852024-10-22 12:39:32 +0200216 self.logger.debug("the db_profile is :{}".format(db_profile))
217 self.logger.debug(
garciadeblas96b94f52024-07-08 16:18:21 +0200218 "the item_content name is :{}".format(db_cluster["name"])
rshri932105f2024-07-05 15:11:55 +0000219 )
garciadeblasc2552852024-10-22 12:39:32 +0200220 self.logger.debug(
rshri932105f2024-07-05 15:11:55 +0000221 "the db_profile name is :{}".format(db_profile["name"])
222 )
garciadeblas96b94f52024-07-08 16:18:21 +0200223 if db_cluster["name"] == db_profile["name"]:
garciadeblasc2552852024-10-22 12:39:32 +0200224 self.logger.debug("it is getting into if default")
rshri932105f2024-07-05 15:11:55 +0000225 self.db.del_one(db_collection, {"_id": profile_id})
226 else:
garciadeblasc2552852024-10-22 12:39:32 +0200227 self.logger.debug("it is getting into else non default")
rshri932105f2024-07-05 15:11:55 +0000228 profile_ids.remove(profile_id)
229 update_dict = {profile_type: profile_ids}
garciadeblasc2552852024-10-22 12:39:32 +0200230 self.logger.debug(f"the update dict is :{update_dict}")
rshri932105f2024-07-05 15:11:55 +0000231 self.db.set_one(
garciadeblas96b94f52024-07-08 16:18:21 +0200232 "clusters", {"_id": db_cluster["_id"]}, update_dict
rshri932105f2024-07-05 15:11:55 +0000233 )
garciadeblas96b94f52024-07-08 16:18:21 +0200234 self.db.del_one("clusters", {"_id": db_cluster["_id"]})
garciadeblasc2552852024-10-22 12:39:32 +0200235 self.logger.debug("the id is :{}".format(db_cluster["_id"]))
rshri932105f2024-07-05 15:11:55 +0000236
garciadeblas96b94f52024-07-08 16:18:21 +0200237 async def attach_profile(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000238 self.logger.info("profile attach Enter")
garciadeblas96b94f52024-07-08 16:18:21 +0200239 db_cluster = content["cluster"]
240 db_profile = content["profile"]
241 profile_type = db_profile["profile_type"]
242 profile_id = db_profile["_id"]
rshri932105f2024-07-05 15:11:55 +0000243 self.logger.info("profile type is : {}".format(profile_type))
rshri932105f2024-07-05 15:11:55 +0000244 self.logger.info("profile id is : {}".format(profile_id))
245
garciadeblas96b94f52024-07-08 16:18:21 +0200246 workflow_name = await self.odu.launch_workflow(
247 "attach_profile_to_cluster", op_id, op_params, content
248 )
rshri932105f2024-07-05 15:11:55 +0000249 self.logger.info("workflow_name is :{}".format(workflow_name))
250
garciadeblas96b94f52024-07-08 16:18:21 +0200251 workflow_status, workflow_msg = await self.odu.check_workflow_status(
252 workflow_name
253 )
rshri932105f2024-07-05 15:11:55 +0000254 self.logger.info(
255 "workflow_status is :{} and workflow_msg is :{}".format(
256 workflow_status, workflow_msg
257 )
258 )
259 if workflow_status:
260 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
261 else:
262 db_cluster["resourceState"] = "ERROR"
263 # has to call update_operation_history return content
264 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
265 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
266
267 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200268 resource_status, resource_msg = await self.odu.check_resource_status(
269 "attach_profile_to_cluster", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000270 )
271 self.logger.info(
272 "resource_status is :{} and resource_msg is :{}".format(
273 resource_status, resource_msg
274 )
275 )
276 if resource_status:
277 db_cluster["resourceState"] = "READY"
278 else:
279 db_cluster["resourceState"] = "ERROR"
280
281 db_cluster["operatingState"] = "IDLE"
282 db_cluster = self.update_operation_history(
283 db_cluster, workflow_status, resource_status
284 )
rshri932105f2024-07-05 15:11:55 +0000285 profile_list = db_cluster[profile_type]
286 self.logger.info("profile list is : {}".format(profile_list))
287 if resource_status:
288 self.logger.info("it is getting into resource status true")
289 profile_list.append(profile_id)
290 self.logger.info("profile list is : {}".format(profile_list))
291 db_cluster[profile_type] = profile_list
292 self.logger.info("db cluster is : {}".format(db_cluster))
293 # update_dict = {item: profile_list}
294 # self.logger.info("the update_dict is :{}".format(update_dict))
295 # self.db.set_one(self.topic, filter_q, update_dict)
296 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
297
298 return
299
garciadeblas96b94f52024-07-08 16:18:21 +0200300 async def detach_profile(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000301 self.logger.info("profile dettach Enter")
garciadeblas96b94f52024-07-08 16:18:21 +0200302 db_cluster = content["cluster"]
303 db_profile = content["profile"]
304 profile_type = db_profile["profile_type"]
305 profile_id = db_profile["_id"]
rshri932105f2024-07-05 15:11:55 +0000306 self.logger.info("profile type is : {}".format(profile_type))
rshri932105f2024-07-05 15:11:55 +0000307 self.logger.info("profile id is : {}".format(profile_id))
308
garciadeblas96b94f52024-07-08 16:18:21 +0200309 workflow_name = await self.odu.launch_workflow(
310 "detach_profile_from_cluster", op_id, op_params, content
311 )
rshri932105f2024-07-05 15:11:55 +0000312 self.logger.info("workflow_name is :{}".format(workflow_name))
313
garciadeblas96b94f52024-07-08 16:18:21 +0200314 workflow_status, workflow_msg = await self.odu.check_workflow_status(
315 workflow_name
316 )
rshri932105f2024-07-05 15:11:55 +0000317 self.logger.info(
318 "workflow_status is :{} and workflow_msg is :{}".format(
319 workflow_status, workflow_msg
320 )
321 )
322 if workflow_status:
323 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
324 else:
325 db_cluster["resourceState"] = "ERROR"
326 # has to call update_operation_history return content
327 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
328 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
329
330 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200331 resource_status, resource_msg = await self.odu.check_resource_status(
332 "detach_profile_from_cluster", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000333 )
334 self.logger.info(
335 "resource_status is :{} and resource_msg is :{}".format(
336 resource_status, resource_msg
337 )
338 )
339 if resource_status:
340 db_cluster["resourceState"] = "READY"
341 else:
342 db_cluster["resourceState"] = "ERROR"
343
344 db_cluster["operatingState"] = "IDLE"
345 db_cluster = self.update_operation_history(
346 db_cluster, workflow_status, resource_status
347 )
rshri932105f2024-07-05 15:11:55 +0000348 profile_list = db_cluster[profile_type]
349 self.logger.info("profile list is : {}".format(profile_list))
350 if resource_status:
351 self.logger.info("it is getting into resource status true")
352 profile_list.remove(profile_id)
353 self.logger.info("profile list is : {}".format(profile_list))
354 db_cluster[profile_type] = profile_list
355 self.logger.info("db cluster is : {}".format(db_cluster))
356 # update_dict = {item: profile_list}
357 # self.logger.info("the update_dict is :{}".format(update_dict))
358 # self.db.set_one(self.topic, filter_q, update_dict)
359 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
360
361 return
362
garciadeblas96b94f52024-07-08 16:18:21 +0200363 async def register(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000364 self.logger.info("cluster register enter")
garciadeblas96b94f52024-07-08 16:18:21 +0200365 db_cluster = content["cluster"]
rshri932105f2024-07-05 15:11:55 +0000366
garciadeblas96b94f52024-07-08 16:18:21 +0200367 workflow_name = await self.odu.launch_workflow(
368 "register_cluster", op_id, op_params, content
369 )
rshri932105f2024-07-05 15:11:55 +0000370 self.logger.info("workflow_name is :{}".format(workflow_name))
371
garciadeblas96b94f52024-07-08 16:18:21 +0200372 workflow_status, workflow_msg = await self.odu.check_workflow_status(
373 workflow_name
374 )
rshri932105f2024-07-05 15:11:55 +0000375 self.logger.info(
376 "workflow_status is :{} and workflow_msg is :{}".format(
377 workflow_status, workflow_msg
378 )
379 )
380 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200381 db_cluster["state"] = "CREATED"
382 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +0000383 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200384 db_cluster["state"] = "FAILED_CREATION"
385 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000386 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +0200387 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
388 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
rshri932105f2024-07-05 15:11:55 +0000389
garciadeblasdde3a312024-09-17 13:25:06 +0200390 # Clean items used in the workflow, no matter if the workflow succeeded
391 clean_status, clean_msg = await self.odu.clean_items_workflow(
392 "register_cluster", op_id, op_params, content
393 )
394 self.logger.info(
395 f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
396 )
397
rshri932105f2024-07-05 15:11:55 +0000398 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200399 resource_status, resource_msg = await self.odu.check_resource_status(
400 "register_cluster", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000401 )
402 self.logger.info(
403 "resource_status is :{} and resource_msg is :{}".format(
404 resource_status, resource_msg
405 )
406 )
407 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200408 db_cluster["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +0000409 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200410 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000411
garciadeblas96b94f52024-07-08 16:18:21 +0200412 db_cluster["operatingState"] = "IDLE"
413 db_cluster = self.update_operation_history(
414 db_cluster, workflow_status, resource_status
rshri932105f2024-07-05 15:11:55 +0000415 )
garciadeblas96b94f52024-07-08 16:18:21 +0200416 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
417 self.update_profile_state(db_cluster, workflow_status, resource_status)
rshri932105f2024-07-05 15:11:55 +0000418 return
419
garciadeblas96b94f52024-07-08 16:18:21 +0200420 async def deregister(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000421 self.logger.info("cluster deregister enter")
garciadeblas96b94f52024-07-08 16:18:21 +0200422 db_cluster = content["cluster"]
rshri932105f2024-07-05 15:11:55 +0000423
garciadeblas96b94f52024-07-08 16:18:21 +0200424 self.logger.info("db_cluster is : {}".format(db_cluster))
rshri932105f2024-07-05 15:11:55 +0000425
garciadeblas96b94f52024-07-08 16:18:21 +0200426 workflow_name = await self.odu.launch_workflow(
427 "deregister_cluster", op_id, op_params, content
428 )
rshri932105f2024-07-05 15:11:55 +0000429 self.logger.info("workflow_name is :{}".format(workflow_name))
430
garciadeblas96b94f52024-07-08 16:18:21 +0200431 workflow_status, workflow_msg = await self.odu.check_workflow_status(
432 workflow_name
433 )
rshri932105f2024-07-05 15:11:55 +0000434 self.logger.info(
435 "workflow_status is :{} and workflow_msg is :{}".format(
436 workflow_status, workflow_msg
437 )
438 )
439 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200440 db_cluster["state"] = "DELETED"
441 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +0000442 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200443 db_cluster["state"] = "FAILED_DELETION"
444 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000445 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +0200446 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
447 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
rshri932105f2024-07-05 15:11:55 +0000448
449 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200450 resource_status, resource_msg = await self.odu.check_resource_status(
451 "deregister_cluster", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000452 )
453 self.logger.info(
454 "resource_status is :{} and resource_msg is :{}".format(
455 resource_status, resource_msg
456 )
457 )
458 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200459 db_cluster["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +0000460 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200461 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000462
garciadeblas96b94f52024-07-08 16:18:21 +0200463 db_cluster["operatingState"] = "IDLE"
464 db_cluster = self.update_operation_history(
465 db_cluster, workflow_status, resource_status
466 )
467 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
rshri932105f2024-07-05 15:11:55 +0000468
garciadeblas96b94f52024-07-08 16:18:21 +0200469 # To delete it from DB
470 if db_cluster["state"] == "DELETED":
471 self.db.del_one("clusters", {"_id": db_cluster["_id"]})
rshri932105f2024-07-05 15:11:55 +0000472 return
473
garciadeblas96b94f52024-07-08 16:18:21 +0200474 async def get_creds(self, db_cluster):
475 self.logger.info("Cluster get creds Enter")
476 result, cluster_creds = await self.odu.get_cluster_credentials(db_cluster)
477 if result:
478 db_cluster["credentials"] = cluster_creds
479 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
yshah771dea82024-07-05 15:11:49 +0000480 return
481
garciadeblas96b94f52024-07-08 16:18:21 +0200482 async def update(self, op_id, op_params, content):
483 self.logger.info("Cluster update Enter")
484 db_cluster = content["cluster"]
yshah771dea82024-07-05 15:11:49 +0000485
garciadeblas96b94f52024-07-08 16:18:21 +0200486 workflow_name = await self.odu.launch_workflow(
487 "update_cluster", op_id, op_params, content
488 )
489 workflow_status, workflow_msg = await self.odu.check_workflow_status(
490 workflow_name
491 )
492 self.logger.info(
493 "Workflow Status: {} Workflow Message: {}".format(
494 workflow_status, workflow_msg
yshah771dea82024-07-05 15:11:49 +0000495 )
garciadeblas96b94f52024-07-08 16:18:21 +0200496 )
497
498 if workflow_status:
499 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
500 else:
501 db_cluster["resourceState"] = "ERROR"
502
503 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
504 # self.logger.info("Db content: {}".format(db_content))
505 # self.db.set_one(self.db_collection, {"_id": _id}, db_cluster)
506 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
507
garciadeblas28bff0f2024-09-16 12:53:07 +0200508 # Clean items used in the workflow, no matter if the workflow succeeded
509 clean_status, clean_msg = await self.odu.clean_items_workflow(
510 "update_cluster", op_id, op_params, content
511 )
512 self.logger.info(
513 f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
514 )
garciadeblas96b94f52024-07-08 16:18:21 +0200515 if workflow_status:
516 resource_status, resource_msg = await self.odu.check_resource_status(
517 "update_cluster", op_id, op_params, content
518 )
519 self.logger.info(
520 "Resource Status: {} Resource Message: {}".format(
521 resource_status, resource_msg
522 )
523 )
yshah771dea82024-07-05 15:11:49 +0000524
525 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200526 db_cluster["resourceState"] = "READY"
yshah771dea82024-07-05 15:11:49 +0000527 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200528 db_cluster["resourceState"] = "ERROR"
yshah771dea82024-07-05 15:11:49 +0000529
garciadeblas96b94f52024-07-08 16:18:21 +0200530 db_cluster["operatingState"] = "IDLE"
531 db_cluster = self.update_operation_history(
532 db_cluster, workflow_status, resource_status
533 )
534 # self.logger.info("db_cluster: {}".format(db_cluster))
535 # TODO: verify enxtcondition
536 # For the moment, if the workflow completed successfully, then we update the db accordingly.
537 if workflow_status:
538 if "k8s_version" in op_params:
539 db_cluster["k8s_version"] = op_params["k8s_version"]
540 elif "node_count" in op_params:
541 db_cluster["node_count"] = op_params["node_count"]
542 # self.db.set_one(self.db_collection, {"_id": _id}, db_content)
543 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
yshah771dea82024-07-05 15:11:49 +0000544 return
545
546
547class CloudCredentialsLcm(LcmBase):
548 db_collection = "vim_accounts"
549
550 def __init__(self, msg, lcm_tasks, config):
551 """
552 Init, Connect to database, filesystem storage, and messaging
553 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
554 :return: None
555 """
556
garciadeblas40539872024-09-11 14:28:38 +0200557 self.logger = logging.getLogger("lcm.gitops")
yshah771dea82024-07-05 15:11:49 +0000558 self.lcm_tasks = lcm_tasks
559 self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config)
560
561 super().__init__(msg, self.logger)
562
garciadeblas96b94f52024-07-08 16:18:21 +0200563 async def add(self, op_id, op_params, content):
yshah771dea82024-07-05 15:11:49 +0000564 self.logger.info("Cloud Credentials create")
565 workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +0200566 "create_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000567 )
568
569 workflow_status, workflow_msg = await self.odu.check_workflow_status(
570 workflow_name
571 )
572
573 self.logger.info(
574 "Workflow Status: {} Workflow Msg: {}".format(workflow_status, workflow_msg)
575 )
576
garciadeblas28bff0f2024-09-16 12:53:07 +0200577 # Clean items used in the workflow, no matter if the workflow succeeded
578 clean_status, clean_msg = await self.odu.clean_items_workflow(
579 "create_cloud_credentials", op_id, op_params, content
580 )
581 self.logger.info(
582 f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
583 )
584
yshah771dea82024-07-05 15:11:49 +0000585 if workflow_status:
586 resource_status, resource_msg = await self.odu.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +0200587 "create_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000588 )
589 self.logger.info(
590 "Resource Status: {} Resource Message: {}".format(
591 resource_status, resource_msg
592 )
593 )
garciadeblas15b8a302024-09-23 12:40:13 +0200594
595 content["_admin"]["operationalState"] = "ENABLED"
596 for operation in content["_admin"]["operations"]:
597 if operation["lcmOperationType"] == "create":
598 operation["operationState"] = "ENABLED"
599 self.logger.info("Content : {}".format(content))
600 self.db.set_one("vim_accounts", {"_id": content["_id"]}, content)
601
yshah771dea82024-07-05 15:11:49 +0000602 return
603
garciadeblas96b94f52024-07-08 16:18:21 +0200604 async def edit(self, op_id, op_params, content):
yshah771dea82024-07-05 15:11:49 +0000605 workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +0200606 "update_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000607 )
608 workflow_status, workflow_msg = await self.odu.check_workflow_status(
609 workflow_name
610 )
611 self.logger.info(
612 "Workflow Status: {} Workflow Msg: {}".format(workflow_status, workflow_msg)
613 )
614
garciadeblas28bff0f2024-09-16 12:53:07 +0200615 # Clean items used in the workflow, no matter if the workflow succeeded
616 clean_status, clean_msg = await self.odu.clean_items_workflow(
617 "update_cloud_credentials", op_id, op_params, content
618 )
619 self.logger.info(
620 f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
621 )
622
yshah771dea82024-07-05 15:11:49 +0000623 if workflow_status:
624 resource_status, resource_msg = await self.odu.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +0200625 "update_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000626 )
627 self.logger.info(
628 "Resource Status: {} Resource Message: {}".format(
629 resource_status, resource_msg
630 )
631 )
632 return
633
garciadeblas96b94f52024-07-08 16:18:21 +0200634 async def remove(self, op_id, op_params, content):
yshah771dea82024-07-05 15:11:49 +0000635 self.logger.info("Cloud Credentials delete")
636 workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +0200637 "delete_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000638 )
639 workflow_status, workflow_msg = await self.odu.check_workflow_status(
640 workflow_name
641 )
642 self.logger.info(
643 "Workflow Status: {} Workflow Msg: {}".format(workflow_status, workflow_msg)
644 )
645
646 if workflow_status:
647 resource_status, resource_msg = await self.odu.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +0200648 "delete_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000649 )
650 self.logger.info(
651 "Resource Status: {} Resource Message: {}".format(
652 resource_status, resource_msg
653 )
654 )
655 self.db.del_one(self.db_collection, {"_id": content["_id"]})
656 return
657
rshri932105f2024-07-05 15:11:55 +0000658
659class K8sAppLcm(LcmBase):
660 def __init__(self, msg, lcm_tasks, config):
661 """
662 Init, Connect to database, filesystem storage, and messaging
663 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
664 :return: None
665 """
666
garciadeblas40539872024-09-11 14:28:38 +0200667 self.logger = logging.getLogger("lcm.gitops")
rshri932105f2024-07-05 15:11:55 +0000668 self.lcm_tasks = lcm_tasks
669 self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config)
670
671 super().__init__(msg, self.logger)
672
garciadeblas96b94f52024-07-08 16:18:21 +0200673 async def create(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000674 self.logger.info("App Create Enter")
675
garciadeblas96b94f52024-07-08 16:18:21 +0200676 workflow_name = await self.odu.launch_workflow(
677 "create_profile", op_id, op_params, content
678 )
rshri932105f2024-07-05 15:11:55 +0000679 self.logger.info("workflow_name is :{}".format(workflow_name))
680
garciadeblas96b94f52024-07-08 16:18:21 +0200681 workflow_status, workflow_msg = await self.odu.check_workflow_status(
682 workflow_name
683 )
rshri932105f2024-07-05 15:11:55 +0000684 self.logger.info(
685 "workflow_status is :{} and workflow_msg is :{}".format(
686 workflow_status, workflow_msg
687 )
688 )
689 if workflow_status:
690 content["state"] = "CREATED"
691 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
692 else:
693 content["state"] = "FAILED_CREATION"
694 content["resourceState"] = "ERROR"
695 # has to call update_operation_history return content
696 content = self.update_operation_history(content, workflow_status, None)
697 self.db.set_one("k8sapp", {"_id": content["_id"]}, content)
698
699 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200700 resource_status, resource_msg = await self.odu.check_resource_status(
701 "create_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000702 )
703 self.logger.info(
704 "resource_status is :{} and resource_msg is :{}".format(
705 resource_status, resource_msg
706 )
707 )
708 if resource_status:
709 content["resourceState"] = "READY"
710 else:
711 content["resourceState"] = "ERROR"
712
713 content["operatingState"] = "IDLE"
714 content = self.update_operation_history(
715 content, workflow_status, resource_status
716 )
717 self.db.set_one("k8sapp", {"_id": content["_id"]}, content)
718
719 return
720
garciadeblas96b94f52024-07-08 16:18:21 +0200721 async def delete(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000722 self.logger.info("App delete Enter")
rshri932105f2024-07-05 15:11:55 +0000723
garciadeblas96b94f52024-07-08 16:18:21 +0200724 workflow_name = await self.odu.launch_workflow(
725 "delete_profile", op_id, op_params, content
726 )
rshri932105f2024-07-05 15:11:55 +0000727 self.logger.info("workflow_name is :{}".format(workflow_name))
728
garciadeblas96b94f52024-07-08 16:18:21 +0200729 workflow_status, workflow_msg = await self.odu.check_workflow_status(
730 workflow_name
731 )
rshri932105f2024-07-05 15:11:55 +0000732 self.logger.info(
733 "workflow_status is :{} and workflow_msg is :{}".format(
734 workflow_status, workflow_msg
735 )
736 )
737 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200738 content["state"] = "DELETED"
739 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +0000740 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200741 content["state"] = "FAILED_DELETION"
742 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000743 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +0200744 content = self.update_operation_history(content, workflow_status, None)
rshri932105f2024-07-05 15:11:55 +0000745 self.db.set_one("k8sapp", {"_id": content["_id"]}, content)
746
747 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200748 resource_status, resource_msg = await self.odu.check_resource_status(
749 "delete_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000750 )
751 self.logger.info(
752 "resource_status is :{} and resource_msg is :{}".format(
753 resource_status, resource_msg
754 )
755 )
756 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200757 content["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +0000758 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200759 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000760
garciadeblas96b94f52024-07-08 16:18:21 +0200761 content["operatingState"] = "IDLE"
762 content = self.update_operation_history(
763 content, workflow_status, resource_status
764 )
765 self.db.set_one("k8sapp", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +0000766
garciadeblas96b94f52024-07-08 16:18:21 +0200767 # To delete it from DB
768 if content["state"] == "DELETED":
rshri932105f2024-07-05 15:11:55 +0000769 self.db.del_one("k8sapp", {"_id": content["_id"]})
770 return
771
772
773class K8sResourceLcm(LcmBase):
774 def __init__(self, msg, lcm_tasks, config):
775 """
776 Init, Connect to database, filesystem storage, and messaging
777 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
778 :return: None
779 """
780
garciadeblas40539872024-09-11 14:28:38 +0200781 self.logger = logging.getLogger("lcm.gitops")
rshri932105f2024-07-05 15:11:55 +0000782 self.lcm_tasks = lcm_tasks
783 self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config)
784
785 super().__init__(msg, self.logger)
786
garciadeblas96b94f52024-07-08 16:18:21 +0200787 async def create(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000788 self.logger.info("Resource Create Enter")
789
garciadeblas96b94f52024-07-08 16:18:21 +0200790 workflow_name = await self.odu.launch_workflow(
791 "create_profile", op_id, op_params, content
792 )
rshri932105f2024-07-05 15:11:55 +0000793 self.logger.info("workflow_name is :{}".format(workflow_name))
794
garciadeblas96b94f52024-07-08 16:18:21 +0200795 workflow_status, workflow_msg = await self.odu.check_workflow_status(
796 workflow_name
797 )
rshri932105f2024-07-05 15:11:55 +0000798 self.logger.info(
799 "workflow_status is :{} and workflow_msg is :{}".format(
800 workflow_status, workflow_msg
801 )
802 )
803 if workflow_status:
804 content["state"] = "CREATED"
805 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
806 else:
807 content["state"] = "FAILED_CREATION"
808 content["resourceState"] = "ERROR"
809 # has to call update_operation_history return content
810 content = self.update_operation_history(content, workflow_status, None)
811 self.db.set_one("k8sresource", {"_id": content["_id"]}, content)
812
813 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200814 resource_status, resource_msg = await self.odu.check_resource_status(
815 "create_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000816 )
817 self.logger.info(
818 "resource_status is :{} and resource_msg is :{}".format(
819 resource_status, resource_msg
820 )
821 )
822 if resource_status:
823 content["resourceState"] = "READY"
824 else:
825 content["resourceState"] = "ERROR"
826
827 content["operatingState"] = "IDLE"
828 content = self.update_operation_history(
829 content, workflow_status, resource_status
830 )
831 self.db.set_one("k8sresource", {"_id": content["_id"]}, content)
832
833 return
834
garciadeblas96b94f52024-07-08 16:18:21 +0200835 async def delete(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000836 self.logger.info("Resource delete Enter")
garciadeblas96b94f52024-07-08 16:18:21 +0200837 content = self.db.get_one("k8sresource", {"_id": content["_id"]})
rshri932105f2024-07-05 15:11:55 +0000838
garciadeblas96b94f52024-07-08 16:18:21 +0200839 workflow_name = await self.odu.launch_workflow(
840 "delete_profile", op_id, op_params, content
841 )
rshri932105f2024-07-05 15:11:55 +0000842 self.logger.info("workflow_name is :{}".format(workflow_name))
843
garciadeblas96b94f52024-07-08 16:18:21 +0200844 workflow_status, workflow_msg = await self.odu.check_workflow_status(
845 workflow_name
846 )
rshri932105f2024-07-05 15:11:55 +0000847 self.logger.info(
848 "workflow_status is :{} and workflow_msg is :{}".format(
849 workflow_status, workflow_msg
850 )
851 )
852 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200853 content["state"] = "DELETED"
854 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +0000855 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200856 content["state"] = "FAILED_DELETION"
857 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000858 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +0200859 content = self.update_operation_history(content, workflow_status, None)
860 self.db.set_one("k8sresource", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +0000861
862 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200863 resource_status, resource_msg = await self.odu.check_resource_status(
864 "delete_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000865 )
866 self.logger.info(
867 "resource_status is :{} and resource_msg is :{}".format(
868 resource_status, resource_msg
869 )
870 )
871 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200872 content["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +0000873 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200874 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000875
garciadeblas96b94f52024-07-08 16:18:21 +0200876 content["operatingState"] = "IDLE"
877 content = self.update_operation_history(
878 content, workflow_status, resource_status
879 )
880 self.db.set_one("k8sresource", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +0000881
garciadeblas96b94f52024-07-08 16:18:21 +0200882 # To delete it from DB
883 if content["state"] == "DELETED":
rshri932105f2024-07-05 15:11:55 +0000884 self.db.del_one("k8sresource", {"_id": content["_id"]})
885 return
886
887
888class K8sInfraControllerLcm(LcmBase):
889 def __init__(self, msg, lcm_tasks, config):
890 """
891 Init, Connect to database, filesystem storage, and messaging
892 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
893 :return: None
894 """
895
garciadeblas40539872024-09-11 14:28:38 +0200896 self.logger = logging.getLogger("lcm.gitops")
rshri932105f2024-07-05 15:11:55 +0000897 self.lcm_tasks = lcm_tasks
898 self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config)
899
900 super().__init__(msg, self.logger)
901
garciadeblas96b94f52024-07-08 16:18:21 +0200902 async def create(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000903 self.logger.info("Infra controller Create Enter")
904
garciadeblas96b94f52024-07-08 16:18:21 +0200905 workflow_name = await self.odu.launch_workflow(
906 "create_profile", op_id, op_params, content
907 )
rshri932105f2024-07-05 15:11:55 +0000908 self.logger.info("workflow_name is :{}".format(workflow_name))
909
garciadeblas96b94f52024-07-08 16:18:21 +0200910 workflow_status, workflow_msg = await self.odu.check_workflow_status(
911 workflow_name
912 )
rshri932105f2024-07-05 15:11:55 +0000913 self.logger.info(
914 "workflow_status is :{} and workflow_msg is :{}".format(
915 workflow_status, workflow_msg
916 )
917 )
918 if workflow_status:
919 content["state"] = "CREATED"
920 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
921 else:
922 content["state"] = "FAILED_CREATION"
923 content["resourceState"] = "ERROR"
924 # has to call update_operation_history return content
925 content = self.update_operation_history(content, workflow_status, None)
926 self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content)
927
928 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200929 resource_status, resource_msg = await self.odu.check_resource_status(
930 "create_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000931 )
932 self.logger.info(
933 "resource_status is :{} and resource_msg is :{}".format(
934 resource_status, resource_msg
935 )
936 )
937 if resource_status:
938 content["resourceState"] = "READY"
939 else:
940 content["resourceState"] = "ERROR"
941
942 content["operatingState"] = "IDLE"
943 content = self.update_operation_history(
944 content, workflow_status, resource_status
945 )
946 self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content)
947
948 return
949
garciadeblas96b94f52024-07-08 16:18:21 +0200950 async def delete(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000951 self.logger.info("Infra controller delete Enter")
rshri932105f2024-07-05 15:11:55 +0000952
garciadeblas96b94f52024-07-08 16:18:21 +0200953 workflow_name = await self.odu.launch_workflow(
954 "delete_profile", op_id, op_params, content
955 )
rshri932105f2024-07-05 15:11:55 +0000956 self.logger.info("workflow_name is :{}".format(workflow_name))
957
garciadeblas96b94f52024-07-08 16:18:21 +0200958 workflow_status, workflow_msg = await self.odu.check_workflow_status(
959 workflow_name
960 )
rshri932105f2024-07-05 15:11:55 +0000961 self.logger.info(
962 "workflow_status is :{} and workflow_msg is :{}".format(
963 workflow_status, workflow_msg
964 )
965 )
966 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200967 content["state"] = "DELETED"
968 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +0000969 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200970 content["state"] = "FAILED_DELETION"
971 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000972 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +0200973 content = self.update_operation_history(content, workflow_status, None)
974 self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +0000975
976 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200977 resource_status, resource_msg = await self.odu.check_resource_status(
978 "delete_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000979 )
980 self.logger.info(
981 "resource_status is :{} and resource_msg is :{}".format(
982 resource_status, resource_msg
983 )
984 )
985 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200986 content["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +0000987 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200988 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000989
garciadeblas96b94f52024-07-08 16:18:21 +0200990 content["operatingState"] = "IDLE"
991 content = self.update_operation_history(
992 content, workflow_status, resource_status
993 )
994 self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +0000995
garciadeblas96b94f52024-07-08 16:18:21 +0200996 # To delete it from DB
997 if content["state"] == "DELETED":
rshri932105f2024-07-05 15:11:55 +0000998 self.db.del_one("k8sinfra_controller", {"_id": content["_id"]})
999 return
1000
1001
1002class K8sInfraConfigLcm(LcmBase):
1003 def __init__(self, msg, lcm_tasks, config):
1004 """
1005 Init, Connect to database, filesystem storage, and messaging
1006 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
1007 :return: None
1008 """
1009
garciadeblas40539872024-09-11 14:28:38 +02001010 self.logger = logging.getLogger("lcm.gitops")
rshri932105f2024-07-05 15:11:55 +00001011 self.lcm_tasks = lcm_tasks
1012 self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config)
1013
1014 super().__init__(msg, self.logger)
1015
garciadeblas96b94f52024-07-08 16:18:21 +02001016 async def create(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +00001017 self.logger.info("Infra config Create Enter")
1018
garciadeblas96b94f52024-07-08 16:18:21 +02001019 workflow_name = await self.odu.launch_workflow(
1020 "create_profile", op_id, op_params, content
1021 )
rshri932105f2024-07-05 15:11:55 +00001022 self.logger.info("workflow_name is :{}".format(workflow_name))
1023
garciadeblas96b94f52024-07-08 16:18:21 +02001024 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1025 workflow_name
1026 )
rshri932105f2024-07-05 15:11:55 +00001027 self.logger.info(
1028 "workflow_status is :{} and workflow_msg is :{}".format(
1029 workflow_status, workflow_msg
1030 )
1031 )
1032 if workflow_status:
1033 content["state"] = "CREATED"
1034 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1035 else:
1036 content["state"] = "FAILED_CREATION"
1037 content["resourceState"] = "ERROR"
1038 # has to call update_operation_history return content
1039 content = self.update_operation_history(content, workflow_status, None)
1040 self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content)
1041
1042 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001043 resource_status, resource_msg = await self.odu.check_resource_status(
1044 "create_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +00001045 )
1046 self.logger.info(
1047 "resource_status is :{} and resource_msg is :{}".format(
1048 resource_status, resource_msg
1049 )
1050 )
1051 if resource_status:
1052 content["resourceState"] = "READY"
1053 else:
1054 content["resourceState"] = "ERROR"
1055
1056 content["operatingState"] = "IDLE"
1057 content = self.update_operation_history(
1058 content, workflow_status, resource_status
1059 )
1060 self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content)
1061
1062 return
1063
garciadeblas96b94f52024-07-08 16:18:21 +02001064 async def delete(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +00001065 self.logger.info("Infra config delete Enter")
1066
garciadeblas96b94f52024-07-08 16:18:21 +02001067 workflow_name = await self.odu.launch_workflow(
1068 "delete_profile", op_id, op_params, content
1069 )
rshri932105f2024-07-05 15:11:55 +00001070 self.logger.info("workflow_name is :{}".format(workflow_name))
rshri932105f2024-07-05 15:11:55 +00001071
garciadeblas96b94f52024-07-08 16:18:21 +02001072 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1073 workflow_name
1074 )
rshri932105f2024-07-05 15:11:55 +00001075 self.logger.info(
1076 "workflow_status is :{} and workflow_msg is :{}".format(
1077 workflow_status, workflow_msg
1078 )
1079 )
1080 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001081 content["state"] = "DELETED"
1082 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +00001083 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001084 content["state"] = "FAILED_DELETION"
1085 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +00001086 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +02001087 content = self.update_operation_history(content, workflow_status, None)
1088 self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +00001089
garciadeblas96b94f52024-07-08 16:18:21 +02001090 resource_status, resource_msg = await self.odu.check_resource_status(
1091 "delete_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +00001092 )
1093 self.logger.info(
1094 "resource_status is :{} and resource_msg is :{}".format(
1095 resource_status, resource_msg
1096 )
1097 )
1098 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001099 content["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +00001100 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001101 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +00001102
garciadeblas96b94f52024-07-08 16:18:21 +02001103 content["operatingState"] = "IDLE"
1104 content = self.update_operation_history(
1105 content, workflow_status, resource_status
1106 )
1107 self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +00001108
garciadeblas96b94f52024-07-08 16:18:21 +02001109 # To delete it from DB
1110 if content["state"] == "DELETED":
rshri932105f2024-07-05 15:11:55 +00001111 self.db.del_one("k8sinfra_config", {"_id": content["_id"]})
1112 return
yshah771dea82024-07-05 15:11:49 +00001113
1114
1115class OkaLcm(LcmBase):
1116 db_collection = "okas"
1117
1118 def __init__(self, msg, lcm_tasks, config):
1119 """
1120 Init, Connect to database, filesystem storage, and messaging
1121 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
1122 :return: None
1123 """
1124
garciadeblas40539872024-09-11 14:28:38 +02001125 self.logger = logging.getLogger("lcm.gitops")
yshah771dea82024-07-05 15:11:49 +00001126 self.lcm_tasks = lcm_tasks
1127 self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config)
1128
1129 super().__init__(msg, self.logger)
1130
garciadeblas96b94f52024-07-08 16:18:21 +02001131 async def create(self, op_id, op_params, content):
1132 self.logger.info("OKA Create Enter")
1133 db_content = content
yshah771dea82024-07-05 15:11:49 +00001134
garciadeblas96b94f52024-07-08 16:18:21 +02001135 workflow_name = await self.odu.launch_workflow(
1136 "create_oka", op_id, op_params, db_content
1137 )
1138 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1139 workflow_name
1140 )
1141 self.logger.info(
1142 "Workflow Status: {} Workflow Message: {}".format(
1143 workflow_status, workflow_msg
1144 )
1145 )
yshah771dea82024-07-05 15:11:49 +00001146
1147 if workflow_status:
1148 db_content["state"] = "CREATED"
1149 db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1150 else:
1151 db_content["state"] = "FAILED_CREATION"
1152 db_content["resourceState"] = "ERROR"
1153
1154 db_content = self.update_operation_history(db_content, workflow_status, None)
garciadeblas96b94f52024-07-08 16:18:21 +02001155 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001156
1157 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001158 resource_status, resource_msg = await self.odu.check_resource_status(
1159 "create_oka", op_id, op_params, db_content
yshah771dea82024-07-05 15:11:49 +00001160 )
garciadeblas96b94f52024-07-08 16:18:21 +02001161 self.logger.info(
1162 "Resource Status: {} Resource Message: {}".format(
1163 resource_status, resource_msg
1164 )
1165 )
yshah771dea82024-07-05 15:11:49 +00001166
1167 if resource_status:
1168 db_content["resourceState"] = "READY"
1169 else:
1170 db_content["resourceState"] = "ERROR"
1171
1172 # self.logger.info("Db content: {}".format(db_content))
1173 db_content = self.update_operation_history(
1174 db_content, workflow_status, resource_status
1175 )
1176
1177 db_content["operatingState"] = "IDLE"
garciadeblas96b94f52024-07-08 16:18:21 +02001178 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001179
1180 return
1181
garciadeblas96b94f52024-07-08 16:18:21 +02001182 async def edit(self, op_id, op_params, content):
1183 self.logger.info("OKA Edit Enter")
1184 db_content = content
yshah771dea82024-07-05 15:11:49 +00001185
garciadeblas96b94f52024-07-08 16:18:21 +02001186 workflow_name = await self.odu.launch_workflow(
1187 "update_oka", op_id, op_params, content
1188 )
1189 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1190 workflow_name
1191 )
1192 self.logger.info(
1193 "Workflow Status: {} Workflow Message: {}".format(
1194 workflow_status, workflow_msg
1195 )
1196 )
yshah771dea82024-07-05 15:11:49 +00001197
1198 if workflow_status:
1199 db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1200 else:
1201 db_content["resourceState"] = "ERROR"
1202
1203 db_content = self.update_operation_history(db_content, workflow_status, None)
1204 # self.logger.info("Db content: {}".format(db_content))
garciadeblas96b94f52024-07-08 16:18:21 +02001205 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001206
1207 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001208 resource_status, resource_msg = await self.odu.check_resource_status(
1209 "update_oka", op_id, op_params, db_content
yshah771dea82024-07-05 15:11:49 +00001210 )
garciadeblas96b94f52024-07-08 16:18:21 +02001211 self.logger.info(
1212 "Resource Status: {} Resource Message: {}".format(
1213 resource_status, resource_msg
1214 )
1215 )
yshah771dea82024-07-05 15:11:49 +00001216
1217 if resource_status:
1218 db_content["resourceState"] = "READY"
1219 else:
1220 db_content["resourceState"] = "ERROR"
1221
1222 db_content = self.update_operation_history(
1223 db_content, workflow_status, resource_status
1224 )
1225
1226 db_content["operatingState"] = "IDLE"
garciadeblas96b94f52024-07-08 16:18:21 +02001227 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001228 return
1229
garciadeblas96b94f52024-07-08 16:18:21 +02001230 async def delete(self, op_id, op_params, content):
1231 self.logger.info("OKA delete Enter")
1232 db_content = content
yshah771dea82024-07-05 15:11:49 +00001233
garciadeblas96b94f52024-07-08 16:18:21 +02001234 workflow_name = await self.odu.launch_workflow(
1235 "delete_oka", op_id, op_params, content
1236 )
1237 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1238 workflow_name
1239 )
1240 self.logger.info(
1241 "Workflow Status: {} Workflow Message: {}".format(
1242 workflow_status, workflow_msg
1243 )
1244 )
yshah771dea82024-07-05 15:11:49 +00001245
1246 if workflow_status:
1247 db_content["state"] = "DELETED"
1248 db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1249 else:
1250 db_content["state"] = "FAILED_DELETION"
1251 db_content["resourceState"] = "ERROR"
1252
1253 db_content = self.update_operation_history(db_content, workflow_status, None)
garciadeblas96b94f52024-07-08 16:18:21 +02001254 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001255
1256 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001257 resource_status, resource_msg = await self.odu.check_resource_status(
1258 "delete_oka", op_id, op_params, db_content
yshah771dea82024-07-05 15:11:49 +00001259 )
garciadeblas96b94f52024-07-08 16:18:21 +02001260 self.logger.info(
1261 "Resource Status: {} Resource Message: {}".format(
1262 resource_status, resource_msg
1263 )
1264 )
yshah771dea82024-07-05 15:11:49 +00001265
1266 if resource_status:
1267 db_content["resourceState"] = "READY"
1268 else:
1269 db_content["resourceState"] = "ERROR"
1270
1271 db_content = self.update_operation_history(
1272 db_content, workflow_status, resource_status
1273 )
1274
1275 db_content["operatingState"] = "IDLE"
garciadeblas96b94f52024-07-08 16:18:21 +02001276 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001277
1278 if db_content["state"] == "DELETED":
garciadeblas96b94f52024-07-08 16:18:21 +02001279 self.db.del_one(self.db_collection, {"_id": db_content["_id"]})
yshah771dea82024-07-05 15:11:49 +00001280 return
1281
1282
1283class KsuLcm(LcmBase):
1284 db_collection = "ksus"
1285
1286 def __init__(self, msg, lcm_tasks, config):
1287 """
1288 Init, Connect to database, filesystem storage, and messaging
1289 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
1290 :return: None
1291 """
1292
garciadeblas40539872024-09-11 14:28:38 +02001293 self.logger = logging.getLogger("lcm.gitops")
yshah771dea82024-07-05 15:11:49 +00001294 self.lcm_tasks = lcm_tasks
1295 self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config)
1296
1297 super().__init__(msg, self.logger)
1298
garciadeblas96b94f52024-07-08 16:18:21 +02001299 async def create(self, op_id, op_params, content):
1300 self.logger.info("ksu Create Enter")
yshah771dea82024-07-05 15:11:49 +00001301
garciadeblas96b94f52024-07-08 16:18:21 +02001302 workflow_name = await self.odu.launch_workflow(
1303 "create_ksus", op_id, op_params, content
1304 )
1305 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1306 workflow_name
1307 )
1308 self.logger.info(
1309 "Workflow Status: {} Workflow Message: {}".format(
1310 workflow_status, workflow_msg
yshah771dea82024-07-05 15:11:49 +00001311 )
garciadeblas96b94f52024-07-08 16:18:21 +02001312 )
yshah771dea82024-07-05 15:11:49 +00001313
garciadeblas96b94f52024-07-08 16:18:21 +02001314 for db_ksu in content:
1315 if workflow_status:
1316 db_ksu["state"] = "CREATED"
1317 db_ksu["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
yshah771dea82024-07-05 15:11:49 +00001318 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001319 db_ksu["state"] = "FAILED_CREATION"
1320 db_ksu["resourceState"] = "ERROR"
yshah771dea82024-07-05 15:11:49 +00001321
garciadeblas96b94f52024-07-08 16:18:21 +02001322 db_ksu = self.update_operation_history(db_ksu, workflow_status, None)
1323 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
1324
garciadeblasd8429852024-10-17 15:30:30 +02001325 # Clean items used in the workflow, no matter if the workflow succeeded
1326 clean_status, clean_msg = await self.odu.clean_items_workflow(
1327 "create_ksus", op_id, op_params, content
1328 )
1329 self.logger.info(
1330 f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
1331 )
1332
garciadeblas96b94f52024-07-08 16:18:21 +02001333 if workflow_status:
1334 resource_status, resource_msg = await self.odu.check_resource_status(
1335 "create_ksus", op_id, op_params, content
1336 )
1337 self.logger.info(
1338 "Resource Status: {} Resource Message: {}".format(
1339 resource_status, resource_msg
1340 )
yshah771dea82024-07-05 15:11:49 +00001341 )
1342
garciadeblas96b94f52024-07-08 16:18:21 +02001343 for db_ksu in content:
1344 if resource_status:
1345 db_ksu["resourceState"] = "READY"
1346 else:
1347 db_ksu["resourceState"] = "ERROR"
1348
1349 db_ksu = self.update_operation_history(
1350 db_ksu, workflow_status, resource_status
1351 )
1352
1353 for db_ksu in content:
1354 db_ksu["operatingState"] = "IDLE"
1355 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
yshah771dea82024-07-05 15:11:49 +00001356
1357 return
1358
garciadeblas96b94f52024-07-08 16:18:21 +02001359 async def edit(self, op_id, op_params, content):
1360 self.logger.info("ksu edit Enter")
yshah771dea82024-07-05 15:11:49 +00001361
garciadeblas96b94f52024-07-08 16:18:21 +02001362 workflow_name = await self.odu.launch_workflow(
1363 "update_ksus", op_id, op_params, content
1364 )
1365 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1366 workflow_name
1367 )
1368 self.logger.info(
1369 "Workflow Status: {} Workflow Message: {}".format(
1370 workflow_status, workflow_msg
yshah771dea82024-07-05 15:11:49 +00001371 )
garciadeblas96b94f52024-07-08 16:18:21 +02001372 )
yshah771dea82024-07-05 15:11:49 +00001373
garciadeblas96b94f52024-07-08 16:18:21 +02001374 for db_ksu in content:
1375 if workflow_status:
1376 db_ksu["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
yshah771dea82024-07-05 15:11:49 +00001377 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001378 db_ksu["resourceState"] = "ERROR"
yshah771dea82024-07-05 15:11:49 +00001379
garciadeblas96b94f52024-07-08 16:18:21 +02001380 db_ksu = self.update_operation_history(db_ksu, workflow_status, None)
1381 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
1382
garciadeblasd8429852024-10-17 15:30:30 +02001383 # Clean items used in the workflow, no matter if the workflow succeeded
1384 clean_status, clean_msg = await self.odu.clean_items_workflow(
1385 "create_ksus", op_id, op_params, content
1386 )
1387 self.logger.info(
1388 f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
1389 )
garciadeblas96b94f52024-07-08 16:18:21 +02001390 if workflow_status:
1391 resource_status, resource_msg = await self.odu.check_resource_status(
1392 "update_ksus", op_id, op_params, content
1393 )
1394 self.logger.info(
1395 "Resource Status: {} Resource Message: {}".format(
1396 resource_status, resource_msg
1397 )
yshah771dea82024-07-05 15:11:49 +00001398 )
1399
garciadeblas96b94f52024-07-08 16:18:21 +02001400 for db_ksu in content:
1401 if resource_status:
1402 db_ksu["resourceState"] = "READY"
1403 else:
1404 db_ksu["resourceState"] = "ERROR"
1405
1406 db_ksu = self.update_operation_history(
1407 db_ksu, workflow_status, resource_status
1408 )
1409
1410 for db_ksu, ksu_params in zip(content, op_params):
1411 db_ksu["operatingState"] = "IDLE"
1412 if workflow_status:
1413 db_ksu["name"] = ksu_params["name"]
1414 db_ksu["description"] = ksu_params["description"]
1415 db_ksu["profile"]["profile_type"] = ksu_params["profile"][
1416 "profile_type"
1417 ]
1418 db_ksu["profile"]["_id"] = ksu_params["profile"]["_id"]
1419 db_ksu["oka"] = ksu_params["oka"]
1420 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
1421
yshah771dea82024-07-05 15:11:49 +00001422 return
1423
garciadeblas96b94f52024-07-08 16:18:21 +02001424 async def delete(self, op_id, op_params, content):
1425 self.logger.info("ksu delete Enter")
yshah771dea82024-07-05 15:11:49 +00001426
garciadeblas96b94f52024-07-08 16:18:21 +02001427 workflow_name = await self.odu.launch_workflow(
1428 "delete_ksus", op_id, op_params, content
1429 )
1430 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1431 workflow_name
1432 )
1433 self.logger.info(
1434 "Workflow Status: {} Workflow Message: {}".format(
1435 workflow_status, workflow_msg
yshah771dea82024-07-05 15:11:49 +00001436 )
garciadeblas96b94f52024-07-08 16:18:21 +02001437 )
yshah771dea82024-07-05 15:11:49 +00001438
garciadeblas96b94f52024-07-08 16:18:21 +02001439 for db_ksu in content:
1440 if workflow_status:
1441 db_ksu["state"] = "DELETED"
1442 db_ksu["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
yshah771dea82024-07-05 15:11:49 +00001443 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001444 db_ksu["state"] = "FAILED_DELETION"
1445 db_ksu["resourceState"] = "ERROR"
yshah771dea82024-07-05 15:11:49 +00001446
garciadeblas96b94f52024-07-08 16:18:21 +02001447 db_ksu = self.update_operation_history(db_ksu, workflow_status, None)
1448 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
1449
1450 if workflow_status:
1451 resource_status, resource_msg = await self.odu.check_resource_status(
1452 "delete_ksus", op_id, op_params, content
1453 )
1454 self.logger.info(
1455 "Resource Status: {} Resource Message: {}".format(
1456 resource_status, resource_msg
1457 )
yshah771dea82024-07-05 15:11:49 +00001458 )
1459
garciadeblas96b94f52024-07-08 16:18:21 +02001460 for db_ksu in content:
1461 if resource_status:
1462 db_ksu["resourceState"] = "READY"
1463 else:
1464 db_ksu["resourceState"] = "ERROR"
yshah771dea82024-07-05 15:11:49 +00001465
garciadeblas96b94f52024-07-08 16:18:21 +02001466 db_ksu = self.update_operation_history(
1467 db_ksu, workflow_status, resource_status
1468 )
1469
1470 for db_ksu in content:
1471 db_ksu["operatingState"] = "IDLE"
1472 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
1473
1474 if db_ksu["state"] == "DELETED":
1475 self.db.del_one(self.db_collection, {"_id": db_ksu["_id"]})
yshah771dea82024-07-05 15:11:49 +00001476 return
1477
garciadeblas96b94f52024-07-08 16:18:21 +02001478 async def clone(self, op_id, op_params, db_content):
1479 self.logger.info("ksu clone Enter")
yshah771dea82024-07-05 15:11:49 +00001480
garciadeblas96b94f52024-07-08 16:18:21 +02001481 workflow_name = await self.odu.launch_workflow(
1482 "clone_ksus", op_id, op_params, db_content
1483 )
1484 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1485 workflow_name
1486 )
1487 self.logger.info(
1488 "Workflow Status: {} Workflow Message: {}".format(
1489 workflow_status, workflow_msg
1490 )
1491 )
yshah771dea82024-07-05 15:11:49 +00001492
1493 if workflow_status:
1494 db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1495 else:
1496 db_content["resourceState"] = "ERROR"
1497
1498 db_content = self.update_operation_history(db_content, workflow_status, None)
garciadeblas96b94f52024-07-08 16:18:21 +02001499 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001500
1501 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001502 resource_status, resource_msg = await self.odu.check_resource_status(
1503 "clone_ksus", op_id, op_params, db_content
yshah771dea82024-07-05 15:11:49 +00001504 )
garciadeblas96b94f52024-07-08 16:18:21 +02001505 self.logger.info(
1506 "Resource Status: {} Resource Message: {}".format(
1507 resource_status, resource_msg
1508 )
1509 )
yshah771dea82024-07-05 15:11:49 +00001510
1511 if resource_status:
1512 db_content["resourceState"] = "READY"
1513 else:
1514 db_content["resourceState"] = "ERROR"
1515
1516 db_content = self.update_operation_history(
1517 db_content, workflow_status, resource_status
1518 )
1519
1520 db_content["operatingState"] = "IDLE"
garciadeblas96b94f52024-07-08 16:18:21 +02001521 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001522 return
1523
garciadeblas96b94f52024-07-08 16:18:21 +02001524 async def move(self, op_id, op_params, db_content):
1525 self.logger.info("ksu move Enter")
yshah771dea82024-07-05 15:11:49 +00001526
garciadeblas96b94f52024-07-08 16:18:21 +02001527 workflow_name = await self.odu.launch_workflow(
1528 "move_ksus", op_id, op_params, db_content
1529 )
1530 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1531 workflow_name
1532 )
1533 self.logger.info(
1534 "Workflow Status: {} Workflow Message: {}".format(
1535 workflow_status, workflow_msg
1536 )
1537 )
yshah771dea82024-07-05 15:11:49 +00001538
1539 if workflow_status:
1540 db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1541 else:
1542 db_content["resourceState"] = "ERROR"
1543
1544 db_content = self.update_operation_history(db_content, workflow_status, None)
garciadeblas96b94f52024-07-08 16:18:21 +02001545 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001546
1547 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001548 resource_status, resource_msg = await self.odu.check_resource_status(
1549 "move_ksus", op_id, op_params, db_content
yshah771dea82024-07-05 15:11:49 +00001550 )
garciadeblas96b94f52024-07-08 16:18:21 +02001551 self.logger.info(
1552 "Resource Status: {} Resource Message: {}".format(
1553 resource_status, resource_msg
1554 )
1555 )
yshah771dea82024-07-05 15:11:49 +00001556 if resource_status:
1557 db_content["resourceState"] = "READY"
1558 else:
1559 db_content["resourceState"] = "ERROR"
1560
1561 db_content = self.update_operation_history(
1562 db_content, workflow_status, resource_status
1563 )
1564
1565 db_content["operatingState"] = "IDLE"
garciadeblas96b94f52024-07-08 16:18:21 +02001566 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001567 return