blob: ab6652ab5adf03863f140aadd381c1a169e640e7 [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
garciadeblas4623e982024-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
garciadeblas4d26e292024-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):
rshri932105f2024-07-05 15:11:55 +0000204 self.logger.info("the profile_type is :{}".format(profile_type))
garciadeblas96b94f52024-07-08 16:18:21 +0200205 profile_ids = db_cluster[profile_type]
rshri932105f2024-07-05 15:11:55 +0000206 self.logger.info("the profile_ids is :{}".format(profile_ids))
207 profile_ids_copy = deepcopy(profile_ids)
208 self.logger.info("the profile_ids_copy is :{}".format(profile_ids_copy))
209 for profile_id in profile_ids_copy:
210 self.logger.info("the profile_id is :{}".format(profile_id))
211 db_collection = profiles_collection[profile_type]
212 self.logger.info("the db_collection is :{}".format(db_collection))
213 db_profile = self.db.get_one(db_collection, {"_id": profile_id})
214 self.logger.info("the db_profile is :{}".format(db_profile))
215 self.logger.info(
garciadeblas96b94f52024-07-08 16:18:21 +0200216 "the item_content name is :{}".format(db_cluster["name"])
rshri932105f2024-07-05 15:11:55 +0000217 )
218 self.logger.info(
219 "the db_profile name is :{}".format(db_profile["name"])
220 )
garciadeblas96b94f52024-07-08 16:18:21 +0200221 if db_cluster["name"] == db_profile["name"]:
rshri932105f2024-07-05 15:11:55 +0000222 self.logger.info("it is getting into if default")
223 self.db.del_one(db_collection, {"_id": profile_id})
224 else:
225 self.logger.info("it is getting into else non default")
226 profile_ids.remove(profile_id)
227 update_dict = {profile_type: profile_ids}
228 self.logger.info(f"the update dict is :{update_dict}")
229 self.db.set_one(
garciadeblas96b94f52024-07-08 16:18:21 +0200230 "clusters", {"_id": db_cluster["_id"]}, update_dict
rshri932105f2024-07-05 15:11:55 +0000231 )
garciadeblas96b94f52024-07-08 16:18:21 +0200232 self.db.del_one("clusters", {"_id": db_cluster["_id"]})
233 self.logger.info("the id is :{}".format(db_cluster["_id"]))
rshri932105f2024-07-05 15:11:55 +0000234
garciadeblas96b94f52024-07-08 16:18:21 +0200235 async def attach_profile(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000236 self.logger.info("profile attach Enter")
garciadeblas96b94f52024-07-08 16:18:21 +0200237 db_cluster = content["cluster"]
238 db_profile = content["profile"]
239 profile_type = db_profile["profile_type"]
240 profile_id = db_profile["_id"]
rshri932105f2024-07-05 15:11:55 +0000241 self.logger.info("profile type is : {}".format(profile_type))
rshri932105f2024-07-05 15:11:55 +0000242 self.logger.info("profile id is : {}".format(profile_id))
243
garciadeblas96b94f52024-07-08 16:18:21 +0200244 workflow_name = await self.odu.launch_workflow(
245 "attach_profile_to_cluster", op_id, op_params, content
246 )
rshri932105f2024-07-05 15:11:55 +0000247 self.logger.info("workflow_name is :{}".format(workflow_name))
248
garciadeblas96b94f52024-07-08 16:18:21 +0200249 workflow_status, workflow_msg = await self.odu.check_workflow_status(
250 workflow_name
251 )
rshri932105f2024-07-05 15:11:55 +0000252 self.logger.info(
253 "workflow_status is :{} and workflow_msg is :{}".format(
254 workflow_status, workflow_msg
255 )
256 )
257 if workflow_status:
258 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
259 else:
260 db_cluster["resourceState"] = "ERROR"
261 # has to call update_operation_history return content
262 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
263 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
264
265 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200266 resource_status, resource_msg = await self.odu.check_resource_status(
267 "attach_profile_to_cluster", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000268 )
269 self.logger.info(
270 "resource_status is :{} and resource_msg is :{}".format(
271 resource_status, resource_msg
272 )
273 )
274 if resource_status:
275 db_cluster["resourceState"] = "READY"
276 else:
277 db_cluster["resourceState"] = "ERROR"
278
279 db_cluster["operatingState"] = "IDLE"
280 db_cluster = self.update_operation_history(
281 db_cluster, workflow_status, resource_status
282 )
rshri932105f2024-07-05 15:11:55 +0000283 profile_list = db_cluster[profile_type]
284 self.logger.info("profile list is : {}".format(profile_list))
285 if resource_status:
286 self.logger.info("it is getting into resource status true")
287 profile_list.append(profile_id)
288 self.logger.info("profile list is : {}".format(profile_list))
289 db_cluster[profile_type] = profile_list
290 self.logger.info("db cluster is : {}".format(db_cluster))
291 # update_dict = {item: profile_list}
292 # self.logger.info("the update_dict is :{}".format(update_dict))
293 # self.db.set_one(self.topic, filter_q, update_dict)
294 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
295
296 return
297
garciadeblas96b94f52024-07-08 16:18:21 +0200298 async def detach_profile(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000299 self.logger.info("profile dettach Enter")
garciadeblas96b94f52024-07-08 16:18:21 +0200300 db_cluster = content["cluster"]
301 db_profile = content["profile"]
302 profile_type = db_profile["profile_type"]
303 profile_id = db_profile["_id"]
rshri932105f2024-07-05 15:11:55 +0000304 self.logger.info("profile type is : {}".format(profile_type))
rshri932105f2024-07-05 15:11:55 +0000305 self.logger.info("profile id is : {}".format(profile_id))
306
garciadeblas96b94f52024-07-08 16:18:21 +0200307 workflow_name = await self.odu.launch_workflow(
308 "detach_profile_from_cluster", op_id, op_params, content
309 )
rshri932105f2024-07-05 15:11:55 +0000310 self.logger.info("workflow_name is :{}".format(workflow_name))
311
garciadeblas96b94f52024-07-08 16:18:21 +0200312 workflow_status, workflow_msg = await self.odu.check_workflow_status(
313 workflow_name
314 )
rshri932105f2024-07-05 15:11:55 +0000315 self.logger.info(
316 "workflow_status is :{} and workflow_msg is :{}".format(
317 workflow_status, workflow_msg
318 )
319 )
320 if workflow_status:
321 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
322 else:
323 db_cluster["resourceState"] = "ERROR"
324 # has to call update_operation_history return content
325 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
326 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
327
328 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200329 resource_status, resource_msg = await self.odu.check_resource_status(
330 "detach_profile_from_cluster", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000331 )
332 self.logger.info(
333 "resource_status is :{} and resource_msg is :{}".format(
334 resource_status, resource_msg
335 )
336 )
337 if resource_status:
338 db_cluster["resourceState"] = "READY"
339 else:
340 db_cluster["resourceState"] = "ERROR"
341
342 db_cluster["operatingState"] = "IDLE"
343 db_cluster = self.update_operation_history(
344 db_cluster, workflow_status, resource_status
345 )
rshri932105f2024-07-05 15:11:55 +0000346 profile_list = db_cluster[profile_type]
347 self.logger.info("profile list is : {}".format(profile_list))
348 if resource_status:
349 self.logger.info("it is getting into resource status true")
350 profile_list.remove(profile_id)
351 self.logger.info("profile list is : {}".format(profile_list))
352 db_cluster[profile_type] = profile_list
353 self.logger.info("db cluster is : {}".format(db_cluster))
354 # update_dict = {item: profile_list}
355 # self.logger.info("the update_dict is :{}".format(update_dict))
356 # self.db.set_one(self.topic, filter_q, update_dict)
357 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
358
359 return
360
garciadeblas96b94f52024-07-08 16:18:21 +0200361 async def register(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000362 self.logger.info("cluster register enter")
garciadeblas96b94f52024-07-08 16:18:21 +0200363 db_cluster = content["cluster"]
rshri932105f2024-07-05 15:11:55 +0000364
garciadeblas96b94f52024-07-08 16:18:21 +0200365 workflow_name = await self.odu.launch_workflow(
366 "register_cluster", op_id, op_params, content
367 )
rshri932105f2024-07-05 15:11:55 +0000368 self.logger.info("workflow_name is :{}".format(workflow_name))
369
garciadeblas96b94f52024-07-08 16:18:21 +0200370 workflow_status, workflow_msg = await self.odu.check_workflow_status(
371 workflow_name
372 )
rshri932105f2024-07-05 15:11:55 +0000373 self.logger.info(
374 "workflow_status is :{} and workflow_msg is :{}".format(
375 workflow_status, workflow_msg
376 )
377 )
378 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200379 db_cluster["state"] = "CREATED"
380 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +0000381 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200382 db_cluster["state"] = "FAILED_CREATION"
383 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000384 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +0200385 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
386 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
rshri932105f2024-07-05 15:11:55 +0000387
garciadeblasf1458032024-09-17 13:25:06 +0200388 # Clean items used in the workflow, no matter if the workflow succeeded
389 clean_status, clean_msg = await self.odu.clean_items_workflow(
390 "register_cluster", op_id, op_params, content
391 )
392 self.logger.info(
393 f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
394 )
395
rshri932105f2024-07-05 15:11:55 +0000396 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200397 resource_status, resource_msg = await self.odu.check_resource_status(
398 "register_cluster", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000399 )
400 self.logger.info(
401 "resource_status is :{} and resource_msg is :{}".format(
402 resource_status, resource_msg
403 )
404 )
405 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200406 db_cluster["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +0000407 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200408 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000409
garciadeblas96b94f52024-07-08 16:18:21 +0200410 db_cluster["operatingState"] = "IDLE"
411 db_cluster = self.update_operation_history(
412 db_cluster, workflow_status, resource_status
rshri932105f2024-07-05 15:11:55 +0000413 )
garciadeblas96b94f52024-07-08 16:18:21 +0200414 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
415 self.update_profile_state(db_cluster, workflow_status, resource_status)
rshri932105f2024-07-05 15:11:55 +0000416 return
417
garciadeblas96b94f52024-07-08 16:18:21 +0200418 async def deregister(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000419 self.logger.info("cluster deregister enter")
garciadeblas96b94f52024-07-08 16:18:21 +0200420 db_cluster = content["cluster"]
rshri932105f2024-07-05 15:11:55 +0000421
garciadeblas96b94f52024-07-08 16:18:21 +0200422 self.logger.info("db_cluster is : {}".format(db_cluster))
rshri932105f2024-07-05 15:11:55 +0000423
garciadeblas96b94f52024-07-08 16:18:21 +0200424 workflow_name = await self.odu.launch_workflow(
425 "deregister_cluster", op_id, op_params, content
426 )
rshri932105f2024-07-05 15:11:55 +0000427 self.logger.info("workflow_name is :{}".format(workflow_name))
428
garciadeblas96b94f52024-07-08 16:18:21 +0200429 workflow_status, workflow_msg = await self.odu.check_workflow_status(
430 workflow_name
431 )
rshri932105f2024-07-05 15:11:55 +0000432 self.logger.info(
433 "workflow_status is :{} and workflow_msg is :{}".format(
434 workflow_status, workflow_msg
435 )
436 )
437 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200438 db_cluster["state"] = "DELETED"
439 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +0000440 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200441 db_cluster["state"] = "FAILED_DELETION"
442 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000443 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +0200444 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
445 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
rshri932105f2024-07-05 15:11:55 +0000446
447 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200448 resource_status, resource_msg = await self.odu.check_resource_status(
449 "deregister_cluster", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000450 )
451 self.logger.info(
452 "resource_status is :{} and resource_msg is :{}".format(
453 resource_status, resource_msg
454 )
455 )
456 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200457 db_cluster["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +0000458 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200459 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000460
garciadeblas96b94f52024-07-08 16:18:21 +0200461 db_cluster["operatingState"] = "IDLE"
462 db_cluster = self.update_operation_history(
463 db_cluster, workflow_status, resource_status
464 )
465 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
rshri932105f2024-07-05 15:11:55 +0000466
garciadeblas96b94f52024-07-08 16:18:21 +0200467 # To delete it from DB
468 if db_cluster["state"] == "DELETED":
469 self.db.del_one("clusters", {"_id": db_cluster["_id"]})
rshri932105f2024-07-05 15:11:55 +0000470 return
471
garciadeblas96b94f52024-07-08 16:18:21 +0200472 async def get_creds(self, db_cluster):
473 self.logger.info("Cluster get creds Enter")
474 result, cluster_creds = await self.odu.get_cluster_credentials(db_cluster)
475 if result:
476 db_cluster["credentials"] = cluster_creds
477 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
yshah771dea82024-07-05 15:11:49 +0000478 return
479
garciadeblas96b94f52024-07-08 16:18:21 +0200480 async def update(self, op_id, op_params, content):
481 self.logger.info("Cluster update Enter")
482 db_cluster = content["cluster"]
yshah771dea82024-07-05 15:11:49 +0000483
garciadeblas96b94f52024-07-08 16:18:21 +0200484 workflow_name = await self.odu.launch_workflow(
485 "update_cluster", op_id, op_params, content
486 )
487 workflow_status, workflow_msg = await self.odu.check_workflow_status(
488 workflow_name
489 )
490 self.logger.info(
491 "Workflow Status: {} Workflow Message: {}".format(
492 workflow_status, workflow_msg
yshah771dea82024-07-05 15:11:49 +0000493 )
garciadeblas96b94f52024-07-08 16:18:21 +0200494 )
495
496 if workflow_status:
497 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
498 else:
499 db_cluster["resourceState"] = "ERROR"
500
501 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
502 # self.logger.info("Db content: {}".format(db_content))
503 # self.db.set_one(self.db_collection, {"_id": _id}, db_cluster)
504 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
505
garciadeblas4d26e292024-09-16 12:53:07 +0200506 # Clean items used in the workflow, no matter if the workflow succeeded
507 clean_status, clean_msg = await self.odu.clean_items_workflow(
508 "update_cluster", op_id, op_params, content
509 )
510 self.logger.info(
511 f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
512 )
garciadeblas96b94f52024-07-08 16:18:21 +0200513 if workflow_status:
514 resource_status, resource_msg = await self.odu.check_resource_status(
515 "update_cluster", op_id, op_params, content
516 )
517 self.logger.info(
518 "Resource Status: {} Resource Message: {}".format(
519 resource_status, resource_msg
520 )
521 )
yshah771dea82024-07-05 15:11:49 +0000522
523 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200524 db_cluster["resourceState"] = "READY"
yshah771dea82024-07-05 15:11:49 +0000525 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200526 db_cluster["resourceState"] = "ERROR"
yshah771dea82024-07-05 15:11:49 +0000527
garciadeblas96b94f52024-07-08 16:18:21 +0200528 db_cluster["operatingState"] = "IDLE"
529 db_cluster = self.update_operation_history(
530 db_cluster, workflow_status, resource_status
531 )
532 # self.logger.info("db_cluster: {}".format(db_cluster))
533 # TODO: verify enxtcondition
534 # For the moment, if the workflow completed successfully, then we update the db accordingly.
535 if workflow_status:
536 if "k8s_version" in op_params:
537 db_cluster["k8s_version"] = op_params["k8s_version"]
538 elif "node_count" in op_params:
539 db_cluster["node_count"] = op_params["node_count"]
540 # self.db.set_one(self.db_collection, {"_id": _id}, db_content)
541 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
yshah771dea82024-07-05 15:11:49 +0000542 return
543
544
545class CloudCredentialsLcm(LcmBase):
546 db_collection = "vim_accounts"
547
548 def __init__(self, msg, lcm_tasks, config):
549 """
550 Init, Connect to database, filesystem storage, and messaging
551 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
552 :return: None
553 """
554
garciadeblas4623e982024-09-11 14:28:38 +0200555 self.logger = logging.getLogger("lcm.gitops")
yshah771dea82024-07-05 15:11:49 +0000556 self.lcm_tasks = lcm_tasks
557 self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config)
558
559 super().__init__(msg, self.logger)
560
garciadeblas96b94f52024-07-08 16:18:21 +0200561 async def add(self, op_id, op_params, content):
yshah771dea82024-07-05 15:11:49 +0000562 self.logger.info("Cloud Credentials create")
563 workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +0200564 "create_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000565 )
566
567 workflow_status, workflow_msg = await self.odu.check_workflow_status(
568 workflow_name
569 )
570
571 self.logger.info(
572 "Workflow Status: {} Workflow Msg: {}".format(workflow_status, workflow_msg)
573 )
574
garciadeblas4d26e292024-09-16 12:53:07 +0200575 # Clean items used in the workflow, no matter if the workflow succeeded
576 clean_status, clean_msg = await self.odu.clean_items_workflow(
577 "create_cloud_credentials", op_id, op_params, content
578 )
579 self.logger.info(
580 f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
581 )
582
yshah771dea82024-07-05 15:11:49 +0000583 if workflow_status:
584 resource_status, resource_msg = await self.odu.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +0200585 "create_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000586 )
587 self.logger.info(
588 "Resource Status: {} Resource Message: {}".format(
589 resource_status, resource_msg
590 )
591 )
garciadeblas8595d572024-09-23 12:40:13 +0200592
593 content["_admin"]["operationalState"] = "ENABLED"
594 for operation in content["_admin"]["operations"]:
595 if operation["lcmOperationType"] == "create":
596 operation["operationState"] = "ENABLED"
597 self.logger.info("Content : {}".format(content))
598 self.db.set_one("vim_accounts", {"_id": content["_id"]}, content)
599
yshah771dea82024-07-05 15:11:49 +0000600 return
601
garciadeblas96b94f52024-07-08 16:18:21 +0200602 async def edit(self, op_id, op_params, content):
yshah771dea82024-07-05 15:11:49 +0000603 workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +0200604 "update_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000605 )
606 workflow_status, workflow_msg = await self.odu.check_workflow_status(
607 workflow_name
608 )
609 self.logger.info(
610 "Workflow Status: {} Workflow Msg: {}".format(workflow_status, workflow_msg)
611 )
612
garciadeblas4d26e292024-09-16 12:53:07 +0200613 # Clean items used in the workflow, no matter if the workflow succeeded
614 clean_status, clean_msg = await self.odu.clean_items_workflow(
615 "update_cloud_credentials", op_id, op_params, content
616 )
617 self.logger.info(
618 f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
619 )
620
yshah771dea82024-07-05 15:11:49 +0000621 if workflow_status:
622 resource_status, resource_msg = await self.odu.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +0200623 "update_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000624 )
625 self.logger.info(
626 "Resource Status: {} Resource Message: {}".format(
627 resource_status, resource_msg
628 )
629 )
630 return
631
garciadeblas96b94f52024-07-08 16:18:21 +0200632 async def remove(self, op_id, op_params, content):
yshah771dea82024-07-05 15:11:49 +0000633 self.logger.info("Cloud Credentials delete")
634 workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +0200635 "delete_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000636 )
637 workflow_status, workflow_msg = await self.odu.check_workflow_status(
638 workflow_name
639 )
640 self.logger.info(
641 "Workflow Status: {} Workflow Msg: {}".format(workflow_status, workflow_msg)
642 )
643
644 if workflow_status:
645 resource_status, resource_msg = await self.odu.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +0200646 "delete_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000647 )
648 self.logger.info(
649 "Resource Status: {} Resource Message: {}".format(
650 resource_status, resource_msg
651 )
652 )
653 self.db.del_one(self.db_collection, {"_id": content["_id"]})
654 return
655
rshri932105f2024-07-05 15:11:55 +0000656
657class K8sAppLcm(LcmBase):
658 def __init__(self, msg, lcm_tasks, config):
659 """
660 Init, Connect to database, filesystem storage, and messaging
661 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
662 :return: None
663 """
664
garciadeblas4623e982024-09-11 14:28:38 +0200665 self.logger = logging.getLogger("lcm.gitops")
rshri932105f2024-07-05 15:11:55 +0000666 self.lcm_tasks = lcm_tasks
667 self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config)
668
669 super().__init__(msg, self.logger)
670
garciadeblas96b94f52024-07-08 16:18:21 +0200671 async def create(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000672 self.logger.info("App Create Enter")
673
garciadeblas96b94f52024-07-08 16:18:21 +0200674 workflow_name = await self.odu.launch_workflow(
675 "create_profile", op_id, op_params, content
676 )
rshri932105f2024-07-05 15:11:55 +0000677 self.logger.info("workflow_name is :{}".format(workflow_name))
678
garciadeblas96b94f52024-07-08 16:18:21 +0200679 workflow_status, workflow_msg = await self.odu.check_workflow_status(
680 workflow_name
681 )
rshri932105f2024-07-05 15:11:55 +0000682 self.logger.info(
683 "workflow_status is :{} and workflow_msg is :{}".format(
684 workflow_status, workflow_msg
685 )
686 )
687 if workflow_status:
688 content["state"] = "CREATED"
689 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
690 else:
691 content["state"] = "FAILED_CREATION"
692 content["resourceState"] = "ERROR"
693 # has to call update_operation_history return content
694 content = self.update_operation_history(content, workflow_status, None)
695 self.db.set_one("k8sapp", {"_id": content["_id"]}, content)
696
697 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200698 resource_status, resource_msg = await self.odu.check_resource_status(
699 "create_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000700 )
701 self.logger.info(
702 "resource_status is :{} and resource_msg is :{}".format(
703 resource_status, resource_msg
704 )
705 )
706 if resource_status:
707 content["resourceState"] = "READY"
708 else:
709 content["resourceState"] = "ERROR"
710
711 content["operatingState"] = "IDLE"
712 content = self.update_operation_history(
713 content, workflow_status, resource_status
714 )
715 self.db.set_one("k8sapp", {"_id": content["_id"]}, content)
716
717 return
718
garciadeblas96b94f52024-07-08 16:18:21 +0200719 async def delete(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000720 self.logger.info("App delete Enter")
rshri932105f2024-07-05 15:11:55 +0000721
garciadeblas96b94f52024-07-08 16:18:21 +0200722 workflow_name = await self.odu.launch_workflow(
723 "delete_profile", op_id, op_params, content
724 )
rshri932105f2024-07-05 15:11:55 +0000725 self.logger.info("workflow_name is :{}".format(workflow_name))
726
garciadeblas96b94f52024-07-08 16:18:21 +0200727 workflow_status, workflow_msg = await self.odu.check_workflow_status(
728 workflow_name
729 )
rshri932105f2024-07-05 15:11:55 +0000730 self.logger.info(
731 "workflow_status is :{} and workflow_msg is :{}".format(
732 workflow_status, workflow_msg
733 )
734 )
735 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200736 content["state"] = "DELETED"
737 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +0000738 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200739 content["state"] = "FAILED_DELETION"
740 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000741 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +0200742 content = self.update_operation_history(content, workflow_status, None)
rshri932105f2024-07-05 15:11:55 +0000743 self.db.set_one("k8sapp", {"_id": content["_id"]}, content)
744
745 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200746 resource_status, resource_msg = await self.odu.check_resource_status(
747 "delete_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000748 )
749 self.logger.info(
750 "resource_status is :{} and resource_msg is :{}".format(
751 resource_status, resource_msg
752 )
753 )
754 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200755 content["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +0000756 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200757 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000758
garciadeblas96b94f52024-07-08 16:18:21 +0200759 content["operatingState"] = "IDLE"
760 content = self.update_operation_history(
761 content, workflow_status, resource_status
762 )
763 self.db.set_one("k8sapp", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +0000764
garciadeblas96b94f52024-07-08 16:18:21 +0200765 # To delete it from DB
766 if content["state"] == "DELETED":
rshri932105f2024-07-05 15:11:55 +0000767 self.db.del_one("k8sapp", {"_id": content["_id"]})
768 return
769
770
771class K8sResourceLcm(LcmBase):
772 def __init__(self, msg, lcm_tasks, config):
773 """
774 Init, Connect to database, filesystem storage, and messaging
775 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
776 :return: None
777 """
778
garciadeblas4623e982024-09-11 14:28:38 +0200779 self.logger = logging.getLogger("lcm.gitops")
rshri932105f2024-07-05 15:11:55 +0000780 self.lcm_tasks = lcm_tasks
781 self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config)
782
783 super().__init__(msg, self.logger)
784
garciadeblas96b94f52024-07-08 16:18:21 +0200785 async def create(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000786 self.logger.info("Resource Create Enter")
787
garciadeblas96b94f52024-07-08 16:18:21 +0200788 workflow_name = await self.odu.launch_workflow(
789 "create_profile", op_id, op_params, content
790 )
rshri932105f2024-07-05 15:11:55 +0000791 self.logger.info("workflow_name is :{}".format(workflow_name))
792
garciadeblas96b94f52024-07-08 16:18:21 +0200793 workflow_status, workflow_msg = await self.odu.check_workflow_status(
794 workflow_name
795 )
rshri932105f2024-07-05 15:11:55 +0000796 self.logger.info(
797 "workflow_status is :{} and workflow_msg is :{}".format(
798 workflow_status, workflow_msg
799 )
800 )
801 if workflow_status:
802 content["state"] = "CREATED"
803 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
804 else:
805 content["state"] = "FAILED_CREATION"
806 content["resourceState"] = "ERROR"
807 # has to call update_operation_history return content
808 content = self.update_operation_history(content, workflow_status, None)
809 self.db.set_one("k8sresource", {"_id": content["_id"]}, content)
810
811 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200812 resource_status, resource_msg = await self.odu.check_resource_status(
813 "create_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000814 )
815 self.logger.info(
816 "resource_status is :{} and resource_msg is :{}".format(
817 resource_status, resource_msg
818 )
819 )
820 if resource_status:
821 content["resourceState"] = "READY"
822 else:
823 content["resourceState"] = "ERROR"
824
825 content["operatingState"] = "IDLE"
826 content = self.update_operation_history(
827 content, workflow_status, resource_status
828 )
829 self.db.set_one("k8sresource", {"_id": content["_id"]}, content)
830
831 return
832
garciadeblas96b94f52024-07-08 16:18:21 +0200833 async def delete(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000834 self.logger.info("Resource delete Enter")
garciadeblas96b94f52024-07-08 16:18:21 +0200835 content = self.db.get_one("k8sresource", {"_id": content["_id"]})
rshri932105f2024-07-05 15:11:55 +0000836
garciadeblas96b94f52024-07-08 16:18:21 +0200837 workflow_name = await self.odu.launch_workflow(
838 "delete_profile", op_id, op_params, content
839 )
rshri932105f2024-07-05 15:11:55 +0000840 self.logger.info("workflow_name is :{}".format(workflow_name))
841
garciadeblas96b94f52024-07-08 16:18:21 +0200842 workflow_status, workflow_msg = await self.odu.check_workflow_status(
843 workflow_name
844 )
rshri932105f2024-07-05 15:11:55 +0000845 self.logger.info(
846 "workflow_status is :{} and workflow_msg is :{}".format(
847 workflow_status, workflow_msg
848 )
849 )
850 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200851 content["state"] = "DELETED"
852 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +0000853 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200854 content["state"] = "FAILED_DELETION"
855 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000856 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +0200857 content = self.update_operation_history(content, workflow_status, None)
858 self.db.set_one("k8sresource", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +0000859
860 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200861 resource_status, resource_msg = await self.odu.check_resource_status(
862 "delete_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000863 )
864 self.logger.info(
865 "resource_status is :{} and resource_msg is :{}".format(
866 resource_status, resource_msg
867 )
868 )
869 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200870 content["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +0000871 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200872 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000873
garciadeblas96b94f52024-07-08 16:18:21 +0200874 content["operatingState"] = "IDLE"
875 content = self.update_operation_history(
876 content, workflow_status, resource_status
877 )
878 self.db.set_one("k8sresource", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +0000879
garciadeblas96b94f52024-07-08 16:18:21 +0200880 # To delete it from DB
881 if content["state"] == "DELETED":
rshri932105f2024-07-05 15:11:55 +0000882 self.db.del_one("k8sresource", {"_id": content["_id"]})
883 return
884
885
886class K8sInfraControllerLcm(LcmBase):
887 def __init__(self, msg, lcm_tasks, config):
888 """
889 Init, Connect to database, filesystem storage, and messaging
890 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
891 :return: None
892 """
893
garciadeblas4623e982024-09-11 14:28:38 +0200894 self.logger = logging.getLogger("lcm.gitops")
rshri932105f2024-07-05 15:11:55 +0000895 self.lcm_tasks = lcm_tasks
896 self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config)
897
898 super().__init__(msg, self.logger)
899
garciadeblas96b94f52024-07-08 16:18:21 +0200900 async def create(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000901 self.logger.info("Infra controller Create Enter")
902
garciadeblas96b94f52024-07-08 16:18:21 +0200903 workflow_name = await self.odu.launch_workflow(
904 "create_profile", op_id, op_params, content
905 )
rshri932105f2024-07-05 15:11:55 +0000906 self.logger.info("workflow_name is :{}".format(workflow_name))
907
garciadeblas96b94f52024-07-08 16:18:21 +0200908 workflow_status, workflow_msg = await self.odu.check_workflow_status(
909 workflow_name
910 )
rshri932105f2024-07-05 15:11:55 +0000911 self.logger.info(
912 "workflow_status is :{} and workflow_msg is :{}".format(
913 workflow_status, workflow_msg
914 )
915 )
916 if workflow_status:
917 content["state"] = "CREATED"
918 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
919 else:
920 content["state"] = "FAILED_CREATION"
921 content["resourceState"] = "ERROR"
922 # has to call update_operation_history return content
923 content = self.update_operation_history(content, workflow_status, None)
924 self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content)
925
926 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200927 resource_status, resource_msg = await self.odu.check_resource_status(
928 "create_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000929 )
930 self.logger.info(
931 "resource_status is :{} and resource_msg is :{}".format(
932 resource_status, resource_msg
933 )
934 )
935 if resource_status:
936 content["resourceState"] = "READY"
937 else:
938 content["resourceState"] = "ERROR"
939
940 content["operatingState"] = "IDLE"
941 content = self.update_operation_history(
942 content, workflow_status, resource_status
943 )
944 self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content)
945
946 return
947
garciadeblas96b94f52024-07-08 16:18:21 +0200948 async def delete(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000949 self.logger.info("Infra controller delete Enter")
rshri932105f2024-07-05 15:11:55 +0000950
garciadeblas96b94f52024-07-08 16:18:21 +0200951 workflow_name = await self.odu.launch_workflow(
952 "delete_profile", op_id, op_params, content
953 )
rshri932105f2024-07-05 15:11:55 +0000954 self.logger.info("workflow_name is :{}".format(workflow_name))
955
garciadeblas96b94f52024-07-08 16:18:21 +0200956 workflow_status, workflow_msg = await self.odu.check_workflow_status(
957 workflow_name
958 )
rshri932105f2024-07-05 15:11:55 +0000959 self.logger.info(
960 "workflow_status is :{} and workflow_msg is :{}".format(
961 workflow_status, workflow_msg
962 )
963 )
964 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200965 content["state"] = "DELETED"
966 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +0000967 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200968 content["state"] = "FAILED_DELETION"
969 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000970 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +0200971 content = self.update_operation_history(content, workflow_status, None)
972 self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +0000973
974 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200975 resource_status, resource_msg = await self.odu.check_resource_status(
976 "delete_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000977 )
978 self.logger.info(
979 "resource_status is :{} and resource_msg is :{}".format(
980 resource_status, resource_msg
981 )
982 )
983 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200984 content["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +0000985 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200986 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000987
garciadeblas96b94f52024-07-08 16:18:21 +0200988 content["operatingState"] = "IDLE"
989 content = self.update_operation_history(
990 content, workflow_status, resource_status
991 )
992 self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +0000993
garciadeblas96b94f52024-07-08 16:18:21 +0200994 # To delete it from DB
995 if content["state"] == "DELETED":
rshri932105f2024-07-05 15:11:55 +0000996 self.db.del_one("k8sinfra_controller", {"_id": content["_id"]})
997 return
998
999
1000class K8sInfraConfigLcm(LcmBase):
1001 def __init__(self, msg, lcm_tasks, config):
1002 """
1003 Init, Connect to database, filesystem storage, and messaging
1004 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
1005 :return: None
1006 """
1007
garciadeblas4623e982024-09-11 14:28:38 +02001008 self.logger = logging.getLogger("lcm.gitops")
rshri932105f2024-07-05 15:11:55 +00001009 self.lcm_tasks = lcm_tasks
1010 self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config)
1011
1012 super().__init__(msg, self.logger)
1013
garciadeblas96b94f52024-07-08 16:18:21 +02001014 async def create(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +00001015 self.logger.info("Infra config Create Enter")
1016
garciadeblas96b94f52024-07-08 16:18:21 +02001017 workflow_name = await self.odu.launch_workflow(
1018 "create_profile", op_id, op_params, content
1019 )
rshri932105f2024-07-05 15:11:55 +00001020 self.logger.info("workflow_name is :{}".format(workflow_name))
1021
garciadeblas96b94f52024-07-08 16:18:21 +02001022 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1023 workflow_name
1024 )
rshri932105f2024-07-05 15:11:55 +00001025 self.logger.info(
1026 "workflow_status is :{} and workflow_msg is :{}".format(
1027 workflow_status, workflow_msg
1028 )
1029 )
1030 if workflow_status:
1031 content["state"] = "CREATED"
1032 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1033 else:
1034 content["state"] = "FAILED_CREATION"
1035 content["resourceState"] = "ERROR"
1036 # has to call update_operation_history return content
1037 content = self.update_operation_history(content, workflow_status, None)
1038 self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content)
1039
1040 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001041 resource_status, resource_msg = await self.odu.check_resource_status(
1042 "create_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +00001043 )
1044 self.logger.info(
1045 "resource_status is :{} and resource_msg is :{}".format(
1046 resource_status, resource_msg
1047 )
1048 )
1049 if resource_status:
1050 content["resourceState"] = "READY"
1051 else:
1052 content["resourceState"] = "ERROR"
1053
1054 content["operatingState"] = "IDLE"
1055 content = self.update_operation_history(
1056 content, workflow_status, resource_status
1057 )
1058 self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content)
1059
1060 return
1061
garciadeblas96b94f52024-07-08 16:18:21 +02001062 async def delete(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +00001063 self.logger.info("Infra config delete Enter")
1064
garciadeblas96b94f52024-07-08 16:18:21 +02001065 workflow_name = await self.odu.launch_workflow(
1066 "delete_profile", op_id, op_params, content
1067 )
rshri932105f2024-07-05 15:11:55 +00001068 self.logger.info("workflow_name is :{}".format(workflow_name))
rshri932105f2024-07-05 15:11:55 +00001069
garciadeblas96b94f52024-07-08 16:18:21 +02001070 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1071 workflow_name
1072 )
rshri932105f2024-07-05 15:11:55 +00001073 self.logger.info(
1074 "workflow_status is :{} and workflow_msg is :{}".format(
1075 workflow_status, workflow_msg
1076 )
1077 )
1078 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001079 content["state"] = "DELETED"
1080 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +00001081 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001082 content["state"] = "FAILED_DELETION"
1083 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +00001084 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +02001085 content = self.update_operation_history(content, workflow_status, None)
1086 self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +00001087
garciadeblas96b94f52024-07-08 16:18:21 +02001088 resource_status, resource_msg = await self.odu.check_resource_status(
1089 "delete_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +00001090 )
1091 self.logger.info(
1092 "resource_status is :{} and resource_msg is :{}".format(
1093 resource_status, resource_msg
1094 )
1095 )
1096 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001097 content["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +00001098 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001099 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +00001100
garciadeblas96b94f52024-07-08 16:18:21 +02001101 content["operatingState"] = "IDLE"
1102 content = self.update_operation_history(
1103 content, workflow_status, resource_status
1104 )
1105 self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +00001106
garciadeblas96b94f52024-07-08 16:18:21 +02001107 # To delete it from DB
1108 if content["state"] == "DELETED":
rshri932105f2024-07-05 15:11:55 +00001109 self.db.del_one("k8sinfra_config", {"_id": content["_id"]})
1110 return
yshah771dea82024-07-05 15:11:49 +00001111
1112
1113class OkaLcm(LcmBase):
1114 db_collection = "okas"
1115
1116 def __init__(self, msg, lcm_tasks, config):
1117 """
1118 Init, Connect to database, filesystem storage, and messaging
1119 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
1120 :return: None
1121 """
1122
garciadeblas4623e982024-09-11 14:28:38 +02001123 self.logger = logging.getLogger("lcm.gitops")
yshah771dea82024-07-05 15:11:49 +00001124 self.lcm_tasks = lcm_tasks
1125 self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config)
1126
1127 super().__init__(msg, self.logger)
1128
garciadeblas96b94f52024-07-08 16:18:21 +02001129 async def create(self, op_id, op_params, content):
1130 self.logger.info("OKA Create Enter")
1131 db_content = content
yshah771dea82024-07-05 15:11:49 +00001132
garciadeblas96b94f52024-07-08 16:18:21 +02001133 workflow_name = await self.odu.launch_workflow(
1134 "create_oka", op_id, op_params, db_content
1135 )
1136 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1137 workflow_name
1138 )
1139 self.logger.info(
1140 "Workflow Status: {} Workflow Message: {}".format(
1141 workflow_status, workflow_msg
1142 )
1143 )
yshah771dea82024-07-05 15:11:49 +00001144
1145 if workflow_status:
1146 db_content["state"] = "CREATED"
1147 db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1148 else:
1149 db_content["state"] = "FAILED_CREATION"
1150 db_content["resourceState"] = "ERROR"
1151
1152 db_content = self.update_operation_history(db_content, workflow_status, None)
garciadeblas96b94f52024-07-08 16:18:21 +02001153 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001154
1155 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001156 resource_status, resource_msg = await self.odu.check_resource_status(
1157 "create_oka", op_id, op_params, db_content
yshah771dea82024-07-05 15:11:49 +00001158 )
garciadeblas96b94f52024-07-08 16:18:21 +02001159 self.logger.info(
1160 "Resource Status: {} Resource Message: {}".format(
1161 resource_status, resource_msg
1162 )
1163 )
yshah771dea82024-07-05 15:11:49 +00001164
1165 if resource_status:
1166 db_content["resourceState"] = "READY"
1167 else:
1168 db_content["resourceState"] = "ERROR"
1169
1170 # self.logger.info("Db content: {}".format(db_content))
1171 db_content = self.update_operation_history(
1172 db_content, workflow_status, resource_status
1173 )
1174
1175 db_content["operatingState"] = "IDLE"
garciadeblas96b94f52024-07-08 16:18:21 +02001176 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001177
1178 return
1179
garciadeblas96b94f52024-07-08 16:18:21 +02001180 async def edit(self, op_id, op_params, content):
1181 self.logger.info("OKA Edit Enter")
1182 db_content = content
yshah771dea82024-07-05 15:11:49 +00001183
garciadeblas96b94f52024-07-08 16:18:21 +02001184 workflow_name = await self.odu.launch_workflow(
1185 "update_oka", op_id, op_params, content
1186 )
1187 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1188 workflow_name
1189 )
1190 self.logger.info(
1191 "Workflow Status: {} Workflow Message: {}".format(
1192 workflow_status, workflow_msg
1193 )
1194 )
yshah771dea82024-07-05 15:11:49 +00001195
1196 if workflow_status:
1197 db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1198 else:
1199 db_content["resourceState"] = "ERROR"
1200
1201 db_content = self.update_operation_history(db_content, workflow_status, None)
1202 # self.logger.info("Db content: {}".format(db_content))
garciadeblas96b94f52024-07-08 16:18:21 +02001203 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001204
1205 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001206 resource_status, resource_msg = await self.odu.check_resource_status(
1207 "update_oka", op_id, op_params, db_content
yshah771dea82024-07-05 15:11:49 +00001208 )
garciadeblas96b94f52024-07-08 16:18:21 +02001209 self.logger.info(
1210 "Resource Status: {} Resource Message: {}".format(
1211 resource_status, resource_msg
1212 )
1213 )
yshah771dea82024-07-05 15:11:49 +00001214
1215 if resource_status:
1216 db_content["resourceState"] = "READY"
1217 else:
1218 db_content["resourceState"] = "ERROR"
1219
1220 db_content = self.update_operation_history(
1221 db_content, workflow_status, resource_status
1222 )
1223
1224 db_content["operatingState"] = "IDLE"
garciadeblas96b94f52024-07-08 16:18:21 +02001225 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001226 return
1227
garciadeblas96b94f52024-07-08 16:18:21 +02001228 async def delete(self, op_id, op_params, content):
1229 self.logger.info("OKA delete Enter")
1230 db_content = content
yshah771dea82024-07-05 15:11:49 +00001231
garciadeblas96b94f52024-07-08 16:18:21 +02001232 workflow_name = await self.odu.launch_workflow(
1233 "delete_oka", op_id, op_params, content
1234 )
1235 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1236 workflow_name
1237 )
1238 self.logger.info(
1239 "Workflow Status: {} Workflow Message: {}".format(
1240 workflow_status, workflow_msg
1241 )
1242 )
yshah771dea82024-07-05 15:11:49 +00001243
1244 if workflow_status:
1245 db_content["state"] = "DELETED"
1246 db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1247 else:
1248 db_content["state"] = "FAILED_DELETION"
1249 db_content["resourceState"] = "ERROR"
1250
1251 db_content = self.update_operation_history(db_content, workflow_status, None)
garciadeblas96b94f52024-07-08 16:18:21 +02001252 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001253
1254 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001255 resource_status, resource_msg = await self.odu.check_resource_status(
1256 "delete_oka", op_id, op_params, db_content
yshah771dea82024-07-05 15:11:49 +00001257 )
garciadeblas96b94f52024-07-08 16:18:21 +02001258 self.logger.info(
1259 "Resource Status: {} Resource Message: {}".format(
1260 resource_status, resource_msg
1261 )
1262 )
yshah771dea82024-07-05 15:11:49 +00001263
1264 if resource_status:
1265 db_content["resourceState"] = "READY"
1266 else:
1267 db_content["resourceState"] = "ERROR"
1268
1269 db_content = self.update_operation_history(
1270 db_content, workflow_status, resource_status
1271 )
1272
1273 db_content["operatingState"] = "IDLE"
garciadeblas96b94f52024-07-08 16:18:21 +02001274 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001275
1276 if db_content["state"] == "DELETED":
garciadeblas96b94f52024-07-08 16:18:21 +02001277 self.db.del_one(self.db_collection, {"_id": db_content["_id"]})
yshah771dea82024-07-05 15:11:49 +00001278 return
1279
1280
1281class KsuLcm(LcmBase):
1282 db_collection = "ksus"
1283
1284 def __init__(self, msg, lcm_tasks, config):
1285 """
1286 Init, Connect to database, filesystem storage, and messaging
1287 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
1288 :return: None
1289 """
1290
garciadeblas4623e982024-09-11 14:28:38 +02001291 self.logger = logging.getLogger("lcm.gitops")
yshah771dea82024-07-05 15:11:49 +00001292 self.lcm_tasks = lcm_tasks
1293 self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config)
1294
1295 super().__init__(msg, self.logger)
1296
garciadeblas96b94f52024-07-08 16:18:21 +02001297 async def create(self, op_id, op_params, content):
1298 self.logger.info("ksu Create Enter")
yshah771dea82024-07-05 15:11:49 +00001299
garciadeblas96b94f52024-07-08 16:18:21 +02001300 workflow_name = await self.odu.launch_workflow(
1301 "create_ksus", op_id, op_params, content
1302 )
1303 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1304 workflow_name
1305 )
1306 self.logger.info(
1307 "Workflow Status: {} Workflow Message: {}".format(
1308 workflow_status, workflow_msg
yshah771dea82024-07-05 15:11:49 +00001309 )
garciadeblas96b94f52024-07-08 16:18:21 +02001310 )
yshah771dea82024-07-05 15:11:49 +00001311
garciadeblas96b94f52024-07-08 16:18:21 +02001312 for db_ksu in content:
1313 if workflow_status:
1314 db_ksu["state"] = "CREATED"
1315 db_ksu["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
yshah771dea82024-07-05 15:11:49 +00001316 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001317 db_ksu["state"] = "FAILED_CREATION"
1318 db_ksu["resourceState"] = "ERROR"
yshah771dea82024-07-05 15:11:49 +00001319
garciadeblas96b94f52024-07-08 16:18:21 +02001320 db_ksu = self.update_operation_history(db_ksu, workflow_status, None)
1321 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
1322
1323 if workflow_status:
1324 resource_status, resource_msg = await self.odu.check_resource_status(
1325 "create_ksus", op_id, op_params, content
1326 )
1327 self.logger.info(
1328 "Resource Status: {} Resource Message: {}".format(
1329 resource_status, resource_msg
1330 )
yshah771dea82024-07-05 15:11:49 +00001331 )
1332
garciadeblas96b94f52024-07-08 16:18:21 +02001333 for db_ksu in content:
1334 if resource_status:
1335 db_ksu["resourceState"] = "READY"
1336 else:
1337 db_ksu["resourceState"] = "ERROR"
1338
1339 db_ksu = self.update_operation_history(
1340 db_ksu, workflow_status, resource_status
1341 )
1342
1343 for db_ksu in content:
1344 db_ksu["operatingState"] = "IDLE"
1345 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
yshah771dea82024-07-05 15:11:49 +00001346
1347 return
1348
garciadeblas96b94f52024-07-08 16:18:21 +02001349 async def edit(self, op_id, op_params, content):
1350 self.logger.info("ksu edit Enter")
yshah771dea82024-07-05 15:11:49 +00001351
garciadeblas96b94f52024-07-08 16:18:21 +02001352 workflow_name = await self.odu.launch_workflow(
1353 "update_ksus", op_id, op_params, content
1354 )
1355 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1356 workflow_name
1357 )
1358 self.logger.info(
1359 "Workflow Status: {} Workflow Message: {}".format(
1360 workflow_status, workflow_msg
yshah771dea82024-07-05 15:11:49 +00001361 )
garciadeblas96b94f52024-07-08 16:18:21 +02001362 )
yshah771dea82024-07-05 15:11:49 +00001363
garciadeblas96b94f52024-07-08 16:18:21 +02001364 for db_ksu in content:
1365 if workflow_status:
1366 db_ksu["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
yshah771dea82024-07-05 15:11:49 +00001367 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001368 db_ksu["resourceState"] = "ERROR"
yshah771dea82024-07-05 15:11:49 +00001369
garciadeblas96b94f52024-07-08 16:18:21 +02001370 db_ksu = self.update_operation_history(db_ksu, workflow_status, None)
1371 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
1372
1373 if workflow_status:
1374 resource_status, resource_msg = await self.odu.check_resource_status(
1375 "update_ksus", op_id, op_params, content
1376 )
1377 self.logger.info(
1378 "Resource Status: {} Resource Message: {}".format(
1379 resource_status, resource_msg
1380 )
yshah771dea82024-07-05 15:11:49 +00001381 )
1382
garciadeblas96b94f52024-07-08 16:18:21 +02001383 for db_ksu in content:
1384 if resource_status:
1385 db_ksu["resourceState"] = "READY"
1386 else:
1387 db_ksu["resourceState"] = "ERROR"
1388
1389 db_ksu = self.update_operation_history(
1390 db_ksu, workflow_status, resource_status
1391 )
1392
1393 for db_ksu, ksu_params in zip(content, op_params):
1394 db_ksu["operatingState"] = "IDLE"
1395 if workflow_status:
1396 db_ksu["name"] = ksu_params["name"]
1397 db_ksu["description"] = ksu_params["description"]
1398 db_ksu["profile"]["profile_type"] = ksu_params["profile"][
1399 "profile_type"
1400 ]
1401 db_ksu["profile"]["_id"] = ksu_params["profile"]["_id"]
1402 db_ksu["oka"] = ksu_params["oka"]
1403 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
1404
yshah771dea82024-07-05 15:11:49 +00001405 return
1406
garciadeblas96b94f52024-07-08 16:18:21 +02001407 async def delete(self, op_id, op_params, content):
1408 self.logger.info("ksu delete Enter")
yshah771dea82024-07-05 15:11:49 +00001409
garciadeblas96b94f52024-07-08 16:18:21 +02001410 workflow_name = await self.odu.launch_workflow(
1411 "delete_ksus", op_id, op_params, content
1412 )
1413 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1414 workflow_name
1415 )
1416 self.logger.info(
1417 "Workflow Status: {} Workflow Message: {}".format(
1418 workflow_status, workflow_msg
yshah771dea82024-07-05 15:11:49 +00001419 )
garciadeblas96b94f52024-07-08 16:18:21 +02001420 )
yshah771dea82024-07-05 15:11:49 +00001421
garciadeblas96b94f52024-07-08 16:18:21 +02001422 for db_ksu in content:
1423 if workflow_status:
1424 db_ksu["state"] = "DELETED"
1425 db_ksu["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
yshah771dea82024-07-05 15:11:49 +00001426 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001427 db_ksu["state"] = "FAILED_DELETION"
1428 db_ksu["resourceState"] = "ERROR"
yshah771dea82024-07-05 15:11:49 +00001429
garciadeblas96b94f52024-07-08 16:18:21 +02001430 db_ksu = self.update_operation_history(db_ksu, workflow_status, None)
1431 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
1432
1433 if workflow_status:
1434 resource_status, resource_msg = await self.odu.check_resource_status(
1435 "delete_ksus", op_id, op_params, content
1436 )
1437 self.logger.info(
1438 "Resource Status: {} Resource Message: {}".format(
1439 resource_status, resource_msg
1440 )
yshah771dea82024-07-05 15:11:49 +00001441 )
1442
garciadeblas96b94f52024-07-08 16:18:21 +02001443 for db_ksu in content:
1444 if resource_status:
1445 db_ksu["resourceState"] = "READY"
1446 else:
1447 db_ksu["resourceState"] = "ERROR"
yshah771dea82024-07-05 15:11:49 +00001448
garciadeblas96b94f52024-07-08 16:18:21 +02001449 db_ksu = self.update_operation_history(
1450 db_ksu, workflow_status, resource_status
1451 )
1452
1453 for db_ksu in content:
1454 db_ksu["operatingState"] = "IDLE"
1455 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
1456
1457 if db_ksu["state"] == "DELETED":
1458 self.db.del_one(self.db_collection, {"_id": db_ksu["_id"]})
yshah771dea82024-07-05 15:11:49 +00001459 return
1460
garciadeblas96b94f52024-07-08 16:18:21 +02001461 async def clone(self, op_id, op_params, db_content):
1462 self.logger.info("ksu clone Enter")
yshah771dea82024-07-05 15:11:49 +00001463
garciadeblas96b94f52024-07-08 16:18:21 +02001464 workflow_name = await self.odu.launch_workflow(
1465 "clone_ksus", op_id, op_params, db_content
1466 )
1467 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1468 workflow_name
1469 )
1470 self.logger.info(
1471 "Workflow Status: {} Workflow Message: {}".format(
1472 workflow_status, workflow_msg
1473 )
1474 )
yshah771dea82024-07-05 15:11:49 +00001475
1476 if workflow_status:
1477 db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1478 else:
1479 db_content["resourceState"] = "ERROR"
1480
1481 db_content = self.update_operation_history(db_content, workflow_status, None)
garciadeblas96b94f52024-07-08 16:18:21 +02001482 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001483
1484 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001485 resource_status, resource_msg = await self.odu.check_resource_status(
1486 "clone_ksus", op_id, op_params, db_content
yshah771dea82024-07-05 15:11:49 +00001487 )
garciadeblas96b94f52024-07-08 16:18:21 +02001488 self.logger.info(
1489 "Resource Status: {} Resource Message: {}".format(
1490 resource_status, resource_msg
1491 )
1492 )
yshah771dea82024-07-05 15:11:49 +00001493
1494 if resource_status:
1495 db_content["resourceState"] = "READY"
1496 else:
1497 db_content["resourceState"] = "ERROR"
1498
1499 db_content = self.update_operation_history(
1500 db_content, workflow_status, resource_status
1501 )
1502
1503 db_content["operatingState"] = "IDLE"
garciadeblas96b94f52024-07-08 16:18:21 +02001504 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001505 return
1506
garciadeblas96b94f52024-07-08 16:18:21 +02001507 async def move(self, op_id, op_params, db_content):
1508 self.logger.info("ksu move Enter")
yshah771dea82024-07-05 15:11:49 +00001509
garciadeblas96b94f52024-07-08 16:18:21 +02001510 workflow_name = await self.odu.launch_workflow(
1511 "move_ksus", op_id, op_params, db_content
1512 )
1513 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1514 workflow_name
1515 )
1516 self.logger.info(
1517 "Workflow Status: {} Workflow Message: {}".format(
1518 workflow_status, workflow_msg
1519 )
1520 )
yshah771dea82024-07-05 15:11:49 +00001521
1522 if workflow_status:
1523 db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1524 else:
1525 db_content["resourceState"] = "ERROR"
1526
1527 db_content = self.update_operation_history(db_content, workflow_status, None)
garciadeblas96b94f52024-07-08 16:18:21 +02001528 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001529
1530 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001531 resource_status, resource_msg = await self.odu.check_resource_status(
1532 "move_ksus", op_id, op_params, db_content
yshah771dea82024-07-05 15:11:49 +00001533 )
garciadeblas96b94f52024-07-08 16:18:21 +02001534 self.logger.info(
1535 "Resource Status: {} Resource Message: {}".format(
1536 resource_status, resource_msg
1537 )
1538 )
yshah771dea82024-07-05 15:11:49 +00001539 if resource_status:
1540 db_content["resourceState"] = "READY"
1541 else:
1542 db_content["resourceState"] = "ERROR"
1543
1544 db_content = self.update_operation_history(
1545 db_content, workflow_status, resource_status
1546 )
1547
1548 db_content["operatingState"] = "IDLE"
garciadeblas96b94f52024-07-08 16:18:21 +02001549 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001550 return