blob: 6c55a52990d8ced0254c1d303230c2689c1c23f9 [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
rshrib0e6ac32024-11-12 18:12:38 +000021import copy
rshri932105f2024-07-05 15:11:55 +000022import logging
yshah07491142024-10-17 06:11:12 +000023from time import time
garciadeblas635b35a2024-11-07 12:41:54 +010024import traceback
rshri932105f2024-07-05 15:11:55 +000025from osm_lcm.lcm_utils import LcmBase
26from copy import deepcopy
27from osm_lcm import odu_workflows
28from osm_lcm import vim_sdn
29
30
garciadeblas635b35a2024-11-07 12:41:54 +010031class GitOpsLcm(LcmBase):
garciadeblas446ba3c2024-11-20 12:42:49 +010032 db_collection = "gitops"
33
garciadeblas635b35a2024-11-07 12:41:54 +010034 def __init__(self, msg, lcm_tasks, config):
35 self.logger = logging.getLogger("lcm.gitops")
36 self.lcm_tasks = lcm_tasks
37 self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config)
38 self._checkloop_kustomization_timeout = 900
39 self._checkloop_resource_timeout = 900
40 self._workflows = {}
41 super().__init__(msg, self.logger)
42
43 async def check_dummy_operation(self, op_id, op_params, content):
44 self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}")
45 return True, "OK"
46
garciadeblas446ba3c2024-11-20 12:42:49 +010047 def initialize_operation(self, item_id, op_id):
48 db_item = self.db.get_one(self.db_collection, {"_id": item_id})
49 operation = next(
50 (op for op in db_item.get("operationHistory", []) if op["op_id"] == op_id),
51 None,
52 )
53 operation["workflowState"] = "PROCESSING"
54 operation["resourceState"] = "NOT_READY"
55 operation["operationState"] = "IN_PROGRESS"
56 operation["gitOperationInfo"] = None
57 db_item["current_operation"] = operation["op_id"]
58 self.db.set_one(self.db_collection, {"_id": item_id}, db_item)
59
garciadeblas2084b282024-11-08 10:41:38 +010060 def update_operation_history(
61 self, content, workflow_status=None, resource_status=None
62 ):
63 self.logger.info(
64 f"Update Operation History in DB. Workflow status: {workflow_status}. Resource status: {resource_status}"
65 )
66 self.logger.debug(f"Content: {content}")
67
68 op_id = content["current_operation"]
69 self.logger.debug("OP_id: {}".format(op_id))
70 op_num = 0
71 for operation in content["operationHistory"]:
72 self.logger.debug("Operations: {}".format(operation))
73 if operation["op_id"] == op_id:
74 self.logger.debug("Found operation number: {}".format(op_num))
75 now = time()
76 if workflow_status:
77 content["operationHistory"][op_num]["workflowState"] = "COMPLETED"
78 content["operationHistory"][op_num]["result"] = True
79 else:
80 content["operationHistory"][op_num]["workflowState"] = "ERROR"
81 content["operationHistory"][op_num]["operationState"] = "FAILED"
82 content["operationHistory"][op_num]["result"] = False
83
84 if resource_status:
85 content["operationHistory"][op_num]["resourceState"] = "READY"
86 content["operationHistory"][op_num]["operationState"] = "COMPLETED"
87 content["operationHistory"][op_num]["result"] = True
88 else:
89 content["operationHistory"][op_num]["resourceState"] = "NOT_READY"
90 content["operationHistory"][op_num]["operationState"] = "FAILED"
91 content["operationHistory"][op_num]["result"] = False
92
93 content["operationHistory"][op_num]["endDate"] = now
94 break
95 op_num += 1
96 self.logger.debug("content: {}".format(content))
97
98 return content
99
100 async def common_check_list(self, checkings_list, db_collection, db_item):
garciadeblas635b35a2024-11-07 12:41:54 +0100101 try:
102 for checking in checkings_list:
103 if checking["enable"]:
104 status, message = await self.odu.readiness_loop(
105 item=checking["item"],
106 name=checking["name"],
107 namespace=checking["namespace"],
108 flag=checking["flag"],
109 timeout=checking["timeout"],
110 )
111 if not status:
112 return status, message
garciadeblas2084b282024-11-08 10:41:38 +0100113 else:
114 db_item["resourceState"] = checking["resourceState"]
115 db_item = self.update_operation_history(
116 db_item, "COMPLETED", checking["resourceState"]
117 )
118 self.db.set_one(db_collection, {"_id": db_item["_id"]}, db_item)
garciadeblas635b35a2024-11-07 12:41:54 +0100119 except Exception as e:
120 self.logger.debug(traceback.format_exc())
121 self.logger.debug(f"Exception: {e}", exc_info=True)
122 return False, f"Unexpected exception: {e}"
123 return True, "OK"
124
125 async def check_resource_status(self, key, op_id, op_params, content):
126 self.logger.info(
127 f"Check resource status. Key: {key}. Operation: {op_id}. Params: {op_params}. Content: {content}"
128 )
129 check_resource_function = self._workflows.get(key, {}).get(
130 "check_resource_function"
131 )
132 self.logger.info("check_resource function : {}".format(check_resource_function))
133 if check_resource_function:
134 return await check_resource_function(op_id, op_params, content)
135 else:
136 return await self.check_dummy_operation(op_id, op_params, content)
137
rshrib0e6ac32024-11-12 18:12:38 +0000138 def decrypting_key(self, content):
139 # This deep copy is for to be passed to ODU workflows.
140 cluster_copy = copy.deepcopy(content)
141
142 # decrypting the key
143 self.db.encrypt_decrypt_fields(
144 cluster_copy,
145 "decrypt",
146 ["age_pubkey", "age_privkey"],
147 schema_version="1.11",
148 salt=cluster_copy["_id"],
149 )
150 db_cluster_copy = {
151 "cluster": cluster_copy,
152 }
153 return db_cluster_copy
154
garciadeblas635b35a2024-11-07 12:41:54 +0100155
156class ClusterLcm(GitOpsLcm):
garciadeblas96b94f52024-07-08 16:18:21 +0200157 db_collection = "clusters"
rshri932105f2024-07-05 15:11:55 +0000158
159 def __init__(self, msg, lcm_tasks, config):
160 """
161 Init, Connect to database, filesystem storage, and messaging
162 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
163 :return: None
164 """
garciadeblas635b35a2024-11-07 12:41:54 +0100165 super().__init__(msg, lcm_tasks, config)
166 self._workflows = {
167 "create_cluster": {
168 "check_resource_function": self.check_create_cluster,
169 },
garciadeblasb5b086e2024-11-13 16:00:10 +0100170 "register_cluster": {
171 "check_resource_function": self.check_register_cluster,
172 },
173 "update_cluster": {
174 "check_resource_function": self.check_update_cluster,
175 },
garciadeblas635b35a2024-11-07 12:41:54 +0100176 }
rshri932105f2024-07-05 15:11:55 +0000177 self.regist = vim_sdn.K8sClusterLcm(msg, self.lcm_tasks, config)
178
garciadeblas96b94f52024-07-08 16:18:21 +0200179 async def create(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000180 self.logger.info("cluster Create Enter")
garciadeblas96b94f52024-07-08 16:18:21 +0200181 db_cluster = content["cluster"]
rshri932105f2024-07-05 15:11:55 +0000182
rshrib0e6ac32024-11-12 18:12:38 +0000183 db_cluster_copy = self.decrypting_key(db_cluster)
184
185 # vim account details
186 db_vim = self.db.get_one("vim_accounts", {"name": db_cluster["vim_account"]})
187 db_cluster_copy["vim_account"] = db_vim
188
garciadeblas869131a2024-11-08 01:11:46 +0100189 _, workflow_name = await self.odu.launch_workflow(
rshrib0e6ac32024-11-12 18:12:38 +0000190 "create_cluster", op_id, op_params, db_cluster_copy
garciadeblas96b94f52024-07-08 16:18:21 +0200191 )
rshri932105f2024-07-05 15:11:55 +0000192 self.logger.info("workflow_name is :{}".format(workflow_name))
193
garciadeblas96b94f52024-07-08 16:18:21 +0200194 workflow_status, workflow_msg = await self.odu.check_workflow_status(
195 workflow_name
196 )
rshri932105f2024-07-05 15:11:55 +0000197 self.logger.info(
198 "workflow_status is :{} and workflow_msg is :{}".format(
199 workflow_status, workflow_msg
200 )
201 )
202 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200203 db_cluster["state"] = "CREATED"
204 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +0000205 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200206 db_cluster["state"] = "FAILED_CREATION"
207 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000208 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +0200209 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
210 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
rshri932105f2024-07-05 15:11:55 +0000211
garciadeblas4d26e292024-09-16 12:53:07 +0200212 # Clean items used in the workflow, no matter if the workflow succeeded
213 clean_status, clean_msg = await self.odu.clean_items_workflow(
rshrib0e6ac32024-11-12 18:12:38 +0000214 "create_cluster", op_id, op_params, db_cluster_copy
garciadeblas4d26e292024-09-16 12:53:07 +0200215 )
216 self.logger.info(
217 f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
218 )
219
rshri932105f2024-07-05 15:11:55 +0000220 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +0100221 resource_status, resource_msg = await self.check_resource_status(
rshrib0e6ac32024-11-12 18:12:38 +0000222 "create_cluster", op_id, op_params, db_cluster_copy
rshri932105f2024-07-05 15:11:55 +0000223 )
224 self.logger.info(
225 "resource_status is :{} and resource_msg is :{}".format(
226 resource_status, resource_msg
227 )
228 )
229 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200230 db_cluster["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +0000231 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200232 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000233
garciadeblas96b94f52024-07-08 16:18:21 +0200234 db_cluster["operatingState"] = "IDLE"
235 db_cluster = self.update_operation_history(
236 db_cluster, workflow_status, resource_status
rshri932105f2024-07-05 15:11:55 +0000237 )
garciadeblas96b94f52024-07-08 16:18:21 +0200238 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
239 self.update_profile_state(db_cluster, workflow_status, resource_status)
rshri932105f2024-07-05 15:11:55 +0000240 return
241
garciadeblas635b35a2024-11-07 12:41:54 +0100242 async def check_create_cluster(self, op_id, op_params, content):
garciadeblas2084b282024-11-08 10:41:38 +0100243 self.logger.info(
244 f"check_create_cluster Operation {op_id}. Params: {op_params}."
245 )
246 # self.logger.debug(f"Content: {content}")
garciadeblas635b35a2024-11-07 12:41:54 +0100247 db_cluster = content["cluster"]
248 cluster_name = db_cluster["git_name"].lower()
249 cluster_kustomization_name = cluster_name
250 db_vim_account = content["vim_account"]
251 cloud_type = db_vim_account["vim_type"]
252 nodepool_name = ""
253 if cloud_type == "aws":
254 nodepool_name = f"{cluster_name}-nodegroup"
255 cluster_name = f"{cluster_name}-cluster"
256 elif cloud_type == "gcp":
257 nodepool_name = f"nodepool-{cluster_name}"
258 bootstrap = op_params.get("bootstrap", True)
259 if cloud_type in ("azure", "gcp", "aws"):
260 checkings_list = [
261 {
262 "item": "kustomization",
263 "name": cluster_kustomization_name,
264 "namespace": "managed-resources",
265 "flag": "Ready",
266 "timeout": self._checkloop_kustomization_timeout,
267 "enable": True,
garciadeblas2084b282024-11-08 10:41:38 +0100268 "resourceState": "IN_PROGRESS.KUSTOMIZATION_READY",
garciadeblas635b35a2024-11-07 12:41:54 +0100269 },
270 {
271 "item": f"cluster_{cloud_type}",
272 "name": cluster_name,
273 "namespace": "",
274 "flag": "Synced",
275 "timeout": self._checkloop_resource_timeout,
276 "enable": True,
garciadeblas2084b282024-11-08 10:41:38 +0100277 "resourceState": "IN_PROGRESS.RESOURCE_SYNCED.CLUSTER",
garciadeblas635b35a2024-11-07 12:41:54 +0100278 },
279 {
280 "item": f"cluster_{cloud_type}",
281 "name": cluster_name,
282 "namespace": "",
283 "flag": "Ready",
284 "timeout": self._checkloop_resource_timeout,
285 "enable": True,
garciadeblas2084b282024-11-08 10:41:38 +0100286 "resourceState": "IN_PROGRESS.RESOURCE_READY.CLUSTER",
garciadeblas635b35a2024-11-07 12:41:54 +0100287 },
288 {
289 "item": "kustomization",
290 "name": f"{cluster_kustomization_name}-bstrp-fluxctrl",
291 "namespace": "managed-resources",
292 "flag": "Ready",
293 "timeout": self._checkloop_kustomization_timeout,
294 "enable": bootstrap,
garciadeblas2084b282024-11-08 10:41:38 +0100295 "resourceState": "IN_PROGRESS.BOOTSTRAP_OK",
garciadeblas635b35a2024-11-07 12:41:54 +0100296 },
297 ]
298 else:
299 return False, "Not suitable VIM account to check cluster status"
300 if nodepool_name:
301 nodepool_check = {
302 "item": f"nodepool_{cloud_type}",
303 "name": nodepool_name,
304 "namespace": "",
305 "flag": "Ready",
306 "timeout": self._checkloop_resource_timeout,
307 "enable": True,
garciadeblas2084b282024-11-08 10:41:38 +0100308 "resourceState": "IN_PROGRESS.RESOURCE_READY.NODEPOOL",
garciadeblas635b35a2024-11-07 12:41:54 +0100309 }
310 checkings_list.insert(3, nodepool_check)
garciadeblas2084b282024-11-08 10:41:38 +0100311 return await self.common_check_list(checkings_list, "clusters", db_cluster)
garciadeblas635b35a2024-11-07 12:41:54 +0100312
garciadeblasb5b086e2024-11-13 16:00:10 +0100313 async def check_register_cluster(self, op_id, op_params, content):
314 self.logger.info(
315 f"check_register_cluster Operation {op_id}. Params: {op_params}."
316 )
317 # self.logger.debug(f"Content: {content}")
318 db_cluster = content["cluster"]
319 cluster_name = db_cluster["git_name"].lower()
320 cluster_kustomization_name = cluster_name
321 bootstrap = op_params.get("bootstrap", True)
322 checkings_list = [
323 {
324 "item": "kustomization",
325 "name": f"{cluster_kustomization_name}-bstrp-fluxctrl",
326 "namespace": "managed-resources",
327 "flag": "Ready",
328 "timeout": self._checkloop_kustomization_timeout,
329 "enable": bootstrap,
330 "resourceState": "IN_PROGRESS.BOOTSTRAP_OK",
331 },
332 ]
333 return await self.common_check_list(checkings_list, "clusters", db_cluster)
334
335 async def check_update_cluster(self, op_id, op_params, content):
336 self.logger.info(
337 f"check_create_cluster Operation {op_id}. Params: {op_params}."
338 )
339 # self.logger.debug(f"Content: {content}")
340 db_cluster = content["cluster"]
341 cluster_name = db_cluster["git_name"].lower()
342 cluster_kustomization_name = cluster_name
343 db_vim_account = content["vim_account"]
344 cloud_type = db_vim_account["vim_type"]
345 nodepool_name = ""
346 if cloud_type == "aws":
347 nodepool_name = f"{cluster_name}-nodegroup"
348 cluster_name = f"{cluster_name}-cluster"
349 elif cloud_type == "gcp":
350 nodepool_name = f"nodepool-{cluster_name}"
351 if cloud_type in ("azure", "gcp", "aws"):
352 checkings_list = [
353 {
354 "item": "kustomization",
355 "name": cluster_kustomization_name,
356 "namespace": "managed-resources",
357 "flag": "Ready",
358 "timeout": self._checkloop_kustomization_timeout,
359 "enable": True,
360 "resourceState": "IN_PROGRESS.KUSTOMIZATION_READY",
361 },
362 {
363 "item": f"cluster_{cloud_type}",
364 "name": cluster_name,
365 "namespace": "",
366 "flag": "Synced",
367 "timeout": self._checkloop_resource_timeout,
368 "enable": True,
369 "resourceState": "IN_PROGRESS.RESOURCE_SYNCED.CLUSTER",
370 },
371 {
372 "item": f"cluster_{cloud_type}",
373 "name": cluster_name,
374 "namespace": "",
375 "flag": "Ready",
376 "timeout": self._checkloop_resource_timeout,
377 "enable": True,
378 "resourceState": "IN_PROGRESS.RESOURCE_READY.CLUSTER",
379 },
380 ]
381 else:
382 return False, "Not suitable VIM account to check cluster status"
383 if nodepool_name:
384 nodepool_check = {
385 "item": f"nodepool_{cloud_type}",
386 "name": nodepool_name,
387 "namespace": "",
388 "flag": "Ready",
389 "timeout": self._checkloop_resource_timeout,
390 "enable": True,
391 "resourceState": "IN_PROGRESS.RESOURCE_READY.NODEPOOL",
392 }
393 checkings_list.append(nodepool_check)
394 return await self.common_check_list(checkings_list, "clusters", db_cluster)
395
garciadeblas96b94f52024-07-08 16:18:21 +0200396 def update_profile_state(self, db_cluster, workflow_status, resource_status):
rshri932105f2024-07-05 15:11:55 +0000397 profiles = [
398 "infra_controller_profiles",
399 "infra_config_profiles",
400 "app_profiles",
401 "resource_profiles",
402 ]
403 profiles_collection = {
404 "infra_controller_profiles": "k8sinfra_controller",
405 "infra_config_profiles": "k8sinfra_config",
406 "app_profiles": "k8sapp",
407 "resource_profiles": "k8sresource",
408 }
409 for profile_type in profiles:
garciadeblas96b94f52024-07-08 16:18:21 +0200410 profile_id = db_cluster[profile_type]
rshri932105f2024-07-05 15:11:55 +0000411 self.logger.info("profile id is : {}".format(profile_id))
412 db_collection = profiles_collection[profile_type]
413 self.logger.info("the db_collection is :{}".format(db_collection))
414 db_profile = self.db.get_one(db_collection, {"_id": profile_id})
415 self.logger.info("the db_profile is :{}".format(db_profile))
garciadeblas96b94f52024-07-08 16:18:21 +0200416 db_profile["state"] = db_cluster["state"]
417 db_profile["resourceState"] = db_cluster["resourceState"]
418 db_profile["operatingState"] = db_cluster["operatingState"]
rshrib0e6ac32024-11-12 18:12:38 +0000419 db_profile["age_pubkey"] = db_cluster["age_pubkey"]
420 db_profile["age_privkey"] = db_profile["age_privkey"]
rshri932105f2024-07-05 15:11:55 +0000421 db_profile = self.update_operation_history(
422 db_profile, workflow_status, resource_status
423 )
424 self.logger.info("the db_profile is :{}".format(db_profile))
425 self.db.set_one(db_collection, {"_id": db_profile["_id"]}, db_profile)
426
garciadeblas96b94f52024-07-08 16:18:21 +0200427 async def delete(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000428 self.logger.info("cluster delete Enter")
garciadeblas96b94f52024-07-08 16:18:21 +0200429 db_cluster = content["cluster"]
garciadeblas968d6d02024-11-18 10:33:12 +0100430 if db_cluster["created"] == "false":
431 return await self.deregister(op_id, op_params, content)
rshri932105f2024-07-05 15:11:55 +0000432
garciadeblas869131a2024-11-08 01:11:46 +0100433 _, workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +0200434 "delete_cluster", op_id, op_params, content
435 )
rshri932105f2024-07-05 15:11:55 +0000436 self.logger.info("workflow_name is :{}".format(workflow_name))
437
garciadeblas96b94f52024-07-08 16:18:21 +0200438 workflow_status, workflow_msg = await self.odu.check_workflow_status(
439 workflow_name
440 )
rshri932105f2024-07-05 15:11:55 +0000441 self.logger.info(
442 "workflow_status is :{} and workflow_msg is :{}".format(
443 workflow_status, workflow_msg
444 )
445 )
446 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200447 db_cluster["state"] = "DELETED"
448 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +0000449 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200450 db_cluster["state"] = "FAILED_DELETION"
451 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000452 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +0200453 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
454 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
rshri932105f2024-07-05 15:11:55 +0000455
456 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +0100457 resource_status, resource_msg = await self.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +0200458 "delete_cluster", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000459 )
460 self.logger.info(
461 "resource_status is :{} and resource_msg is :{}".format(
462 resource_status, resource_msg
463 )
464 )
465 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200466 db_cluster["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +0000467 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200468 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000469
garciadeblas96b94f52024-07-08 16:18:21 +0200470 db_cluster["operatingState"] = "IDLE"
471 db_cluster = self.update_operation_history(
472 db_cluster, workflow_status, resource_status
473 )
474 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
rshri932105f2024-07-05 15:11:55 +0000475
garciadeblas96b94f52024-07-08 16:18:21 +0200476 # To delete it from DB
477 if db_cluster["state"] == "DELETED":
478 self.delete_cluster(db_cluster)
rshri932105f2024-07-05 15:11:55 +0000479 return
480
garciadeblas96b94f52024-07-08 16:18:21 +0200481 def delete_cluster(self, db_cluster):
482 # Actually, item_content is equal to db_cluster
483 # item_content = self.db.get_one("clusters", {"_id": db_cluster["_id"]})
484 # self.logger.debug("item_content is : {}".format(item_content))
rshri932105f2024-07-05 15:11:55 +0000485
rshri932105f2024-07-05 15:11:55 +0000486 # detach profiles
487 update_dict = None
488 profiles_to_detach = [
489 "infra_controller_profiles",
490 "infra_config_profiles",
491 "app_profiles",
492 "resource_profiles",
493 ]
494 profiles_collection = {
495 "infra_controller_profiles": "k8sinfra_controller",
496 "infra_config_profiles": "k8sinfra_config",
497 "app_profiles": "k8sapp",
498 "resource_profiles": "k8sresource",
499 }
500 for profile_type in profiles_to_detach:
garciadeblas96b94f52024-07-08 16:18:21 +0200501 if db_cluster.get(profile_type):
garciadeblas5a1d6c12024-10-22 12:39:32 +0200502 self.logger.debug("the profile_type is :{}".format(profile_type))
garciadeblas96b94f52024-07-08 16:18:21 +0200503 profile_ids = db_cluster[profile_type]
garciadeblas5a1d6c12024-10-22 12:39:32 +0200504 self.logger.debug("the profile_ids is :{}".format(profile_ids))
rshri932105f2024-07-05 15:11:55 +0000505 profile_ids_copy = deepcopy(profile_ids)
garciadeblas5a1d6c12024-10-22 12:39:32 +0200506 self.logger.debug(
507 "the profile_ids_copy is :{}".format(profile_ids_copy)
508 )
rshri932105f2024-07-05 15:11:55 +0000509 for profile_id in profile_ids_copy:
garciadeblas5a1d6c12024-10-22 12:39:32 +0200510 self.logger.debug("the profile_id is :{}".format(profile_id))
rshri932105f2024-07-05 15:11:55 +0000511 db_collection = profiles_collection[profile_type]
garciadeblas5a1d6c12024-10-22 12:39:32 +0200512 self.logger.debug("the db_collection is :{}".format(db_collection))
rshri932105f2024-07-05 15:11:55 +0000513 db_profile = self.db.get_one(db_collection, {"_id": profile_id})
garciadeblas5a1d6c12024-10-22 12:39:32 +0200514 self.logger.debug("the db_profile is :{}".format(db_profile))
515 self.logger.debug(
garciadeblas96b94f52024-07-08 16:18:21 +0200516 "the item_content name is :{}".format(db_cluster["name"])
rshri932105f2024-07-05 15:11:55 +0000517 )
garciadeblas5a1d6c12024-10-22 12:39:32 +0200518 self.logger.debug(
rshri932105f2024-07-05 15:11:55 +0000519 "the db_profile name is :{}".format(db_profile["name"])
520 )
garciadeblas96b94f52024-07-08 16:18:21 +0200521 if db_cluster["name"] == db_profile["name"]:
garciadeblas5a1d6c12024-10-22 12:39:32 +0200522 self.logger.debug("it is getting into if default")
rshri932105f2024-07-05 15:11:55 +0000523 self.db.del_one(db_collection, {"_id": profile_id})
524 else:
garciadeblas5a1d6c12024-10-22 12:39:32 +0200525 self.logger.debug("it is getting into else non default")
rshri932105f2024-07-05 15:11:55 +0000526 profile_ids.remove(profile_id)
527 update_dict = {profile_type: profile_ids}
garciadeblas5a1d6c12024-10-22 12:39:32 +0200528 self.logger.debug(f"the update dict is :{update_dict}")
rshri932105f2024-07-05 15:11:55 +0000529 self.db.set_one(
garciadeblas96b94f52024-07-08 16:18:21 +0200530 "clusters", {"_id": db_cluster["_id"]}, update_dict
rshri932105f2024-07-05 15:11:55 +0000531 )
garciadeblas96b94f52024-07-08 16:18:21 +0200532 self.db.del_one("clusters", {"_id": db_cluster["_id"]})
garciadeblas5a1d6c12024-10-22 12:39:32 +0200533 self.logger.debug("the id is :{}".format(db_cluster["_id"]))
rshri932105f2024-07-05 15:11:55 +0000534
garciadeblas96b94f52024-07-08 16:18:21 +0200535 async def attach_profile(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000536 self.logger.info("profile attach Enter")
garciadeblas96b94f52024-07-08 16:18:21 +0200537 db_cluster = content["cluster"]
538 db_profile = content["profile"]
539 profile_type = db_profile["profile_type"]
540 profile_id = db_profile["_id"]
rshri932105f2024-07-05 15:11:55 +0000541 self.logger.info("profile type is : {}".format(profile_type))
rshri932105f2024-07-05 15:11:55 +0000542 self.logger.info("profile id is : {}".format(profile_id))
543
garciadeblas869131a2024-11-08 01:11:46 +0100544 _, workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +0200545 "attach_profile_to_cluster", op_id, op_params, content
546 )
rshri932105f2024-07-05 15:11:55 +0000547 self.logger.info("workflow_name is :{}".format(workflow_name))
548
garciadeblas96b94f52024-07-08 16:18:21 +0200549 workflow_status, workflow_msg = await self.odu.check_workflow_status(
550 workflow_name
551 )
rshri932105f2024-07-05 15:11:55 +0000552 self.logger.info(
553 "workflow_status is :{} and workflow_msg is :{}".format(
554 workflow_status, workflow_msg
555 )
556 )
557 if workflow_status:
558 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
559 else:
560 db_cluster["resourceState"] = "ERROR"
561 # has to call update_operation_history return content
562 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
563 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
564
565 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +0100566 resource_status, resource_msg = await self.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +0200567 "attach_profile_to_cluster", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000568 )
569 self.logger.info(
570 "resource_status is :{} and resource_msg is :{}".format(
571 resource_status, resource_msg
572 )
573 )
574 if resource_status:
575 db_cluster["resourceState"] = "READY"
576 else:
577 db_cluster["resourceState"] = "ERROR"
578
579 db_cluster["operatingState"] = "IDLE"
580 db_cluster = self.update_operation_history(
581 db_cluster, workflow_status, resource_status
582 )
rshri932105f2024-07-05 15:11:55 +0000583 profile_list = db_cluster[profile_type]
584 self.logger.info("profile list is : {}".format(profile_list))
585 if resource_status:
586 self.logger.info("it is getting into resource status true")
587 profile_list.append(profile_id)
588 self.logger.info("profile list is : {}".format(profile_list))
589 db_cluster[profile_type] = profile_list
590 self.logger.info("db cluster is : {}".format(db_cluster))
591 # update_dict = {item: profile_list}
592 # self.logger.info("the update_dict is :{}".format(update_dict))
593 # self.db.set_one(self.topic, filter_q, update_dict)
594 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
595
596 return
597
garciadeblas96b94f52024-07-08 16:18:21 +0200598 async def detach_profile(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000599 self.logger.info("profile dettach Enter")
garciadeblas96b94f52024-07-08 16:18:21 +0200600 db_cluster = content["cluster"]
601 db_profile = content["profile"]
602 profile_type = db_profile["profile_type"]
603 profile_id = db_profile["_id"]
rshri932105f2024-07-05 15:11:55 +0000604 self.logger.info("profile type is : {}".format(profile_type))
rshri932105f2024-07-05 15:11:55 +0000605 self.logger.info("profile id is : {}".format(profile_id))
606
garciadeblas869131a2024-11-08 01:11:46 +0100607 _, workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +0200608 "detach_profile_from_cluster", op_id, op_params, content
609 )
rshri932105f2024-07-05 15:11:55 +0000610 self.logger.info("workflow_name is :{}".format(workflow_name))
611
garciadeblas96b94f52024-07-08 16:18:21 +0200612 workflow_status, workflow_msg = await self.odu.check_workflow_status(
613 workflow_name
614 )
rshri932105f2024-07-05 15:11:55 +0000615 self.logger.info(
616 "workflow_status is :{} and workflow_msg is :{}".format(
617 workflow_status, workflow_msg
618 )
619 )
620 if workflow_status:
621 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
622 else:
623 db_cluster["resourceState"] = "ERROR"
624 # has to call update_operation_history return content
625 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
626 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
627
628 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +0100629 resource_status, resource_msg = await self.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +0200630 "detach_profile_from_cluster", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000631 )
632 self.logger.info(
633 "resource_status is :{} and resource_msg is :{}".format(
634 resource_status, resource_msg
635 )
636 )
637 if resource_status:
638 db_cluster["resourceState"] = "READY"
639 else:
640 db_cluster["resourceState"] = "ERROR"
641
642 db_cluster["operatingState"] = "IDLE"
643 db_cluster = self.update_operation_history(
644 db_cluster, workflow_status, resource_status
645 )
rshri932105f2024-07-05 15:11:55 +0000646 profile_list = db_cluster[profile_type]
647 self.logger.info("profile list is : {}".format(profile_list))
648 if resource_status:
649 self.logger.info("it is getting into resource status true")
650 profile_list.remove(profile_id)
651 self.logger.info("profile list is : {}".format(profile_list))
652 db_cluster[profile_type] = profile_list
653 self.logger.info("db cluster is : {}".format(db_cluster))
654 # update_dict = {item: profile_list}
655 # self.logger.info("the update_dict is :{}".format(update_dict))
656 # self.db.set_one(self.topic, filter_q, update_dict)
657 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
658
659 return
660
garciadeblas96b94f52024-07-08 16:18:21 +0200661 async def register(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000662 self.logger.info("cluster register enter")
garciadeblas96b94f52024-07-08 16:18:21 +0200663 db_cluster = content["cluster"]
rshri932105f2024-07-05 15:11:55 +0000664
rshrib0e6ac32024-11-12 18:12:38 +0000665 db_cluster_copy = self.decrypting_key(db_cluster)
666
garciadeblas869131a2024-11-08 01:11:46 +0100667 _, workflow_name = await self.odu.launch_workflow(
rshrib0e6ac32024-11-12 18:12:38 +0000668 "register_cluster", op_id, op_params, db_cluster_copy
garciadeblas96b94f52024-07-08 16:18:21 +0200669 )
rshri932105f2024-07-05 15:11:55 +0000670 self.logger.info("workflow_name is :{}".format(workflow_name))
671
garciadeblas96b94f52024-07-08 16:18:21 +0200672 workflow_status, workflow_msg = await self.odu.check_workflow_status(
673 workflow_name
674 )
rshri932105f2024-07-05 15:11:55 +0000675 self.logger.info(
676 "workflow_status is :{} and workflow_msg is :{}".format(
677 workflow_status, workflow_msg
678 )
679 )
680 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200681 db_cluster["state"] = "CREATED"
682 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +0000683 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200684 db_cluster["state"] = "FAILED_CREATION"
685 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000686 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +0200687 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
688 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
rshri932105f2024-07-05 15:11:55 +0000689
garciadeblasf1458032024-09-17 13:25:06 +0200690 # Clean items used in the workflow, no matter if the workflow succeeded
691 clean_status, clean_msg = await self.odu.clean_items_workflow(
rshrib0e6ac32024-11-12 18:12:38 +0000692 "register_cluster", op_id, op_params, db_cluster_copy
garciadeblasf1458032024-09-17 13:25:06 +0200693 )
694 self.logger.info(
695 f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
696 )
697
rshri932105f2024-07-05 15:11:55 +0000698 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +0100699 resource_status, resource_msg = await self.check_resource_status(
rshrib0e6ac32024-11-12 18:12:38 +0000700 "register_cluster", op_id, op_params, db_cluster_copy
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 db_cluster["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +0000709 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200710 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000711
garciadeblas96b94f52024-07-08 16:18:21 +0200712 db_cluster["operatingState"] = "IDLE"
713 db_cluster = self.update_operation_history(
714 db_cluster, workflow_status, resource_status
rshri932105f2024-07-05 15:11:55 +0000715 )
garciadeblas96b94f52024-07-08 16:18:21 +0200716 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
rshri932105f2024-07-05 15:11:55 +0000717 return
718
garciadeblas96b94f52024-07-08 16:18:21 +0200719 async def deregister(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000720 self.logger.info("cluster deregister enter")
garciadeblas96b94f52024-07-08 16:18:21 +0200721 db_cluster = content["cluster"]
rshri932105f2024-07-05 15:11:55 +0000722
garciadeblas96b94f52024-07-08 16:18:21 +0200723 self.logger.info("db_cluster is : {}".format(db_cluster))
rshri932105f2024-07-05 15:11:55 +0000724
garciadeblas869131a2024-11-08 01:11:46 +0100725 _, workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +0200726 "deregister_cluster", op_id, op_params, content
727 )
rshri932105f2024-07-05 15:11:55 +0000728 self.logger.info("workflow_name is :{}".format(workflow_name))
729
garciadeblas96b94f52024-07-08 16:18:21 +0200730 workflow_status, workflow_msg = await self.odu.check_workflow_status(
731 workflow_name
732 )
rshri932105f2024-07-05 15:11:55 +0000733 self.logger.info(
734 "workflow_status is :{} and workflow_msg is :{}".format(
735 workflow_status, workflow_msg
736 )
737 )
738 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200739 db_cluster["state"] = "DELETED"
740 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +0000741 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200742 db_cluster["state"] = "FAILED_DELETION"
743 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000744 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +0200745 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
746 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
rshri932105f2024-07-05 15:11:55 +0000747
garciadeblas4c0d2132024-11-12 11:17:12 +0100748 # Clean items used in the workflow or in the cluster, no matter if the workflow succeeded
749 clean_status, clean_msg = await self.odu.clean_items_workflow(
750 "deregister_cluster", op_id, op_params, content
751 )
752 self.logger.info(
753 f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
754 )
755
rshri932105f2024-07-05 15:11:55 +0000756 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +0100757 resource_status, resource_msg = await self.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +0200758 "deregister_cluster", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +0000759 )
760 self.logger.info(
761 "resource_status is :{} and resource_msg is :{}".format(
762 resource_status, resource_msg
763 )
764 )
765 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200766 db_cluster["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +0000767 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200768 db_cluster["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +0000769
garciadeblas96b94f52024-07-08 16:18:21 +0200770 db_cluster["operatingState"] = "IDLE"
771 db_cluster = self.update_operation_history(
772 db_cluster, workflow_status, resource_status
773 )
774 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
rshri932105f2024-07-05 15:11:55 +0000775
garciadeblas96b94f52024-07-08 16:18:21 +0200776 # To delete it from DB
777 if db_cluster["state"] == "DELETED":
778 self.db.del_one("clusters", {"_id": db_cluster["_id"]})
rshri932105f2024-07-05 15:11:55 +0000779 return
780
yshah07491142024-10-17 06:11:12 +0000781 async def get_creds(self, op_id, db_cluster):
garciadeblas96b94f52024-07-08 16:18:21 +0200782 self.logger.info("Cluster get creds Enter")
783 result, cluster_creds = await self.odu.get_cluster_credentials(db_cluster)
784 if result:
785 db_cluster["credentials"] = cluster_creds
yshah07491142024-10-17 06:11:12 +0000786 op_len = 0
787 for operations in db_cluster["operationHistory"]:
788 if operations["op_id"] == op_id:
789 db_cluster["operationHistory"][op_len]["result"] = result
790 db_cluster["operationHistory"][op_len]["endDate"] = time()
791 op_len += 1
792 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
yshah771dea82024-07-05 15:11:49 +0000793 return
794
garciadeblas96b94f52024-07-08 16:18:21 +0200795 async def update(self, op_id, op_params, content):
796 self.logger.info("Cluster update Enter")
797 db_cluster = content["cluster"]
yshah771dea82024-07-05 15:11:49 +0000798
rshrib0e6ac32024-11-12 18:12:38 +0000799 db_cluster_copy = self.decrypting_key(db_cluster)
800
801 # vim account details
802 db_vim = self.db.get_one("vim_accounts", {"name": db_cluster["vim_account"]})
803 db_cluster_copy["vim_account"] = db_vim
804
garciadeblas869131a2024-11-08 01:11:46 +0100805 _, workflow_name = await self.odu.launch_workflow(
rshrib0e6ac32024-11-12 18:12:38 +0000806 "update_cluster", op_id, op_params, db_cluster_copy
garciadeblas96b94f52024-07-08 16:18:21 +0200807 )
808 workflow_status, workflow_msg = await self.odu.check_workflow_status(
809 workflow_name
810 )
811 self.logger.info(
812 "Workflow Status: {} Workflow Message: {}".format(
813 workflow_status, workflow_msg
yshah771dea82024-07-05 15:11:49 +0000814 )
garciadeblas96b94f52024-07-08 16:18:21 +0200815 )
816
817 if workflow_status:
818 db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
819 else:
820 db_cluster["resourceState"] = "ERROR"
821
822 db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
823 # self.logger.info("Db content: {}".format(db_content))
824 # self.db.set_one(self.db_collection, {"_id": _id}, db_cluster)
825 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
826
garciadeblas4d26e292024-09-16 12:53:07 +0200827 # Clean items used in the workflow, no matter if the workflow succeeded
828 clean_status, clean_msg = await self.odu.clean_items_workflow(
rshrib0e6ac32024-11-12 18:12:38 +0000829 "update_cluster", op_id, op_params, db_cluster_copy
garciadeblas4d26e292024-09-16 12:53:07 +0200830 )
831 self.logger.info(
832 f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
833 )
garciadeblas96b94f52024-07-08 16:18:21 +0200834 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +0100835 resource_status, resource_msg = await self.check_resource_status(
rshrib0e6ac32024-11-12 18:12:38 +0000836 "update_cluster", op_id, op_params, db_cluster_copy
garciadeblas96b94f52024-07-08 16:18:21 +0200837 )
838 self.logger.info(
839 "Resource Status: {} Resource Message: {}".format(
840 resource_status, resource_msg
841 )
842 )
yshah771dea82024-07-05 15:11:49 +0000843
844 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +0200845 db_cluster["resourceState"] = "READY"
yshah771dea82024-07-05 15:11:49 +0000846 else:
garciadeblas96b94f52024-07-08 16:18:21 +0200847 db_cluster["resourceState"] = "ERROR"
yshah771dea82024-07-05 15:11:49 +0000848
garciadeblas96b94f52024-07-08 16:18:21 +0200849 db_cluster["operatingState"] = "IDLE"
850 db_cluster = self.update_operation_history(
851 db_cluster, workflow_status, resource_status
852 )
853 # self.logger.info("db_cluster: {}".format(db_cluster))
854 # TODO: verify enxtcondition
855 # For the moment, if the workflow completed successfully, then we update the db accordingly.
856 if workflow_status:
857 if "k8s_version" in op_params:
858 db_cluster["k8s_version"] = op_params["k8s_version"]
859 elif "node_count" in op_params:
860 db_cluster["node_count"] = op_params["node_count"]
861 # self.db.set_one(self.db_collection, {"_id": _id}, db_content)
862 self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
yshah771dea82024-07-05 15:11:49 +0000863 return
864
865
garciadeblas635b35a2024-11-07 12:41:54 +0100866class CloudCredentialsLcm(GitOpsLcm):
yshah771dea82024-07-05 15:11:49 +0000867 db_collection = "vim_accounts"
868
869 def __init__(self, msg, lcm_tasks, config):
870 """
871 Init, Connect to database, filesystem storage, and messaging
872 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
873 :return: None
874 """
garciadeblas635b35a2024-11-07 12:41:54 +0100875 super().__init__(msg, lcm_tasks, config)
yshah771dea82024-07-05 15:11:49 +0000876
garciadeblas96b94f52024-07-08 16:18:21 +0200877 async def add(self, op_id, op_params, content):
yshah771dea82024-07-05 15:11:49 +0000878 self.logger.info("Cloud Credentials create")
garciadeblas869131a2024-11-08 01:11:46 +0100879 _, workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +0200880 "create_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000881 )
882
883 workflow_status, workflow_msg = await self.odu.check_workflow_status(
884 workflow_name
885 )
886
887 self.logger.info(
888 "Workflow Status: {} Workflow Msg: {}".format(workflow_status, workflow_msg)
889 )
890
garciadeblas4d26e292024-09-16 12:53:07 +0200891 # Clean items used in the workflow, no matter if the workflow succeeded
892 clean_status, clean_msg = await self.odu.clean_items_workflow(
893 "create_cloud_credentials", op_id, op_params, content
894 )
895 self.logger.info(
896 f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
897 )
898
yshah771dea82024-07-05 15:11:49 +0000899 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +0100900 resource_status, resource_msg = await self.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +0200901 "create_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000902 )
903 self.logger.info(
904 "Resource Status: {} Resource Message: {}".format(
905 resource_status, resource_msg
906 )
907 )
garciadeblas8595d572024-09-23 12:40:13 +0200908
909 content["_admin"]["operationalState"] = "ENABLED"
910 for operation in content["_admin"]["operations"]:
911 if operation["lcmOperationType"] == "create":
912 operation["operationState"] = "ENABLED"
913 self.logger.info("Content : {}".format(content))
914 self.db.set_one("vim_accounts", {"_id": content["_id"]}, content)
915
yshah771dea82024-07-05 15:11:49 +0000916 return
917
garciadeblas96b94f52024-07-08 16:18:21 +0200918 async def edit(self, op_id, op_params, content):
garciadeblas869131a2024-11-08 01:11:46 +0100919 _, workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +0200920 "update_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000921 )
922 workflow_status, workflow_msg = await self.odu.check_workflow_status(
923 workflow_name
924 )
925 self.logger.info(
926 "Workflow Status: {} Workflow Msg: {}".format(workflow_status, workflow_msg)
927 )
928
garciadeblas4d26e292024-09-16 12:53:07 +0200929 # Clean items used in the workflow, no matter if the workflow succeeded
930 clean_status, clean_msg = await self.odu.clean_items_workflow(
931 "update_cloud_credentials", op_id, op_params, content
932 )
933 self.logger.info(
934 f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
935 )
936
yshah771dea82024-07-05 15:11:49 +0000937 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +0100938 resource_status, resource_msg = await self.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +0200939 "update_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000940 )
941 self.logger.info(
942 "Resource Status: {} Resource Message: {}".format(
943 resource_status, resource_msg
944 )
945 )
946 return
947
garciadeblas96b94f52024-07-08 16:18:21 +0200948 async def remove(self, op_id, op_params, content):
yshah771dea82024-07-05 15:11:49 +0000949 self.logger.info("Cloud Credentials delete")
garciadeblas869131a2024-11-08 01:11:46 +0100950 _, workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +0200951 "delete_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000952 )
953 workflow_status, workflow_msg = await self.odu.check_workflow_status(
954 workflow_name
955 )
956 self.logger.info(
957 "Workflow Status: {} Workflow Msg: {}".format(workflow_status, workflow_msg)
958 )
959
960 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +0100961 resource_status, resource_msg = await self.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +0200962 "delete_cloud_credentials", op_id, op_params, content
yshah771dea82024-07-05 15:11:49 +0000963 )
964 self.logger.info(
965 "Resource Status: {} Resource Message: {}".format(
966 resource_status, resource_msg
967 )
968 )
969 self.db.del_one(self.db_collection, {"_id": content["_id"]})
970 return
971
rshri932105f2024-07-05 15:11:55 +0000972
garciadeblas635b35a2024-11-07 12:41:54 +0100973class K8sAppLcm(GitOpsLcm):
rshri932105f2024-07-05 15:11:55 +0000974 def __init__(self, msg, lcm_tasks, config):
975 """
976 Init, Connect to database, filesystem storage, and messaging
977 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
978 :return: None
979 """
garciadeblas635b35a2024-11-07 12:41:54 +0100980 super().__init__(msg, lcm_tasks, config)
rshri932105f2024-07-05 15:11:55 +0000981
garciadeblas96b94f52024-07-08 16:18:21 +0200982 async def create(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +0000983 self.logger.info("App Create Enter")
984
garciadeblas869131a2024-11-08 01:11:46 +0100985 _, workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +0200986 "create_profile", op_id, op_params, content
987 )
rshri932105f2024-07-05 15:11:55 +0000988 self.logger.info("workflow_name is :{}".format(workflow_name))
989
garciadeblas96b94f52024-07-08 16:18:21 +0200990 workflow_status, workflow_msg = await self.odu.check_workflow_status(
991 workflow_name
992 )
rshri932105f2024-07-05 15:11:55 +0000993 self.logger.info(
994 "workflow_status is :{} and workflow_msg is :{}".format(
995 workflow_status, workflow_msg
996 )
997 )
998 if workflow_status:
999 content["state"] = "CREATED"
1000 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1001 else:
1002 content["state"] = "FAILED_CREATION"
1003 content["resourceState"] = "ERROR"
1004 # has to call update_operation_history return content
1005 content = self.update_operation_history(content, workflow_status, None)
1006 self.db.set_one("k8sapp", {"_id": content["_id"]}, content)
1007
1008 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +01001009 resource_status, resource_msg = await self.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +02001010 "create_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +00001011 )
1012 self.logger.info(
1013 "resource_status is :{} and resource_msg is :{}".format(
1014 resource_status, resource_msg
1015 )
1016 )
1017 if resource_status:
1018 content["resourceState"] = "READY"
1019 else:
1020 content["resourceState"] = "ERROR"
1021
1022 content["operatingState"] = "IDLE"
1023 content = self.update_operation_history(
1024 content, workflow_status, resource_status
1025 )
1026 self.db.set_one("k8sapp", {"_id": content["_id"]}, content)
1027
1028 return
1029
garciadeblas96b94f52024-07-08 16:18:21 +02001030 async def delete(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +00001031 self.logger.info("App delete Enter")
rshri932105f2024-07-05 15:11:55 +00001032
garciadeblas869131a2024-11-08 01:11:46 +01001033 _, workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +02001034 "delete_profile", op_id, op_params, content
1035 )
rshri932105f2024-07-05 15:11:55 +00001036 self.logger.info("workflow_name is :{}".format(workflow_name))
1037
garciadeblas96b94f52024-07-08 16:18:21 +02001038 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1039 workflow_name
1040 )
rshri932105f2024-07-05 15:11:55 +00001041 self.logger.info(
1042 "workflow_status is :{} and workflow_msg is :{}".format(
1043 workflow_status, workflow_msg
1044 )
1045 )
1046 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001047 content["state"] = "DELETED"
1048 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +00001049 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001050 content["state"] = "FAILED_DELETION"
1051 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +00001052 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +02001053 content = self.update_operation_history(content, workflow_status, None)
rshri932105f2024-07-05 15:11:55 +00001054 self.db.set_one("k8sapp", {"_id": content["_id"]}, content)
1055
1056 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +01001057 resource_status, resource_msg = await self.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +02001058 "delete_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +00001059 )
1060 self.logger.info(
1061 "resource_status is :{} and resource_msg is :{}".format(
1062 resource_status, resource_msg
1063 )
1064 )
1065 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001066 content["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +00001067 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001068 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +00001069
garciadeblas96b94f52024-07-08 16:18:21 +02001070 content["operatingState"] = "IDLE"
1071 content = self.update_operation_history(
1072 content, workflow_status, resource_status
1073 )
1074 self.db.set_one("k8sapp", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +00001075
garciadeblas96b94f52024-07-08 16:18:21 +02001076 # To delete it from DB
1077 if content["state"] == "DELETED":
rshri932105f2024-07-05 15:11:55 +00001078 self.db.del_one("k8sapp", {"_id": content["_id"]})
1079 return
1080
1081
garciadeblas635b35a2024-11-07 12:41:54 +01001082class K8sResourceLcm(GitOpsLcm):
rshri932105f2024-07-05 15:11:55 +00001083 def __init__(self, msg, lcm_tasks, config):
1084 """
1085 Init, Connect to database, filesystem storage, and messaging
1086 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
1087 :return: None
1088 """
garciadeblas635b35a2024-11-07 12:41:54 +01001089 super().__init__(msg, lcm_tasks, config)
rshri932105f2024-07-05 15:11:55 +00001090
garciadeblas96b94f52024-07-08 16:18:21 +02001091 async def create(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +00001092 self.logger.info("Resource Create Enter")
1093
garciadeblas869131a2024-11-08 01:11:46 +01001094 _, workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +02001095 "create_profile", op_id, op_params, content
1096 )
rshri932105f2024-07-05 15:11:55 +00001097 self.logger.info("workflow_name is :{}".format(workflow_name))
1098
garciadeblas96b94f52024-07-08 16:18:21 +02001099 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1100 workflow_name
1101 )
rshri932105f2024-07-05 15:11:55 +00001102 self.logger.info(
1103 "workflow_status is :{} and workflow_msg is :{}".format(
1104 workflow_status, workflow_msg
1105 )
1106 )
1107 if workflow_status:
1108 content["state"] = "CREATED"
1109 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1110 else:
1111 content["state"] = "FAILED_CREATION"
1112 content["resourceState"] = "ERROR"
1113 # has to call update_operation_history return content
1114 content = self.update_operation_history(content, workflow_status, None)
1115 self.db.set_one("k8sresource", {"_id": content["_id"]}, content)
1116
1117 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +01001118 resource_status, resource_msg = await self.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +02001119 "create_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +00001120 )
1121 self.logger.info(
1122 "resource_status is :{} and resource_msg is :{}".format(
1123 resource_status, resource_msg
1124 )
1125 )
1126 if resource_status:
1127 content["resourceState"] = "READY"
1128 else:
1129 content["resourceState"] = "ERROR"
1130
1131 content["operatingState"] = "IDLE"
1132 content = self.update_operation_history(
1133 content, workflow_status, resource_status
1134 )
1135 self.db.set_one("k8sresource", {"_id": content["_id"]}, content)
1136
1137 return
1138
garciadeblas96b94f52024-07-08 16:18:21 +02001139 async def delete(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +00001140 self.logger.info("Resource delete Enter")
garciadeblas96b94f52024-07-08 16:18:21 +02001141 content = self.db.get_one("k8sresource", {"_id": content["_id"]})
rshri932105f2024-07-05 15:11:55 +00001142
garciadeblas869131a2024-11-08 01:11:46 +01001143 _, workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +02001144 "delete_profile", op_id, op_params, content
1145 )
rshri932105f2024-07-05 15:11:55 +00001146 self.logger.info("workflow_name is :{}".format(workflow_name))
1147
garciadeblas96b94f52024-07-08 16:18:21 +02001148 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1149 workflow_name
1150 )
rshri932105f2024-07-05 15:11:55 +00001151 self.logger.info(
1152 "workflow_status is :{} and workflow_msg is :{}".format(
1153 workflow_status, workflow_msg
1154 )
1155 )
1156 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001157 content["state"] = "DELETED"
1158 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +00001159 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001160 content["state"] = "FAILED_DELETION"
1161 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +00001162 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +02001163 content = self.update_operation_history(content, workflow_status, None)
1164 self.db.set_one("k8sresource", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +00001165
1166 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +01001167 resource_status, resource_msg = await self.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +02001168 "delete_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +00001169 )
1170 self.logger.info(
1171 "resource_status is :{} and resource_msg is :{}".format(
1172 resource_status, resource_msg
1173 )
1174 )
1175 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001176 content["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +00001177 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001178 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +00001179
garciadeblas96b94f52024-07-08 16:18:21 +02001180 content["operatingState"] = "IDLE"
1181 content = self.update_operation_history(
1182 content, workflow_status, resource_status
1183 )
1184 self.db.set_one("k8sresource", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +00001185
garciadeblas96b94f52024-07-08 16:18:21 +02001186 # To delete it from DB
1187 if content["state"] == "DELETED":
rshri932105f2024-07-05 15:11:55 +00001188 self.db.del_one("k8sresource", {"_id": content["_id"]})
1189 return
1190
1191
garciadeblas635b35a2024-11-07 12:41:54 +01001192class K8sInfraControllerLcm(GitOpsLcm):
rshri932105f2024-07-05 15:11:55 +00001193 def __init__(self, msg, lcm_tasks, config):
1194 """
1195 Init, Connect to database, filesystem storage, and messaging
1196 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
1197 :return: None
1198 """
garciadeblas635b35a2024-11-07 12:41:54 +01001199 super().__init__(msg, lcm_tasks, config)
rshri932105f2024-07-05 15:11:55 +00001200
garciadeblas96b94f52024-07-08 16:18:21 +02001201 async def create(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +00001202 self.logger.info("Infra controller Create Enter")
1203
garciadeblas869131a2024-11-08 01:11:46 +01001204 _, workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +02001205 "create_profile", op_id, op_params, content
1206 )
rshri932105f2024-07-05 15:11:55 +00001207 self.logger.info("workflow_name is :{}".format(workflow_name))
1208
garciadeblas96b94f52024-07-08 16:18:21 +02001209 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1210 workflow_name
1211 )
rshri932105f2024-07-05 15:11:55 +00001212 self.logger.info(
1213 "workflow_status is :{} and workflow_msg is :{}".format(
1214 workflow_status, workflow_msg
1215 )
1216 )
1217 if workflow_status:
1218 content["state"] = "CREATED"
1219 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1220 else:
1221 content["state"] = "FAILED_CREATION"
1222 content["resourceState"] = "ERROR"
1223 # has to call update_operation_history return content
1224 content = self.update_operation_history(content, workflow_status, None)
1225 self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content)
1226
1227 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +01001228 resource_status, resource_msg = await self.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +02001229 "create_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +00001230 )
1231 self.logger.info(
1232 "resource_status is :{} and resource_msg is :{}".format(
1233 resource_status, resource_msg
1234 )
1235 )
1236 if resource_status:
1237 content["resourceState"] = "READY"
1238 else:
1239 content["resourceState"] = "ERROR"
1240
1241 content["operatingState"] = "IDLE"
1242 content = self.update_operation_history(
1243 content, workflow_status, resource_status
1244 )
1245 self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content)
1246
1247 return
1248
garciadeblas96b94f52024-07-08 16:18:21 +02001249 async def delete(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +00001250 self.logger.info("Infra controller delete Enter")
rshri932105f2024-07-05 15:11:55 +00001251
garciadeblas869131a2024-11-08 01:11:46 +01001252 _, workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +02001253 "delete_profile", op_id, op_params, content
1254 )
rshri932105f2024-07-05 15:11:55 +00001255 self.logger.info("workflow_name is :{}".format(workflow_name))
1256
garciadeblas96b94f52024-07-08 16:18:21 +02001257 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1258 workflow_name
1259 )
rshri932105f2024-07-05 15:11:55 +00001260 self.logger.info(
1261 "workflow_status is :{} and workflow_msg is :{}".format(
1262 workflow_status, workflow_msg
1263 )
1264 )
1265 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001266 content["state"] = "DELETED"
1267 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +00001268 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001269 content["state"] = "FAILED_DELETION"
1270 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +00001271 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +02001272 content = self.update_operation_history(content, workflow_status, None)
1273 self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +00001274
1275 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +01001276 resource_status, resource_msg = await self.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +02001277 "delete_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +00001278 )
1279 self.logger.info(
1280 "resource_status is :{} and resource_msg is :{}".format(
1281 resource_status, resource_msg
1282 )
1283 )
1284 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001285 content["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +00001286 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001287 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +00001288
garciadeblas96b94f52024-07-08 16:18:21 +02001289 content["operatingState"] = "IDLE"
1290 content = self.update_operation_history(
1291 content, workflow_status, resource_status
1292 )
1293 self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +00001294
garciadeblas96b94f52024-07-08 16:18:21 +02001295 # To delete it from DB
1296 if content["state"] == "DELETED":
rshri932105f2024-07-05 15:11:55 +00001297 self.db.del_one("k8sinfra_controller", {"_id": content["_id"]})
1298 return
1299
1300
garciadeblas635b35a2024-11-07 12:41:54 +01001301class K8sInfraConfigLcm(GitOpsLcm):
rshri932105f2024-07-05 15:11:55 +00001302 def __init__(self, msg, lcm_tasks, config):
1303 """
1304 Init, Connect to database, filesystem storage, and messaging
1305 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
1306 :return: None
1307 """
garciadeblas635b35a2024-11-07 12:41:54 +01001308 super().__init__(msg, lcm_tasks, config)
rshri932105f2024-07-05 15:11:55 +00001309
garciadeblas96b94f52024-07-08 16:18:21 +02001310 async def create(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +00001311 self.logger.info("Infra config Create Enter")
1312
garciadeblas869131a2024-11-08 01:11:46 +01001313 _, workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +02001314 "create_profile", op_id, op_params, content
1315 )
rshri932105f2024-07-05 15:11:55 +00001316 self.logger.info("workflow_name is :{}".format(workflow_name))
1317
garciadeblas96b94f52024-07-08 16:18:21 +02001318 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1319 workflow_name
1320 )
rshri932105f2024-07-05 15:11:55 +00001321 self.logger.info(
1322 "workflow_status is :{} and workflow_msg is :{}".format(
1323 workflow_status, workflow_msg
1324 )
1325 )
1326 if workflow_status:
1327 content["state"] = "CREATED"
1328 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1329 else:
1330 content["state"] = "FAILED_CREATION"
1331 content["resourceState"] = "ERROR"
1332 # has to call update_operation_history return content
1333 content = self.update_operation_history(content, workflow_status, None)
1334 self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content)
1335
1336 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +01001337 resource_status, resource_msg = await self.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +02001338 "create_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +00001339 )
1340 self.logger.info(
1341 "resource_status is :{} and resource_msg is :{}".format(
1342 resource_status, resource_msg
1343 )
1344 )
1345 if resource_status:
1346 content["resourceState"] = "READY"
1347 else:
1348 content["resourceState"] = "ERROR"
1349
1350 content["operatingState"] = "IDLE"
1351 content = self.update_operation_history(
1352 content, workflow_status, resource_status
1353 )
1354 self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content)
1355
1356 return
1357
garciadeblas96b94f52024-07-08 16:18:21 +02001358 async def delete(self, op_id, op_params, content):
rshri932105f2024-07-05 15:11:55 +00001359 self.logger.info("Infra config delete Enter")
1360
garciadeblas869131a2024-11-08 01:11:46 +01001361 _, workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +02001362 "delete_profile", op_id, op_params, content
1363 )
rshri932105f2024-07-05 15:11:55 +00001364 self.logger.info("workflow_name is :{}".format(workflow_name))
rshri932105f2024-07-05 15:11:55 +00001365
garciadeblas96b94f52024-07-08 16:18:21 +02001366 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1367 workflow_name
1368 )
rshri932105f2024-07-05 15:11:55 +00001369 self.logger.info(
1370 "workflow_status is :{} and workflow_msg is :{}".format(
1371 workflow_status, workflow_msg
1372 )
1373 )
1374 if workflow_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001375 content["state"] = "DELETED"
1376 content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
rshri932105f2024-07-05 15:11:55 +00001377 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001378 content["state"] = "FAILED_DELETION"
1379 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +00001380 # has to call update_operation_history return content
garciadeblas96b94f52024-07-08 16:18:21 +02001381 content = self.update_operation_history(content, workflow_status, None)
1382 self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +00001383
garciadeblas635b35a2024-11-07 12:41:54 +01001384 resource_status, resource_msg = await self.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +02001385 "delete_profile", op_id, op_params, content
rshri932105f2024-07-05 15:11:55 +00001386 )
1387 self.logger.info(
1388 "resource_status is :{} and resource_msg is :{}".format(
1389 resource_status, resource_msg
1390 )
1391 )
1392 if resource_status:
garciadeblas96b94f52024-07-08 16:18:21 +02001393 content["resourceState"] = "READY"
rshri932105f2024-07-05 15:11:55 +00001394 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001395 content["resourceState"] = "ERROR"
rshri932105f2024-07-05 15:11:55 +00001396
garciadeblas96b94f52024-07-08 16:18:21 +02001397 content["operatingState"] = "IDLE"
1398 content = self.update_operation_history(
1399 content, workflow_status, resource_status
1400 )
1401 self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content)
rshri932105f2024-07-05 15:11:55 +00001402
garciadeblas96b94f52024-07-08 16:18:21 +02001403 # To delete it from DB
1404 if content["state"] == "DELETED":
rshri932105f2024-07-05 15:11:55 +00001405 self.db.del_one("k8sinfra_config", {"_id": content["_id"]})
1406 return
yshah771dea82024-07-05 15:11:49 +00001407
1408
garciadeblas635b35a2024-11-07 12:41:54 +01001409class OkaLcm(GitOpsLcm):
yshah771dea82024-07-05 15:11:49 +00001410 db_collection = "okas"
1411
1412 def __init__(self, msg, lcm_tasks, config):
1413 """
1414 Init, Connect to database, filesystem storage, and messaging
1415 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
1416 :return: None
1417 """
garciadeblas635b35a2024-11-07 12:41:54 +01001418 super().__init__(msg, lcm_tasks, config)
yshah771dea82024-07-05 15:11:49 +00001419
garciadeblas96b94f52024-07-08 16:18:21 +02001420 async def create(self, op_id, op_params, content):
1421 self.logger.info("OKA Create Enter")
1422 db_content = content
yshah771dea82024-07-05 15:11:49 +00001423
garciadeblas869131a2024-11-08 01:11:46 +01001424 _, workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +02001425 "create_oka", op_id, op_params, db_content
1426 )
1427 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1428 workflow_name
1429 )
1430 self.logger.info(
1431 "Workflow Status: {} Workflow Message: {}".format(
1432 workflow_status, workflow_msg
1433 )
1434 )
yshah771dea82024-07-05 15:11:49 +00001435
1436 if workflow_status:
1437 db_content["state"] = "CREATED"
1438 db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1439 else:
1440 db_content["state"] = "FAILED_CREATION"
1441 db_content["resourceState"] = "ERROR"
1442
1443 db_content = self.update_operation_history(db_content, workflow_status, None)
garciadeblas96b94f52024-07-08 16:18:21 +02001444 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001445
1446 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +01001447 resource_status, resource_msg = await self.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +02001448 "create_oka", op_id, op_params, db_content
yshah771dea82024-07-05 15:11:49 +00001449 )
garciadeblas96b94f52024-07-08 16:18:21 +02001450 self.logger.info(
1451 "Resource Status: {} Resource Message: {}".format(
1452 resource_status, resource_msg
1453 )
1454 )
yshah771dea82024-07-05 15:11:49 +00001455
1456 if resource_status:
1457 db_content["resourceState"] = "READY"
1458 else:
1459 db_content["resourceState"] = "ERROR"
1460
1461 # self.logger.info("Db content: {}".format(db_content))
1462 db_content = self.update_operation_history(
1463 db_content, workflow_status, resource_status
1464 )
1465
1466 db_content["operatingState"] = "IDLE"
garciadeblas96b94f52024-07-08 16:18:21 +02001467 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001468
1469 return
1470
garciadeblas96b94f52024-07-08 16:18:21 +02001471 async def edit(self, op_id, op_params, content):
1472 self.logger.info("OKA Edit Enter")
1473 db_content = content
yshah771dea82024-07-05 15:11:49 +00001474
garciadeblas869131a2024-11-08 01:11:46 +01001475 _, workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +02001476 "update_oka", op_id, op_params, content
1477 )
1478 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1479 workflow_name
1480 )
1481 self.logger.info(
1482 "Workflow Status: {} Workflow Message: {}".format(
1483 workflow_status, workflow_msg
1484 )
1485 )
yshah771dea82024-07-05 15:11:49 +00001486
1487 if workflow_status:
1488 db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1489 else:
1490 db_content["resourceState"] = "ERROR"
1491
1492 db_content = self.update_operation_history(db_content, workflow_status, None)
1493 # self.logger.info("Db content: {}".format(db_content))
garciadeblas96b94f52024-07-08 16:18:21 +02001494 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001495
1496 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +01001497 resource_status, resource_msg = await self.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +02001498 "update_oka", op_id, op_params, db_content
yshah771dea82024-07-05 15:11:49 +00001499 )
garciadeblas96b94f52024-07-08 16:18:21 +02001500 self.logger.info(
1501 "Resource Status: {} Resource Message: {}".format(
1502 resource_status, resource_msg
1503 )
1504 )
yshah771dea82024-07-05 15:11:49 +00001505
1506 if resource_status:
1507 db_content["resourceState"] = "READY"
1508 else:
1509 db_content["resourceState"] = "ERROR"
1510
1511 db_content = self.update_operation_history(
1512 db_content, workflow_status, resource_status
1513 )
1514
1515 db_content["operatingState"] = "IDLE"
garciadeblas96b94f52024-07-08 16:18:21 +02001516 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001517 return
1518
garciadeblas96b94f52024-07-08 16:18:21 +02001519 async def delete(self, op_id, op_params, content):
1520 self.logger.info("OKA delete Enter")
1521 db_content = content
yshah771dea82024-07-05 15:11:49 +00001522
garciadeblas869131a2024-11-08 01:11:46 +01001523 _, workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +02001524 "delete_oka", op_id, op_params, content
1525 )
1526 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1527 workflow_name
1528 )
1529 self.logger.info(
1530 "Workflow Status: {} Workflow Message: {}".format(
1531 workflow_status, workflow_msg
1532 )
1533 )
yshah771dea82024-07-05 15:11:49 +00001534
1535 if workflow_status:
1536 db_content["state"] = "DELETED"
1537 db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1538 else:
1539 db_content["state"] = "FAILED_DELETION"
1540 db_content["resourceState"] = "ERROR"
1541
1542 db_content = self.update_operation_history(db_content, workflow_status, None)
garciadeblas96b94f52024-07-08 16:18:21 +02001543 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001544
1545 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +01001546 resource_status, resource_msg = await self.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +02001547 "delete_oka", op_id, op_params, db_content
yshah771dea82024-07-05 15:11:49 +00001548 )
garciadeblas96b94f52024-07-08 16:18:21 +02001549 self.logger.info(
1550 "Resource Status: {} Resource Message: {}".format(
1551 resource_status, resource_msg
1552 )
1553 )
yshah771dea82024-07-05 15:11:49 +00001554
1555 if resource_status:
1556 db_content["resourceState"] = "READY"
1557 else:
1558 db_content["resourceState"] = "ERROR"
1559
1560 db_content = self.update_operation_history(
1561 db_content, workflow_status, resource_status
1562 )
1563
1564 db_content["operatingState"] = "IDLE"
garciadeblas96b94f52024-07-08 16:18:21 +02001565 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001566
1567 if db_content["state"] == "DELETED":
garciadeblas96b94f52024-07-08 16:18:21 +02001568 self.db.del_one(self.db_collection, {"_id": db_content["_id"]})
yshah771dea82024-07-05 15:11:49 +00001569 return
1570
1571
garciadeblas635b35a2024-11-07 12:41:54 +01001572class KsuLcm(GitOpsLcm):
yshah771dea82024-07-05 15:11:49 +00001573 db_collection = "ksus"
1574
1575 def __init__(self, msg, lcm_tasks, config):
1576 """
1577 Init, Connect to database, filesystem storage, and messaging
1578 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
1579 :return: None
1580 """
garciadeblas635b35a2024-11-07 12:41:54 +01001581 super().__init__(msg, lcm_tasks, config)
yshah771dea82024-07-05 15:11:49 +00001582
garciadeblas96b94f52024-07-08 16:18:21 +02001583 async def create(self, op_id, op_params, content):
1584 self.logger.info("ksu Create Enter")
yshah771dea82024-07-05 15:11:49 +00001585
garciadeblas869131a2024-11-08 01:11:46 +01001586 _, workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +02001587 "create_ksus", op_id, op_params, content
1588 )
1589 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1590 workflow_name
1591 )
1592 self.logger.info(
1593 "Workflow Status: {} Workflow Message: {}".format(
1594 workflow_status, workflow_msg
yshah771dea82024-07-05 15:11:49 +00001595 )
garciadeblas96b94f52024-07-08 16:18:21 +02001596 )
yshah771dea82024-07-05 15:11:49 +00001597
garciadeblas96b94f52024-07-08 16:18:21 +02001598 for db_ksu in content:
1599 if workflow_status:
1600 db_ksu["state"] = "CREATED"
1601 db_ksu["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
yshah771dea82024-07-05 15:11:49 +00001602 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001603 db_ksu["state"] = "FAILED_CREATION"
1604 db_ksu["resourceState"] = "ERROR"
yshah771dea82024-07-05 15:11:49 +00001605
garciadeblas96b94f52024-07-08 16:18:21 +02001606 db_ksu = self.update_operation_history(db_ksu, workflow_status, None)
1607 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
1608
garciadeblas163d9992024-10-17 15:30:30 +02001609 # Clean items used in the workflow, no matter if the workflow succeeded
1610 clean_status, clean_msg = await self.odu.clean_items_workflow(
1611 "create_ksus", op_id, op_params, content
1612 )
1613 self.logger.info(
1614 f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
1615 )
1616
garciadeblas96b94f52024-07-08 16:18:21 +02001617 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +01001618 resource_status, resource_msg = await self.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +02001619 "create_ksus", op_id, op_params, content
1620 )
1621 self.logger.info(
1622 "Resource Status: {} Resource Message: {}".format(
1623 resource_status, resource_msg
1624 )
yshah771dea82024-07-05 15:11:49 +00001625 )
1626
garciadeblas96b94f52024-07-08 16:18:21 +02001627 for db_ksu in content:
1628 if resource_status:
1629 db_ksu["resourceState"] = "READY"
1630 else:
1631 db_ksu["resourceState"] = "ERROR"
1632
1633 db_ksu = self.update_operation_history(
1634 db_ksu, workflow_status, resource_status
1635 )
1636
1637 for db_ksu in content:
1638 db_ksu["operatingState"] = "IDLE"
1639 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
yshah771dea82024-07-05 15:11:49 +00001640
1641 return
1642
garciadeblas96b94f52024-07-08 16:18:21 +02001643 async def edit(self, op_id, op_params, content):
1644 self.logger.info("ksu edit Enter")
yshah771dea82024-07-05 15:11:49 +00001645
garciadeblas869131a2024-11-08 01:11:46 +01001646 _, workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +02001647 "update_ksus", op_id, op_params, content
1648 )
1649 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1650 workflow_name
1651 )
1652 self.logger.info(
1653 "Workflow Status: {} Workflow Message: {}".format(
1654 workflow_status, workflow_msg
yshah771dea82024-07-05 15:11:49 +00001655 )
garciadeblas96b94f52024-07-08 16:18:21 +02001656 )
yshah771dea82024-07-05 15:11:49 +00001657
garciadeblas96b94f52024-07-08 16:18:21 +02001658 for db_ksu in content:
1659 if workflow_status:
1660 db_ksu["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
yshah771dea82024-07-05 15:11:49 +00001661 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001662 db_ksu["resourceState"] = "ERROR"
yshah771dea82024-07-05 15:11:49 +00001663
garciadeblas96b94f52024-07-08 16:18:21 +02001664 db_ksu = self.update_operation_history(db_ksu, workflow_status, None)
1665 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
1666
garciadeblas163d9992024-10-17 15:30:30 +02001667 # Clean items used in the workflow, no matter if the workflow succeeded
1668 clean_status, clean_msg = await self.odu.clean_items_workflow(
1669 "create_ksus", op_id, op_params, content
1670 )
1671 self.logger.info(
1672 f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
1673 )
garciadeblas96b94f52024-07-08 16:18:21 +02001674 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +01001675 resource_status, resource_msg = await self.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +02001676 "update_ksus", op_id, op_params, content
1677 )
1678 self.logger.info(
1679 "Resource Status: {} Resource Message: {}".format(
1680 resource_status, resource_msg
1681 )
yshah771dea82024-07-05 15:11:49 +00001682 )
1683
garciadeblas96b94f52024-07-08 16:18:21 +02001684 for db_ksu in content:
1685 if resource_status:
1686 db_ksu["resourceState"] = "READY"
1687 else:
1688 db_ksu["resourceState"] = "ERROR"
1689
1690 db_ksu = self.update_operation_history(
1691 db_ksu, workflow_status, resource_status
1692 )
1693
1694 for db_ksu, ksu_params in zip(content, op_params):
1695 db_ksu["operatingState"] = "IDLE"
1696 if workflow_status:
1697 db_ksu["name"] = ksu_params["name"]
1698 db_ksu["description"] = ksu_params["description"]
1699 db_ksu["profile"]["profile_type"] = ksu_params["profile"][
1700 "profile_type"
1701 ]
1702 db_ksu["profile"]["_id"] = ksu_params["profile"]["_id"]
1703 db_ksu["oka"] = ksu_params["oka"]
1704 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
1705
yshah771dea82024-07-05 15:11:49 +00001706 return
1707
garciadeblas96b94f52024-07-08 16:18:21 +02001708 async def delete(self, op_id, op_params, content):
1709 self.logger.info("ksu delete Enter")
yshah771dea82024-07-05 15:11:49 +00001710
garciadeblas869131a2024-11-08 01:11:46 +01001711 _, workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +02001712 "delete_ksus", op_id, op_params, content
1713 )
1714 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1715 workflow_name
1716 )
1717 self.logger.info(
1718 "Workflow Status: {} Workflow Message: {}".format(
1719 workflow_status, workflow_msg
yshah771dea82024-07-05 15:11:49 +00001720 )
garciadeblas96b94f52024-07-08 16:18:21 +02001721 )
yshah771dea82024-07-05 15:11:49 +00001722
garciadeblas96b94f52024-07-08 16:18:21 +02001723 for db_ksu in content:
1724 if workflow_status:
1725 db_ksu["state"] = "DELETED"
1726 db_ksu["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
yshah771dea82024-07-05 15:11:49 +00001727 else:
garciadeblas96b94f52024-07-08 16:18:21 +02001728 db_ksu["state"] = "FAILED_DELETION"
1729 db_ksu["resourceState"] = "ERROR"
yshah771dea82024-07-05 15:11:49 +00001730
garciadeblas96b94f52024-07-08 16:18:21 +02001731 db_ksu = self.update_operation_history(db_ksu, workflow_status, None)
1732 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
1733
1734 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +01001735 resource_status, resource_msg = await self.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +02001736 "delete_ksus", op_id, op_params, content
1737 )
1738 self.logger.info(
1739 "Resource Status: {} Resource Message: {}".format(
1740 resource_status, resource_msg
1741 )
yshah771dea82024-07-05 15:11:49 +00001742 )
1743
garciadeblas96b94f52024-07-08 16:18:21 +02001744 for db_ksu in content:
1745 if resource_status:
1746 db_ksu["resourceState"] = "READY"
1747 else:
1748 db_ksu["resourceState"] = "ERROR"
yshah771dea82024-07-05 15:11:49 +00001749
garciadeblas96b94f52024-07-08 16:18:21 +02001750 db_ksu = self.update_operation_history(
1751 db_ksu, workflow_status, resource_status
1752 )
1753
1754 for db_ksu in content:
1755 db_ksu["operatingState"] = "IDLE"
1756 self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
1757
1758 if db_ksu["state"] == "DELETED":
1759 self.db.del_one(self.db_collection, {"_id": db_ksu["_id"]})
yshah771dea82024-07-05 15:11:49 +00001760 return
1761
garciadeblas96b94f52024-07-08 16:18:21 +02001762 async def clone(self, op_id, op_params, db_content):
1763 self.logger.info("ksu clone Enter")
yshah771dea82024-07-05 15:11:49 +00001764
garciadeblas869131a2024-11-08 01:11:46 +01001765 _, workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +02001766 "clone_ksus", op_id, op_params, db_content
1767 )
1768 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1769 workflow_name
1770 )
1771 self.logger.info(
1772 "Workflow Status: {} Workflow Message: {}".format(
1773 workflow_status, workflow_msg
1774 )
1775 )
yshah771dea82024-07-05 15:11:49 +00001776
1777 if workflow_status:
1778 db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1779 else:
1780 db_content["resourceState"] = "ERROR"
1781
1782 db_content = self.update_operation_history(db_content, workflow_status, None)
garciadeblas96b94f52024-07-08 16:18:21 +02001783 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001784
1785 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +01001786 resource_status, resource_msg = await self.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +02001787 "clone_ksus", op_id, op_params, db_content
yshah771dea82024-07-05 15:11:49 +00001788 )
garciadeblas96b94f52024-07-08 16:18:21 +02001789 self.logger.info(
1790 "Resource Status: {} Resource Message: {}".format(
1791 resource_status, resource_msg
1792 )
1793 )
yshah771dea82024-07-05 15:11:49 +00001794
1795 if resource_status:
1796 db_content["resourceState"] = "READY"
1797 else:
1798 db_content["resourceState"] = "ERROR"
1799
1800 db_content = self.update_operation_history(
1801 db_content, workflow_status, resource_status
1802 )
1803
1804 db_content["operatingState"] = "IDLE"
garciadeblas96b94f52024-07-08 16:18:21 +02001805 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001806 return
1807
garciadeblas96b94f52024-07-08 16:18:21 +02001808 async def move(self, op_id, op_params, db_content):
1809 self.logger.info("ksu move Enter")
yshah771dea82024-07-05 15:11:49 +00001810
garciadeblas869131a2024-11-08 01:11:46 +01001811 _, workflow_name = await self.odu.launch_workflow(
garciadeblas96b94f52024-07-08 16:18:21 +02001812 "move_ksus", op_id, op_params, db_content
1813 )
1814 workflow_status, workflow_msg = await self.odu.check_workflow_status(
1815 workflow_name
1816 )
1817 self.logger.info(
1818 "Workflow Status: {} Workflow Message: {}".format(
1819 workflow_status, workflow_msg
1820 )
1821 )
yshah771dea82024-07-05 15:11:49 +00001822
1823 if workflow_status:
1824 db_content["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
1825 else:
1826 db_content["resourceState"] = "ERROR"
1827
1828 db_content = self.update_operation_history(db_content, workflow_status, None)
garciadeblas96b94f52024-07-08 16:18:21 +02001829 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001830
1831 if workflow_status:
garciadeblas635b35a2024-11-07 12:41:54 +01001832 resource_status, resource_msg = await self.check_resource_status(
garciadeblas96b94f52024-07-08 16:18:21 +02001833 "move_ksus", op_id, op_params, db_content
yshah771dea82024-07-05 15:11:49 +00001834 )
garciadeblas96b94f52024-07-08 16:18:21 +02001835 self.logger.info(
1836 "Resource Status: {} Resource Message: {}".format(
1837 resource_status, resource_msg
1838 )
1839 )
yshah771dea82024-07-05 15:11:49 +00001840 if resource_status:
1841 db_content["resourceState"] = "READY"
1842 else:
1843 db_content["resourceState"] = "ERROR"
1844
1845 db_content = self.update_operation_history(
1846 db_content, workflow_status, resource_status
1847 )
1848
1849 db_content["operatingState"] = "IDLE"
garciadeblas96b94f52024-07-08 16:18:21 +02001850 self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
yshah771dea82024-07-05 15:11:49 +00001851 return