blob: c48228e0290ca85cce48ab420588b04a5ca9d1c9 [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
72 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +020073 resource_status, resource_msg = await self.odu.check_resource_status(
74 "create_cluster", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +000075 )
76 self.logger.info(
77 "resource_status is :{} and resource_msg is :{}".format(
78 resource_status, resource_msg
79 )
80 )
81 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +020082 db_cluster["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +000083 else:
garciadeblas96b94f52024-07-08 16:18:21 +020084 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +000085
garciadeblas96b94f52024-07-08 16:18:21 +020086 db_cluster["operatingState"] = "IDLE"
87 db_cluster = self.update_operation_history(
88 db_cluster, workflow_status, resource_status
rshri932105f2024-07-05 15:11:55 +000089 )
garciadeblas96b94f52024-07-08 16:18:21 +020090 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
91 self.update_profile_state(db_cluster, workflow_status, resource_status)
rshri932105f2024-07-05 15:11:55 +000092 return
93
garciadeblas96b94f52024-07-08 16:18:21 +020094 def update_profile_state(self, db_cluster, workflow_status, resource_status):
rshri932105f2024-07-05 15:11:55 +000095 profiles = [
96 "infra_controller_profiles",
97 "infra_config_profiles",
98 "app_profiles",
99 "resource_profiles",
100 ]
101 profiles_collection = {
102 "infra_controller_profiles": "k8sinfra_controller",
103 "infra_config_profiles": "k8sinfra_config",
104 "app_profiles": "k8sapp",
105 "resource_profiles": "k8sresource",
106 }
107 for profile_type in profiles:
garciadeblas96b94f52024-07-08 16:18:21 +0200108 profile_id = db_cluster[profile_type]
rshri932105f2024-07-05 15:11:55 +0000109 self.logger.info("profile id is : {}".format(profile_id))
110 db_collection = profiles_collection[profile_type]
111 self.logger.info("the db_collection is :{}".format(db_collection))
112 db_profile = self.db.get_one(db_collection, {"_id": profile_id})
113 self.logger.info("the db_profile is :{}".format(db_profile))
garciadeblas96b94f52024-07-08 16:18:21 +0200114 db_profile["state"] = db_cluster["state"]
115 db_profile["resourceState"] = db_cluster["resourceState"]
116 db_profile["operatingState"] = db_cluster["operatingState"]
rshri932105f2024-07-05 15:11:55 +0000117 db_profile = self.update_operation_history(
118 db_profile, workflow_status, resource_status
119 )
120 self.logger.info("the db_profile is :{}".format(db_profile))
121 self.db.set_one(db_collection, {"_id": db_profile["_id"]}, db_profile)
122
garciadeblas96b94f52024-07-08 16:18:21 +0200123 async def delete(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000124 self.logger.info("cluster delete Enter")
garciadeblas96b94f52024-07-08 16:18:21 +0200125 db_cluster = content["cluster"]
rshri932105f2024-07-05 15:11:55 +0000126
garciadeblas96b94f52024-07-08 16:18:21 +0200127 workflow_name = await self.odu.launch_workflow(
128 "delete_cluster", op_id, op_params, content
129 )
rshri932105f2024-07-05 15:11:55 +0000130 self.logger.info("workflow_name is :{}".format(workflow_name))
131
garciadeblas96b94f52024-07-08 16:18:21 +0200132 workflow_status, workflow_msg = await self.odu.check_workflow_status(
133 workflow_name
134 )
rshri932105f2024-07-05 15:11:55 +0000135 self.logger.info(
136 "workflow_status is :{} and workflow_msg is :{}".format(
137 workflow_status, workflow_msg
138 )
139 )
140 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200141 db_cluster["state"] = "DELETED"
142 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +0000143 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200144 db_cluster["state"] = "FAILED_DELETION"
145 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000146 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +0200147 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
148 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
rshri932105f2024-07-05 15:11:55 +0000149
150 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200151 resource_status, resource_msg = await self.odu.check_resource_status(
152 "delete_cluster", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000153 )
154 self.logger.info(
155 "resource_status is :{} and resource_msg is :{}".format(
156 resource_status, resource_msg
157 )
158 )
159 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200160 db_cluster["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +0000161 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200162 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000163
garciadeblas96b94f52024-07-08 16:18:21 +0200164 db_cluster["operatingState"] = "IDLE"
165 db_cluster = self.update_operation_history(
166 db_cluster, workflow_status, resource_status
167 )
168 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
rshri932105f2024-07-05 15:11:55 +0000169
garciadeblas96b94f52024-07-08 16:18:21 +0200170 # To delete it from DB
171 if db_cluster["state"] == "DELETED":
172 self.delete_cluster(db_cluster)
rshri932105f2024-07-05 15:11:55 +0000173 return
174
garciadeblas96b94f52024-07-08 16:18:21 +0200175 def delete_cluster(self, db_cluster):
176 # Actually, item_content is equal to db_cluster
177 # item_content = self.db.get_one("clusters", {"_id": db_cluster["_id"]})
178 # self.logger.debug("item_content is : {}".format(item_content))
rshri932105f2024-07-05 15:11:55 +0000179
rshri932105f2024-07-05 15:11:55 +0000180 # detach profiles
181 update_dict = None
182 profiles_to_detach = [
183 "infra_controller_profiles",
184 "infra_config_profiles",
185 "app_profiles",
186 "resource_profiles",
187 ]
188 profiles_collection = {
189 "infra_controller_profiles": "k8sinfra_controller",
190 "infra_config_profiles": "k8sinfra_config",
191 "app_profiles": "k8sapp",
192 "resource_profiles": "k8sresource",
193 }
194 for profile_type in profiles_to_detach:
garciadeblas96b94f52024-07-08 16:18:21 +0200195 if db_cluster.get(profile_type):
rshri932105f2024-07-05 15:11:55 +0000196 self.logger.info("the profile_type is :{}".format(profile_type))
garciadeblas96b94f52024-07-08 16:18:21 +0200197 profile_ids = db_cluster[profile_type]
rshri932105f2024-07-05 15:11:55 +0000198 self.logger.info("the profile_ids is :{}".format(profile_ids))
199 profile_ids_copy = deepcopy(profile_ids)
200 self.logger.info("the profile_ids_copy is :{}".format(profile_ids_copy))
201 for profile_id in profile_ids_copy:
202 self.logger.info("the profile_id is :{}".format(profile_id))
203 db_collection = profiles_collection[profile_type]
204 self.logger.info("the db_collection is :{}".format(db_collection))
205 db_profile = self.db.get_one(db_collection, {"_id": profile_id})
206 self.logger.info("the db_profile is :{}".format(db_profile))
207 self.logger.info(
garciadeblas96b94f52024-07-08 16:18:21 +0200208 "the item_content name is :{}".format(db_cluster["name"])
rshri932105f2024-07-05 15:11:55 +0000209 )
210 self.logger.info(
211 "the db_profile name is :{}".format(db_profile["name"])
212 )
garciadeblas96b94f52024-07-08 16:18:21 +0200213 if db_cluster["name"] == db_profile["name"]:
rshri932105f2024-07-05 15:11:55 +0000214 self.logger.info("it is getting into if default")
215 self.db.del_one(db_collection, {"_id": profile_id})
216 else:
217 self.logger.info("it is getting into else non default")
218 profile_ids.remove(profile_id)
219 update_dict = {profile_type: profile_ids}
220 self.logger.info(f"the update dict is :{update_dict}")
221 self.db.set_one(
garciadeblas96b94f52024-07-08 16:18:21 +0200222 "clusters", {"_id": db_cluster["_id"]}, update_dict
rshri932105f2024-07-05 15:11:55 +0000223 )
garciadeblas96b94f52024-07-08 16:18:21 +0200224 self.db.del_one("clusters", {"_id": db_cluster["_id"]})
225 self.logger.info("the id is :{}".format(db_cluster["_id"]))
rshri932105f2024-07-05 15:11:55 +0000226
garciadeblas96b94f52024-07-08 16:18:21 +0200227 async def attach_profile(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000228 self.logger.info("profile attach Enter")
garciadeblas96b94f52024-07-08 16:18:21 +0200229 db_cluster = content["cluster"]
230 db_profile = content["profile"]
231 profile_type = db_profile["profile_type"]
232 profile_id = db_profile["_id"]
rshri932105f2024-07-05 15:11:55 +0000233 self.logger.info("profile type is : {}".format(profile_type))
rshri932105f2024-07-05 15:11:55 +0000234 self.logger.info("profile id is : {}".format(profile_id))
235
garciadeblas96b94f52024-07-08 16:18:21 +0200236 workflow_name = await self.odu.launch_workflow(
237 "attach_profile_to_cluster", op_id, op_params, content
238 )
rshri932105f2024-07-05 15:11:55 +0000239 self.logger.info("workflow_name is :{}".format(workflow_name))
240
garciadeblas96b94f52024-07-08 16:18:21 +0200241 workflow_status, workflow_msg = await self.odu.check_workflow_status(
242 workflow_name
243 )
rshri932105f2024-07-05 15:11:55 +0000244 self.logger.info(
245 "workflow_status is :{} and workflow_msg is :{}".format(
246 workflow_status, workflow_msg
247 )
248 )
249 if workflow_status:
250 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
251 else:
252 db_cluster["resourceState"] = "ERROR"
253 # has to call update_operation_history return content
254 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
255 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
256
257 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200258 resource_status, resource_msg = await self.odu.check_resource_status(
259 "attach_profile_to_cluster", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000260 )
261 self.logger.info(
262 "resource_status is :{} and resource_msg is :{}".format(
263 resource_status, resource_msg
264 )
265 )
266 if resource_status:
267 db_cluster["resourceState"] = "READY"
268 else:
269 db_cluster["resourceState"] = "ERROR"
270
271 db_cluster["operatingState"] = "IDLE"
272 db_cluster = self.update_operation_history(
273 db_cluster, workflow_status, resource_status
274 )
rshri932105f2024-07-05 15:11:55 +0000275 profile_list = db_cluster[profile_type]
276 self.logger.info("profile list is : {}".format(profile_list))
277 if resource_status:
278 self.logger.info("it is getting into resource status true")
279 profile_list.append(profile_id)
280 self.logger.info("profile list is : {}".format(profile_list))
281 db_cluster[profile_type] = profile_list
282 self.logger.info("db cluster is : {}".format(db_cluster))
283 # update_dict = {item: profile_list}
284 # self.logger.info("the update_dict is :{}".format(update_dict))
285 # self.db.set_one(self.topic, filter_q, update_dict)
286 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
287
288 return
289
garciadeblas96b94f52024-07-08 16:18:21 +0200290 async def detach_profile(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000291 self.logger.info("profile dettach Enter")
garciadeblas96b94f52024-07-08 16:18:21 +0200292 db_cluster = content["cluster"]
293 db_profile = content["profile"]
294 profile_type = db_profile["profile_type"]
295 profile_id = db_profile["_id"]
rshri932105f2024-07-05 15:11:55 +0000296 self.logger.info("profile type is : {}".format(profile_type))
rshri932105f2024-07-05 15:11:55 +0000297 self.logger.info("profile id is : {}".format(profile_id))
298
garciadeblas96b94f52024-07-08 16:18:21 +0200299 workflow_name = await self.odu.launch_workflow(
300 "detach_profile_from_cluster", op_id, op_params, content
301 )
rshri932105f2024-07-05 15:11:55 +0000302 self.logger.info("workflow_name is :{}".format(workflow_name))
303
garciadeblas96b94f52024-07-08 16:18:21 +0200304 workflow_status, workflow_msg = await self.odu.check_workflow_status(
305 workflow_name
306 )
rshri932105f2024-07-05 15:11:55 +0000307 self.logger.info(
308 "workflow_status is :{} and workflow_msg is :{}".format(
309 workflow_status, workflow_msg
310 )
311 )
312 if workflow_status:
313 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
314 else:
315 db_cluster["resourceState"] = "ERROR"
316 # has to call update_operation_history return content
317 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
318 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
319
320 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200321 resource_status, resource_msg = await self.odu.check_resource_status(
322 "detach_profile_from_cluster", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000323 )
324 self.logger.info(
325 "resource_status is :{} and resource_msg is :{}".format(
326 resource_status, resource_msg
327 )
328 )
329 if resource_status:
330 db_cluster["resourceState"] = "READY"
331 else:
332 db_cluster["resourceState"] = "ERROR"
333
334 db_cluster["operatingState"] = "IDLE"
335 db_cluster = self.update_operation_history(
336 db_cluster, workflow_status, resource_status
337 )
rshri932105f2024-07-05 15:11:55 +0000338 profile_list = db_cluster[profile_type]
339 self.logger.info("profile list is : {}".format(profile_list))
340 if resource_status:
341 self.logger.info("it is getting into resource status true")
342 profile_list.remove(profile_id)
343 self.logger.info("profile list is : {}".format(profile_list))
344 db_cluster[profile_type] = profile_list
345 self.logger.info("db cluster is : {}".format(db_cluster))
346 # update_dict = {item: profile_list}
347 # self.logger.info("the update_dict is :{}".format(update_dict))
348 # self.db.set_one(self.topic, filter_q, update_dict)
349 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
350
351 return
352
garciadeblas96b94f52024-07-08 16:18:21 +0200353 async def register(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000354 self.logger.info("cluster register enter")
garciadeblas96b94f52024-07-08 16:18:21 +0200355 db_cluster = content["cluster"]
rshri932105f2024-07-05 15:11:55 +0000356
garciadeblas96b94f52024-07-08 16:18:21 +0200357 workflow_name = await self.odu.launch_workflow(
358 "register_cluster", op_id, op_params, content
359 )
rshri932105f2024-07-05 15:11:55 +0000360 self.logger.info("workflow_name is :{}".format(workflow_name))
361
garciadeblas96b94f52024-07-08 16:18:21 +0200362 workflow_status, workflow_msg = await self.odu.check_workflow_status(
363 workflow_name
364 )
rshri932105f2024-07-05 15:11:55 +0000365 self.logger.info(
366 "workflow_status is :{} and workflow_msg is :{}".format(
367 workflow_status, workflow_msg
368 )
369 )
370 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200371 db_cluster["state"] = "CREATED"
372 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +0000373 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200374 db_cluster["state"] = "FAILED_CREATION"
375 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000376 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +0200377 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
378 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
rshri932105f2024-07-05 15:11:55 +0000379
380 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200381 resource_status, resource_msg = await self.odu.check_resource_status(
382 "register_cluster", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000383 )
384 self.logger.info(
385 "resource_status is :{} and resource_msg is :{}".format(
386 resource_status, resource_msg
387 )
388 )
389 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200390 db_cluster["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +0000391 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200392 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000393
garciadeblas96b94f52024-07-08 16:18:21 +0200394 db_cluster["operatingState"] = "IDLE"
395 db_cluster = self.update_operation_history(
396 db_cluster, workflow_status, resource_status
rshri932105f2024-07-05 15:11:55 +0000397 )
garciadeblas96b94f52024-07-08 16:18:21 +0200398 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
399 self.update_profile_state(db_cluster, workflow_status, resource_status)
rshri932105f2024-07-05 15:11:55 +0000400 return
401
garciadeblas96b94f52024-07-08 16:18:21 +0200402 async def deregister(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000403 self.logger.info("cluster deregister enter")
garciadeblas96b94f52024-07-08 16:18:21 +0200404 db_cluster = content["cluster"]
rshri932105f2024-07-05 15:11:55 +0000405
garciadeblas96b94f52024-07-08 16:18:21 +0200406 self.logger.info("db_cluster is : {}".format(db_cluster))
rshri932105f2024-07-05 15:11:55 +0000407
garciadeblas96b94f52024-07-08 16:18:21 +0200408 workflow_name = await self.odu.launch_workflow(
409 "deregister_cluster", op_id, op_params, content
410 )
rshri932105f2024-07-05 15:11:55 +0000411 self.logger.info("workflow_name is :{}".format(workflow_name))
412
garciadeblas96b94f52024-07-08 16:18:21 +0200413 workflow_status, workflow_msg = await self.odu.check_workflow_status(
414 workflow_name
415 )
rshri932105f2024-07-05 15:11:55 +0000416 self.logger.info(
417 "workflow_status is :{} and workflow_msg is :{}".format(
418 workflow_status, workflow_msg
419 )
420 )
421 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200422 db_cluster["state"] = "DELETED"
423 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +0000424 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200425 db_cluster["state"] = "FAILED_DELETION"
426 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000427 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +0200428 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
429 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
rshri932105f2024-07-05 15:11:55 +0000430
431 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200432 resource_status, resource_msg = await self.odu.check_resource_status(
433 "deregister_cluster", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000434 )
435 self.logger.info(
436 "resource_status is :{} and resource_msg is :{}".format(
437 resource_status, resource_msg
438 )
439 )
440 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200441 db_cluster["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +0000442 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200443 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000444
garciadeblas96b94f52024-07-08 16:18:21 +0200445 db_cluster["operatingState"] = "IDLE"
446 db_cluster = self.update_operation_history(
447 db_cluster, workflow_status, resource_status
448 )
449 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
rshri932105f2024-07-05 15:11:55 +0000450
garciadeblas96b94f52024-07-08 16:18:21 +0200451 # To delete it from DB
452 if db_cluster["state"] == "DELETED":
453 self.db.del_one("clusters", {"_id": db_cluster["_id"]})
rshri932105f2024-07-05 15:11:55 +0000454 return
455
garciadeblas96b94f52024-07-08 16:18:21 +0200456 async def get_creds(self, db_cluster):
457 self.logger.info("Cluster get creds Enter")
458 result, cluster_creds = await self.odu.get_cluster_credentials(db_cluster)
459 if result:
460 db_cluster["credentials"] = cluster_creds
461 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
yshah771dea82024-07-05 15:11:49 +0000462 return
463
garciadeblas96b94f52024-07-08 16:18:21 +0200464 async def update(self, op_id, op_params, content):
465 self.logger.info("Cluster update Enter")
466 db_cluster = content["cluster"]
yshah771dea82024-07-05 15:11:49 +0000467
garciadeblas96b94f52024-07-08 16:18:21 +0200468 workflow_name = await self.odu.launch_workflow(
469 "update_cluster", op_id, op_params, content
470 )
471 workflow_status, workflow_msg = await self.odu.check_workflow_status(
472 workflow_name
473 )
474 self.logger.info(
475 "Workflow Status: {} Workflow Message: {}".format(
476 workflow_status, workflow_msg
yshah771dea82024-07-05 15:11:49 +0000477 )
garciadeblas96b94f52024-07-08 16:18:21 +0200478 )
479
480 if workflow_status:
481 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
482 else:
483 db_cluster["resourceState"] = "ERROR"
484
485 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
486 # self.logger.info("Db content: {}".format(db_content))
487 # self.db.set_one(self.db_collection, {"_id": _id}, db_cluster)
488 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
489
490 if workflow_status:
491 resource_status, resource_msg = await self.odu.check_resource_status(
492 "update_cluster", op_id, op_params, content
493 )
494 self.logger.info(
495 "Resource Status: {} Resource Message: {}".format(
496 resource_status, resource_msg
497 )
498 )
yshah771dea82024-07-05 15:11:49 +0000499
500 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200501 db_cluster["resourceState"] = "READY"
yshah771dea82024-07-05 15:11:49 +0000502 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200503 db_cluster["resourceState"] = "ERROR"
yshah771dea82024-07-05 15:11:49 +0000504
garciadeblas96b94f52024-07-08 16:18:21 +0200505 db_cluster["operatingState"] = "IDLE"
506 db_cluster = self.update_operation_history(
507 db_cluster, workflow_status, resource_status
508 )
509 # self.logger.info("db_cluster: {}".format(db_cluster))
510 # TODO: verify enxtcondition
511 # For the moment, if the workflow completed successfully, then we update the db accordingly.
512 if workflow_status:
513 if "k8s_version" in op_params:
514 db_cluster["k8s_version"] = op_params["k8s_version"]
515 elif "node_count" in op_params:
516 db_cluster["node_count"] = op_params["node_count"]
517 # self.db.set_one(self.db_collection, {"_id": _id}, db_content)
518 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
yshah771dea82024-07-05 15:11:49 +0000519 return
520
521
522class CloudCredentialsLcm(LcmBase):
523 db_collection = "vim_accounts"
524
525 def __init__(self, msg, lcm_tasks, config):
526 """
527 Init, Connect to database, filesystem storage, and messaging
528 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
529 :return: None
530 """
531
garciadeblas4623e982024-09-11 14:28:38 +0200532 self.logger = logging.getLogger("lcm.gitops")
yshah771dea82024-07-05 15:11:49 +0000533 self.lcm_tasks = lcm_tasks
534 self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config)
535
536 super().__init__(msg, self.logger)
537
garciadeblas96b94f52024-07-08 16:18:21 +0200538 async def add(self, op_id, op_params, content):
yshah771dea82024-07-05 15:11:49 +0000539 self.logger.info("Cloud Credentials create")
540 workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +0200541 "create_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000542 )
543
544 workflow_status, workflow_msg = await self.odu.check_workflow_status(
545 workflow_name
546 )
547
548 self.logger.info(
549 "Workflow Status: {} Workflow Msg: {}".format(workflow_status, workflow_msg)
550 )
551
552 if workflow_status:
553 resource_status, resource_msg = await self.odu.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +0200554 "create_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000555 )
556 self.logger.info(
557 "Resource Status: {} Resource Message: {}".format(
558 resource_status, resource_msg
559 )
560 )
561 return
562
garciadeblas96b94f52024-07-08 16:18:21 +0200563 async def edit(self, op_id, op_params, content):
yshah771dea82024-07-05 15:11:49 +0000564 workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +0200565 "update_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000566 )
567 workflow_status, workflow_msg = await self.odu.check_workflow_status(
568 workflow_name
569 )
570 self.logger.info(
571 "Workflow Status: {} Workflow Msg: {}".format(workflow_status, workflow_msg)
572 )
573
574 if workflow_status:
575 resource_status, resource_msg = await self.odu.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +0200576 "update_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000577 )
578 self.logger.info(
579 "Resource Status: {} Resource Message: {}".format(
580 resource_status, resource_msg
581 )
582 )
583 return
584
garciadeblas96b94f52024-07-08 16:18:21 +0200585 async def remove(self, op_id, op_params, content):
yshah771dea82024-07-05 15:11:49 +0000586 self.logger.info("Cloud Credentials delete")
587 workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +0200588 "delete_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000589 )
590 workflow_status, workflow_msg = await self.odu.check_workflow_status(
591 workflow_name
592 )
593 self.logger.info(
594 "Workflow Status: {} Workflow Msg: {}".format(workflow_status, workflow_msg)
595 )
596
597 if workflow_status:
598 resource_status, resource_msg = await self.odu.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +0200599 "delete_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000600 )
601 self.logger.info(
602 "Resource Status: {} Resource Message: {}".format(
603 resource_status, resource_msg
604 )
605 )
606 self.db.del_one(self.db_collection, {"_id": content["_id"]})
607 return
608
rshri932105f2024-07-05 15:11:55 +0000609
610class K8sAppLcm(LcmBase):
611 def __init__(self, msg, lcm_tasks, config):
612 """
613 Init, Connect to database, filesystem storage, and messaging
614 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
615 :return: None
616 """
617
garciadeblas4623e982024-09-11 14:28:38 +0200618 self.logger = logging.getLogger("lcm.gitops")
rshri932105f2024-07-05 15:11:55 +0000619 self.lcm_tasks = lcm_tasks
620 self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config)
621
622 super().__init__(msg, self.logger)
623
garciadeblas96b94f52024-07-08 16:18:21 +0200624 async def create(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000625 self.logger.info("App Create Enter")
626
garciadeblas96b94f52024-07-08 16:18:21 +0200627 workflow_name = await self.odu.launch_workflow(
628 "create_profile", op_id, op_params, content
629 )
rshri932105f2024-07-05 15:11:55 +0000630 self.logger.info("workflow_name is :{}".format(workflow_name))
631
garciadeblas96b94f52024-07-08 16:18:21 +0200632 workflow_status, workflow_msg = await self.odu.check_workflow_status(
633 workflow_name
634 )
rshri932105f2024-07-05 15:11:55 +0000635 self.logger.info(
636 "workflow_status is :{} and workflow_msg is :{}".format(
637 workflow_status, workflow_msg
638 )
639 )
640 if workflow_status:
641 content["state"] = "CREATED"
642 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
643 else:
644 content["state"] = "FAILED_CREATION"
645 content["resourceState"] = "ERROR"
646 # has to call update_operation_history return content
647 content = self.update_operation_history(content, workflow_status, None)
648 self.db.set_one("k8sapp", {"_id": content["_id"]}, content)
649
650 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200651 resource_status, resource_msg = await self.odu.check_resource_status(
652 "create_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000653 )
654 self.logger.info(
655 "resource_status is :{} and resource_msg is :{}".format(
656 resource_status, resource_msg
657 )
658 )
659 if resource_status:
660 content["resourceState"] = "READY"
661 else:
662 content["resourceState"] = "ERROR"
663
664 content["operatingState"] = "IDLE"
665 content = self.update_operation_history(
666 content, workflow_status, resource_status
667 )
668 self.db.set_one("k8sapp", {"_id": content["_id"]}, content)
669
670 return
671
garciadeblas96b94f52024-07-08 16:18:21 +0200672 async def delete(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000673 self.logger.info("App delete Enter")
rshri932105f2024-07-05 15:11:55 +0000674
garciadeblas96b94f52024-07-08 16:18:21 +0200675 workflow_name = await self.odu.launch_workflow(
676 "delete_profile", op_id, op_params, content
677 )
rshri932105f2024-07-05 15:11:55 +0000678 self.logger.info("workflow_name is :{}".format(workflow_name))
679
garciadeblas96b94f52024-07-08 16:18:21 +0200680 workflow_status, workflow_msg = await self.odu.check_workflow_status(
681 workflow_name
682 )
rshri932105f2024-07-05 15:11:55 +0000683 self.logger.info(
684 "workflow_status is :{} and workflow_msg is :{}".format(
685 workflow_status, workflow_msg
686 )
687 )
688 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200689 content["state"] = "DELETED"
690 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +0000691 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200692 content["state"] = "FAILED_DELETION"
693 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000694 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +0200695 content = self.update_operation_history(content, workflow_status, None)
rshri932105f2024-07-05 15:11:55 +0000696 self.db.set_one("k8sapp", {"_id": content["_id"]}, content)
697
698 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200699 resource_status, resource_msg = await self.odu.check_resource_status(
700 "delete_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000701 )
702 self.logger.info(
703 "resource_status is :{} and resource_msg is :{}".format(
704 resource_status, resource_msg
705 )
706 )
707 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200708 content["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +0000709 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200710 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000711
garciadeblas96b94f52024-07-08 16:18:21 +0200712 content["operatingState"] = "IDLE"
713 content = self.update_operation_history(
714 content, workflow_status, resource_status
715 )
716 self.db.set_one("k8sapp", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +0000717
garciadeblas96b94f52024-07-08 16:18:21 +0200718 # To delete it from DB
719 if content["state"] == "DELETED":
rshri932105f2024-07-05 15:11:55 +0000720 self.db.del_one("k8sapp", {"_id": content["_id"]})
721 return
722
723
724class K8sResourceLcm(LcmBase):
725 def __init__(self, msg, lcm_tasks, config):
726 """
727 Init, Connect to database, filesystem storage, and messaging
728 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
729 :return: None
730 """
731
garciadeblas4623e982024-09-11 14:28:38 +0200732 self.logger = logging.getLogger("lcm.gitops")
rshri932105f2024-07-05 15:11:55 +0000733 self.lcm_tasks = lcm_tasks
734 self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config)
735
736 super().__init__(msg, self.logger)
737
garciadeblas96b94f52024-07-08 16:18:21 +0200738 async def create(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000739 self.logger.info("Resource Create Enter")
740
garciadeblas96b94f52024-07-08 16:18:21 +0200741 workflow_name = await self.odu.launch_workflow(
742 "create_profile", op_id, op_params, content
743 )
rshri932105f2024-07-05 15:11:55 +0000744 self.logger.info("workflow_name is :{}".format(workflow_name))
745
garciadeblas96b94f52024-07-08 16:18:21 +0200746 workflow_status, workflow_msg = await self.odu.check_workflow_status(
747 workflow_name
748 )
rshri932105f2024-07-05 15:11:55 +0000749 self.logger.info(
750 "workflow_status is :{} and workflow_msg is :{}".format(
751 workflow_status, workflow_msg
752 )
753 )
754 if workflow_status:
755 content["state"] = "CREATED"
756 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
757 else:
758 content["state"] = "FAILED_CREATION"
759 content["resourceState"] = "ERROR"
760 # has to call update_operation_history return content
761 content = self.update_operation_history(content, workflow_status, None)
762 self.db.set_one("k8sresource", {"_id": content["_id"]}, content)
763
764 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200765 resource_status, resource_msg = await self.odu.check_resource_status(
766 "create_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000767 )
768 self.logger.info(
769 "resource_status is :{} and resource_msg is :{}".format(
770 resource_status, resource_msg
771 )
772 )
773 if resource_status:
774 content["resourceState"] = "READY"
775 else:
776 content["resourceState"] = "ERROR"
777
778 content["operatingState"] = "IDLE"
779 content = self.update_operation_history(
780 content, workflow_status, resource_status
781 )
782 self.db.set_one("k8sresource", {"_id": content["_id"]}, content)
783
784 return
785
garciadeblas96b94f52024-07-08 16:18:21 +0200786 async def delete(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000787 self.logger.info("Resource delete Enter")
garciadeblas96b94f52024-07-08 16:18:21 +0200788 content = self.db.get_one("k8sresource", {"_id": content["_id"]})
rshri932105f2024-07-05 15:11:55 +0000789
garciadeblas96b94f52024-07-08 16:18:21 +0200790 workflow_name = await self.odu.launch_workflow(
791 "delete_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:
garciadeblas96b94f52024-07-08 16:18:21 +0200804 content["state"] = "DELETED"
805 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +0000806 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200807 content["state"] = "FAILED_DELETION"
808 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000809 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +0200810 content = self.update_operation_history(content, workflow_status, None)
811 self.db.set_one("k8sresource", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +0000812
813 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200814 resource_status, resource_msg = await self.odu.check_resource_status(
815 "delete_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:
garciadeblas96b94f52024-07-08 16:18:21 +0200823 content["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +0000824 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200825 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000826
garciadeblas96b94f52024-07-08 16:18:21 +0200827 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)
rshri932105f2024-07-05 15:11:55 +0000832
garciadeblas96b94f52024-07-08 16:18:21 +0200833 # To delete it from DB
834 if content["state"] == "DELETED":
rshri932105f2024-07-05 15:11:55 +0000835 self.db.del_one("k8sresource", {"_id": content["_id"]})
836 return
837
838
839class K8sInfraControllerLcm(LcmBase):
840 def __init__(self, msg, lcm_tasks, config):
841 """
842 Init, Connect to database, filesystem storage, and messaging
843 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
844 :return: None
845 """
846
garciadeblas4623e982024-09-11 14:28:38 +0200847 self.logger = logging.getLogger("lcm.gitops")
rshri932105f2024-07-05 15:11:55 +0000848 self.lcm_tasks = lcm_tasks
849 self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config)
850
851 super().__init__(msg, self.logger)
852
garciadeblas96b94f52024-07-08 16:18:21 +0200853 async def create(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000854 self.logger.info("Infra controller Create Enter")
855
garciadeblas96b94f52024-07-08 16:18:21 +0200856 workflow_name = await self.odu.launch_workflow(
857 "create_profile", op_id, op_params, content
858 )
rshri932105f2024-07-05 15:11:55 +0000859 self.logger.info("workflow_name is :{}".format(workflow_name))
860
garciadeblas96b94f52024-07-08 16:18:21 +0200861 workflow_status, workflow_msg = await self.odu.check_workflow_status(
862 workflow_name
863 )
rshri932105f2024-07-05 15:11:55 +0000864 self.logger.info(
865 "workflow_status is :{} and workflow_msg is :{}".format(
866 workflow_status, workflow_msg
867 )
868 )
869 if workflow_status:
870 content["state"] = "CREATED"
871 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
872 else:
873 content["state"] = "FAILED_CREATION"
874 content["resourceState"] = "ERROR"
875 # has to call update_operation_history return content
876 content = self.update_operation_history(content, workflow_status, None)
877 self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content)
878
879 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200880 resource_status, resource_msg = await self.odu.check_resource_status(
881 "create_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000882 )
883 self.logger.info(
884 "resource_status is :{} and resource_msg is :{}".format(
885 resource_status, resource_msg
886 )
887 )
888 if resource_status:
889 content["resourceState"] = "READY"
890 else:
891 content["resourceState"] = "ERROR"
892
893 content["operatingState"] = "IDLE"
894 content = self.update_operation_history(
895 content, workflow_status, resource_status
896 )
897 self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content)
898
899 return
900
garciadeblas96b94f52024-07-08 16:18:21 +0200901 async def delete(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000902 self.logger.info("Infra controller delete Enter")
rshri932105f2024-07-05 15:11:55 +0000903
garciadeblas96b94f52024-07-08 16:18:21 +0200904 workflow_name = await self.odu.launch_workflow(
905 "delete_profile", op_id, op_params, content
906 )
rshri932105f2024-07-05 15:11:55 +0000907 self.logger.info("workflow_name is :{}".format(workflow_name))
908
garciadeblas96b94f52024-07-08 16:18:21 +0200909 workflow_status, workflow_msg = await self.odu.check_workflow_status(
910 workflow_name
911 )
rshri932105f2024-07-05 15:11:55 +0000912 self.logger.info(
913 "workflow_status is :{} and workflow_msg is :{}".format(
914 workflow_status, workflow_msg
915 )
916 )
917 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200918 content["state"] = "DELETED"
919 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +0000920 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200921 content["state"] = "FAILED_DELETION"
922 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000923 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +0200924 content = self.update_operation_history(content, workflow_status, None)
925 self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +0000926
927 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200928 resource_status, resource_msg = await self.odu.check_resource_status(
929 "delete_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000930 )
931 self.logger.info(
932 "resource_status is :{} and resource_msg is :{}".format(
933 resource_status, resource_msg
934 )
935 )
936 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200937 content["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +0000938 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200939 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000940
garciadeblas96b94f52024-07-08 16:18:21 +0200941 content["operatingState"] = "IDLE"
942 content = self.update_operation_history(
943 content, workflow_status, resource_status
944 )
945 self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +0000946
garciadeblas96b94f52024-07-08 16:18:21 +0200947 # To delete it from DB
948 if content["state"] == "DELETED":
rshri932105f2024-07-05 15:11:55 +0000949 self.db.del_one("k8sinfra_controller", {"_id": content["_id"]})
950 return
951
952
953class K8sInfraConfigLcm(LcmBase):
954 def __init__(self, msg, lcm_tasks, config):
955 """
956 Init, Connect to database, filesystem storage, and messaging
957 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
958 :return: None
959 """
960
garciadeblas4623e982024-09-11 14:28:38 +0200961 self.logger = logging.getLogger("lcm.gitops")
rshri932105f2024-07-05 15:11:55 +0000962 self.lcm_tasks = lcm_tasks
963 self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config)
964
965 super().__init__(msg, self.logger)
966
garciadeblas96b94f52024-07-08 16:18:21 +0200967 async def create(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000968 self.logger.info("Infra config Create Enter")
969
garciadeblas96b94f52024-07-08 16:18:21 +0200970 workflow_name = await self.odu.launch_workflow(
971 "create_profile", op_id, op_params, content
972 )
rshri932105f2024-07-05 15:11:55 +0000973 self.logger.info("workflow_name is :{}".format(workflow_name))
974
garciadeblas96b94f52024-07-08 16:18:21 +0200975 workflow_status, workflow_msg = await self.odu.check_workflow_status(
976 workflow_name
977 )
rshri932105f2024-07-05 15:11:55 +0000978 self.logger.info(
979 "workflow_status is :{} and workflow_msg is :{}".format(
980 workflow_status, workflow_msg
981 )
982 )
983 if workflow_status:
984 content["state"] = "CREATED"
985 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
986 else:
987 content["state"] = "FAILED_CREATION"
988 content["resourceState"] = "ERROR"
989 # has to call update_operation_history return content
990 content = self.update_operation_history(content, workflow_status, None)
991 self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content)
992
993 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200994 resource_status, resource_msg = await self.odu.check_resource_status(
995 "create_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000996 )
997 self.logger.info(
998 "resource_status is :{} and resource_msg is :{}".format(
999 resource_status, resource_msg
1000 )
1001 )
1002 if resource_status:
1003 content["resourceState"] = "READY"
1004 else:
1005 content["resourceState"] = "ERROR"
1006
1007 content["operatingState"] = "IDLE"
1008 content = self.update_operation_history(
1009 content, workflow_status, resource_status
1010 )
1011 self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content)
1012
1013 return
1014
garciadeblas96b94f52024-07-08 16:18:21 +02001015 async def delete(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +00001016 self.logger.info("Infra config delete Enter")
1017
garciadeblas96b94f52024-07-08 16:18:21 +02001018 workflow_name = await self.odu.launch_workflow(
1019 "delete_profile", op_id, op_params, content
1020 )
rshri932105f2024-07-05 15:11:55 +00001021 self.logger.info("workflow_name is :{}".format(workflow_name))
rshri932105f2024-07-05 15:11:55 +00001022
garciadeblas96b94f52024-07-08 16:18:21 +02001023 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1024 workflow_name
1025 )
rshri932105f2024-07-05 15:11:55 +00001026 self.logger.info(
1027 "workflow_status is :{} and workflow_msg is :{}".format(
1028 workflow_status, workflow_msg
1029 )
1030 )
1031 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001032 content["state"] = "DELETED"
1033 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +00001034 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001035 content["state"] = "FAILED_DELETION"
1036 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +00001037 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +02001038 content = self.update_operation_history(content, workflow_status, None)
1039 self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +00001040
garciadeblas96b94f52024-07-08 16:18:21 +02001041 resource_status, resource_msg = await self.odu.check_resource_status(
1042 "delete_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:
garciadeblas96b94f52024-07-08 16:18:21 +02001050 content["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +00001051 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001052 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +00001053
garciadeblas96b94f52024-07-08 16:18:21 +02001054 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)
rshri932105f2024-07-05 15:11:55 +00001059
garciadeblas96b94f52024-07-08 16:18:21 +02001060 # To delete it from DB
1061 if content["state"] == "DELETED":
rshri932105f2024-07-05 15:11:55 +00001062 self.db.del_one("k8sinfra_config", {"_id": content["_id"]})
1063 return
yshah771dea82024-07-05 15:11:49 +00001064
1065
1066class OkaLcm(LcmBase):
1067 db_collection = "okas"
1068
1069 def __init__(self, msg, lcm_tasks, config):
1070 """
1071 Init, Connect to database, filesystem storage, and messaging
1072 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
1073 :return: None
1074 """
1075
garciadeblas4623e982024-09-11 14:28:38 +02001076 self.logger = logging.getLogger("lcm.gitops")
yshah771dea82024-07-05 15:11:49 +00001077 self.lcm_tasks = lcm_tasks
1078 self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config)
1079
1080 super().__init__(msg, self.logger)
1081
garciadeblas96b94f52024-07-08 16:18:21 +02001082 async def create(self, op_id, op_params, content):
1083 self.logger.info("OKA Create Enter")
1084 db_content = content
yshah771dea82024-07-05 15:11:49 +00001085
garciadeblas96b94f52024-07-08 16:18:21 +02001086 workflow_name = await self.odu.launch_workflow(
1087 "create_oka", op_id, op_params, db_content
1088 )
1089 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1090 workflow_name
1091 )
1092 self.logger.info(
1093 "Workflow Status: {} Workflow Message: {}".format(
1094 workflow_status, workflow_msg
1095 )
1096 )
yshah771dea82024-07-05 15:11:49 +00001097
1098 if workflow_status:
1099 db_content["state"] = "CREATED"
1100 db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1101 else:
1102 db_content["state"] = "FAILED_CREATION"
1103 db_content["resourceState"] = "ERROR"
1104
1105 db_content = self.update_operation_history(db_content, workflow_status, None)
garciadeblas96b94f52024-07-08 16:18:21 +02001106 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001107
1108 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001109 resource_status, resource_msg = await self.odu.check_resource_status(
1110 "create_oka", op_id, op_params, db_content
yshah771dea82024-07-05 15:11:49 +00001111 )
garciadeblas96b94f52024-07-08 16:18:21 +02001112 self.logger.info(
1113 "Resource Status: {} Resource Message: {}".format(
1114 resource_status, resource_msg
1115 )
1116 )
yshah771dea82024-07-05 15:11:49 +00001117
1118 if resource_status:
1119 db_content["resourceState"] = "READY"
1120 else:
1121 db_content["resourceState"] = "ERROR"
1122
1123 # self.logger.info("Db content: {}".format(db_content))
1124 db_content = self.update_operation_history(
1125 db_content, workflow_status, resource_status
1126 )
1127
1128 db_content["operatingState"] = "IDLE"
garciadeblas96b94f52024-07-08 16:18:21 +02001129 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001130
1131 return
1132
garciadeblas96b94f52024-07-08 16:18:21 +02001133 async def edit(self, op_id, op_params, content):
1134 self.logger.info("OKA Edit Enter")
1135 db_content = content
yshah771dea82024-07-05 15:11:49 +00001136
garciadeblas96b94f52024-07-08 16:18:21 +02001137 workflow_name = await self.odu.launch_workflow(
1138 "update_oka", op_id, op_params, content
1139 )
1140 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1141 workflow_name
1142 )
1143 self.logger.info(
1144 "Workflow Status: {} Workflow Message: {}".format(
1145 workflow_status, workflow_msg
1146 )
1147 )
yshah771dea82024-07-05 15:11:49 +00001148
1149 if workflow_status:
1150 db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1151 else:
1152 db_content["resourceState"] = "ERROR"
1153
1154 db_content = self.update_operation_history(db_content, workflow_status, None)
1155 # self.logger.info("Db content: {}".format(db_content))
garciadeblas96b94f52024-07-08 16:18:21 +02001156 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001157
1158 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001159 resource_status, resource_msg = await self.odu.check_resource_status(
1160 "update_oka", op_id, op_params, db_content
yshah771dea82024-07-05 15:11:49 +00001161 )
garciadeblas96b94f52024-07-08 16:18:21 +02001162 self.logger.info(
1163 "Resource Status: {} Resource Message: {}".format(
1164 resource_status, resource_msg
1165 )
1166 )
yshah771dea82024-07-05 15:11:49 +00001167
1168 if resource_status:
1169 db_content["resourceState"] = "READY"
1170 else:
1171 db_content["resourceState"] = "ERROR"
1172
1173 db_content = self.update_operation_history(
1174 db_content, workflow_status, resource_status
1175 )
1176
1177 db_content["operatingState"] = "IDLE"
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 return
1180
garciadeblas96b94f52024-07-08 16:18:21 +02001181 async def delete(self, op_id, op_params, content):
1182 self.logger.info("OKA delete Enter")
1183 db_content = content
yshah771dea82024-07-05 15:11:49 +00001184
garciadeblas96b94f52024-07-08 16:18:21 +02001185 workflow_name = await self.odu.launch_workflow(
1186 "delete_oka", op_id, op_params, content
1187 )
1188 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1189 workflow_name
1190 )
1191 self.logger.info(
1192 "Workflow Status: {} Workflow Message: {}".format(
1193 workflow_status, workflow_msg
1194 )
1195 )
yshah771dea82024-07-05 15:11:49 +00001196
1197 if workflow_status:
1198 db_content["state"] = "DELETED"
1199 db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1200 else:
1201 db_content["state"] = "FAILED_DELETION"
1202 db_content["resourceState"] = "ERROR"
1203
1204 db_content = self.update_operation_history(db_content, workflow_status, None)
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 "delete_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
1229 if db_content["state"] == "DELETED":
garciadeblas96b94f52024-07-08 16:18:21 +02001230 self.db.del_one(self.db_collection, {"_id": db_content["_id"]})
yshah771dea82024-07-05 15:11:49 +00001231 return
1232
1233
1234class KsuLcm(LcmBase):
1235 db_collection = "ksus"
1236
1237 def __init__(self, msg, lcm_tasks, config):
1238 """
1239 Init, Connect to database, filesystem storage, and messaging
1240 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
1241 :return: None
1242 """
1243
garciadeblas4623e982024-09-11 14:28:38 +02001244 self.logger = logging.getLogger("lcm.gitops")
yshah771dea82024-07-05 15:11:49 +00001245 self.lcm_tasks = lcm_tasks
1246 self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config)
1247
1248 super().__init__(msg, self.logger)
1249
garciadeblas96b94f52024-07-08 16:18:21 +02001250 async def create(self, op_id, op_params, content):
1251 self.logger.info("ksu Create Enter")
yshah771dea82024-07-05 15:11:49 +00001252
garciadeblas96b94f52024-07-08 16:18:21 +02001253 workflow_name = await self.odu.launch_workflow(
1254 "create_ksus", op_id, op_params, content
1255 )
1256 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1257 workflow_name
1258 )
1259 self.logger.info(
1260 "Workflow Status: {} Workflow Message: {}".format(
1261 workflow_status, workflow_msg
yshah771dea82024-07-05 15:11:49 +00001262 )
garciadeblas96b94f52024-07-08 16:18:21 +02001263 )
yshah771dea82024-07-05 15:11:49 +00001264
garciadeblas96b94f52024-07-08 16:18:21 +02001265 for db_ksu in content:
1266 if workflow_status:
1267 db_ksu["state"] = "CREATED"
1268 db_ksu["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
yshah771dea82024-07-05 15:11:49 +00001269 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001270 db_ksu["state"] = "FAILED_CREATION"
1271 db_ksu["resourceState"] = "ERROR"
yshah771dea82024-07-05 15:11:49 +00001272
garciadeblas96b94f52024-07-08 16:18:21 +02001273 db_ksu = self.update_operation_history(db_ksu, workflow_status, None)
1274 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
1275
1276 if workflow_status:
1277 resource_status, resource_msg = await self.odu.check_resource_status(
1278 "create_ksus", op_id, op_params, content
1279 )
1280 self.logger.info(
1281 "Resource Status: {} Resource Message: {}".format(
1282 resource_status, resource_msg
1283 )
yshah771dea82024-07-05 15:11:49 +00001284 )
1285
garciadeblas96b94f52024-07-08 16:18:21 +02001286 for db_ksu in content:
1287 if resource_status:
1288 db_ksu["resourceState"] = "READY"
1289 else:
1290 db_ksu["resourceState"] = "ERROR"
1291
1292 db_ksu = self.update_operation_history(
1293 db_ksu, workflow_status, resource_status
1294 )
1295
1296 for db_ksu in content:
1297 db_ksu["operatingState"] = "IDLE"
1298 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
yshah771dea82024-07-05 15:11:49 +00001299
1300 return
1301
garciadeblas96b94f52024-07-08 16:18:21 +02001302 async def edit(self, op_id, op_params, content):
1303 self.logger.info("ksu edit Enter")
yshah771dea82024-07-05 15:11:49 +00001304
garciadeblas96b94f52024-07-08 16:18:21 +02001305 workflow_name = await self.odu.launch_workflow(
1306 "update_ksus", op_id, op_params, content
1307 )
1308 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1309 workflow_name
1310 )
1311 self.logger.info(
1312 "Workflow Status: {} Workflow Message: {}".format(
1313 workflow_status, workflow_msg
yshah771dea82024-07-05 15:11:49 +00001314 )
garciadeblas96b94f52024-07-08 16:18:21 +02001315 )
yshah771dea82024-07-05 15:11:49 +00001316
garciadeblas96b94f52024-07-08 16:18:21 +02001317 for db_ksu in content:
1318 if workflow_status:
1319 db_ksu["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
yshah771dea82024-07-05 15:11:49 +00001320 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001321 db_ksu["resourceState"] = "ERROR"
yshah771dea82024-07-05 15:11:49 +00001322
garciadeblas96b94f52024-07-08 16:18:21 +02001323 db_ksu = self.update_operation_history(db_ksu, workflow_status, None)
1324 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
1325
1326 if workflow_status:
1327 resource_status, resource_msg = await self.odu.check_resource_status(
1328 "update_ksus", op_id, op_params, content
1329 )
1330 self.logger.info(
1331 "Resource Status: {} Resource Message: {}".format(
1332 resource_status, resource_msg
1333 )
yshah771dea82024-07-05 15:11:49 +00001334 )
1335
garciadeblas96b94f52024-07-08 16:18:21 +02001336 for db_ksu in content:
1337 if resource_status:
1338 db_ksu["resourceState"] = "READY"
1339 else:
1340 db_ksu["resourceState"] = "ERROR"
1341
1342 db_ksu = self.update_operation_history(
1343 db_ksu, workflow_status, resource_status
1344 )
1345
1346 for db_ksu, ksu_params in zip(content, op_params):
1347 db_ksu["operatingState"] = "IDLE"
1348 if workflow_status:
1349 db_ksu["name"] = ksu_params["name"]
1350 db_ksu["description"] = ksu_params["description"]
1351 db_ksu["profile"]["profile_type"] = ksu_params["profile"][
1352 "profile_type"
1353 ]
1354 db_ksu["profile"]["_id"] = ksu_params["profile"]["_id"]
1355 db_ksu["oka"] = ksu_params["oka"]
1356 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
1357
yshah771dea82024-07-05 15:11:49 +00001358 return
1359
garciadeblas96b94f52024-07-08 16:18:21 +02001360 async def delete(self, op_id, op_params, content):
1361 self.logger.info("ksu delete Enter")
yshah771dea82024-07-05 15:11:49 +00001362
garciadeblas96b94f52024-07-08 16:18:21 +02001363 workflow_name = await self.odu.launch_workflow(
1364 "delete_ksus", op_id, op_params, content
1365 )
1366 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1367 workflow_name
1368 )
1369 self.logger.info(
1370 "Workflow Status: {} Workflow Message: {}".format(
1371 workflow_status, workflow_msg
yshah771dea82024-07-05 15:11:49 +00001372 )
garciadeblas96b94f52024-07-08 16:18:21 +02001373 )
yshah771dea82024-07-05 15:11:49 +00001374
garciadeblas96b94f52024-07-08 16:18:21 +02001375 for db_ksu in content:
1376 if workflow_status:
1377 db_ksu["state"] = "DELETED"
1378 db_ksu["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
yshah771dea82024-07-05 15:11:49 +00001379 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001380 db_ksu["state"] = "FAILED_DELETION"
1381 db_ksu["resourceState"] = "ERROR"
yshah771dea82024-07-05 15:11:49 +00001382
garciadeblas96b94f52024-07-08 16:18:21 +02001383 db_ksu = self.update_operation_history(db_ksu, workflow_status, None)
1384 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
1385
1386 if workflow_status:
1387 resource_status, resource_msg = await self.odu.check_resource_status(
1388 "delete_ksus", op_id, op_params, content
1389 )
1390 self.logger.info(
1391 "Resource Status: {} Resource Message: {}".format(
1392 resource_status, resource_msg
1393 )
yshah771dea82024-07-05 15:11:49 +00001394 )
1395
garciadeblas96b94f52024-07-08 16:18:21 +02001396 for db_ksu in content:
1397 if resource_status:
1398 db_ksu["resourceState"] = "READY"
1399 else:
1400 db_ksu["resourceState"] = "ERROR"
yshah771dea82024-07-05 15:11:49 +00001401
garciadeblas96b94f52024-07-08 16:18:21 +02001402 db_ksu = self.update_operation_history(
1403 db_ksu, workflow_status, resource_status
1404 )
1405
1406 for db_ksu in content:
1407 db_ksu["operatingState"] = "IDLE"
1408 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
1409
1410 if db_ksu["state"] == "DELETED":
1411 self.db.del_one(self.db_collection, {"_id": db_ksu["_id"]})
yshah771dea82024-07-05 15:11:49 +00001412 return
1413
garciadeblas96b94f52024-07-08 16:18:21 +02001414 async def clone(self, op_id, op_params, db_content):
1415 self.logger.info("ksu clone Enter")
yshah771dea82024-07-05 15:11:49 +00001416
garciadeblas96b94f52024-07-08 16:18:21 +02001417 workflow_name = await self.odu.launch_workflow(
1418 "clone_ksus", op_id, op_params, db_content
1419 )
1420 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1421 workflow_name
1422 )
1423 self.logger.info(
1424 "Workflow Status: {} Workflow Message: {}".format(
1425 workflow_status, workflow_msg
1426 )
1427 )
yshah771dea82024-07-05 15:11:49 +00001428
1429 if workflow_status:
1430 db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1431 else:
1432 db_content["resourceState"] = "ERROR"
1433
1434 db_content = self.update_operation_history(db_content, workflow_status, None)
garciadeblas96b94f52024-07-08 16:18:21 +02001435 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001436
1437 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001438 resource_status, resource_msg = await self.odu.check_resource_status(
1439 "clone_ksus", op_id, op_params, db_content
yshah771dea82024-07-05 15:11:49 +00001440 )
garciadeblas96b94f52024-07-08 16:18:21 +02001441 self.logger.info(
1442 "Resource Status: {} Resource Message: {}".format(
1443 resource_status, resource_msg
1444 )
1445 )
yshah771dea82024-07-05 15:11:49 +00001446
1447 if resource_status:
1448 db_content["resourceState"] = "READY"
1449 else:
1450 db_content["resourceState"] = "ERROR"
1451
1452 db_content = self.update_operation_history(
1453 db_content, workflow_status, resource_status
1454 )
1455
1456 db_content["operatingState"] = "IDLE"
garciadeblas96b94f52024-07-08 16:18:21 +02001457 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001458 return
1459
garciadeblas96b94f52024-07-08 16:18:21 +02001460 async def move(self, op_id, op_params, db_content):
1461 self.logger.info("ksu move Enter")
yshah771dea82024-07-05 15:11:49 +00001462
garciadeblas96b94f52024-07-08 16:18:21 +02001463 workflow_name = await self.odu.launch_workflow(
1464 "move_ksus", op_id, op_params, db_content
1465 )
1466 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1467 workflow_name
1468 )
1469 self.logger.info(
1470 "Workflow Status: {} Workflow Message: {}".format(
1471 workflow_status, workflow_msg
1472 )
1473 )
yshah771dea82024-07-05 15:11:49 +00001474
1475 if workflow_status:
1476 db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1477 else:
1478 db_content["resourceState"] = "ERROR"
1479
1480 db_content = self.update_operation_history(db_content, workflow_status, None)
garciadeblas96b94f52024-07-08 16:18:21 +02001481 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001482
1483 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001484 resource_status, resource_msg = await self.odu.check_resource_status(
1485 "move_ksus", op_id, op_params, db_content
yshah771dea82024-07-05 15:11:49 +00001486 )
garciadeblas96b94f52024-07-08 16:18:21 +02001487 self.logger.info(
1488 "Resource Status: {} Resource Message: {}".format(
1489 resource_status, resource_msg
1490 )
1491 )
yshah771dea82024-07-05 15:11:49 +00001492 if resource_status:
1493 db_content["resourceState"] = "READY"
1494 else:
1495 db_content["resourceState"] = "ERROR"
1496
1497 db_content = self.update_operation_history(
1498 db_content, workflow_status, resource_status
1499 )
1500
1501 db_content["operatingState"] = "IDLE"
garciadeblas96b94f52024-07-08 16:18:21 +02001502 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001503 return