blob: 62207a300d3c6fa25d9523074390d6a378123fc2 [file] [log] [blame]
garciadeblas96b94f52024-07-08 16:18:21 +02001#######################################################################################
2# Copyright ETSI Contributors and Others.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13# implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#######################################################################################
17
18
19import yaml
garciadeblas96b94f52024-07-08 16:18:21 +020020
21
22async def create_oka(self, op_id, op_params, content):
garciadeblas9e532812024-10-22 14:04:36 +020023 self.logger.info(f"create_oka Enter. Operation {op_id}. Params: {op_params}")
24 # self.logger.debug(f"Content: {content}")
garciadeblas96b94f52024-07-08 16:18:21 +020025
26 workflow_template = "launcher-create-oka.j2"
27 workflow_name = f"create-oka-{content['_id']}"
28
29 # Additional params for the workflow
30 oka_name = content["git_name"].lower()
31 oka_type = "infra-controllers"
32 osm_project_name = "osm_admin" # TODO: get project name from content
33
34 # Get the OKA package
35 oka_fs_info = content["_admin"]["storage"]
36 oka_folder = f"{oka_fs_info['path']}{oka_fs_info['folder']}"
37 oka_filename = oka_fs_info["zipfile"]
38 self.fs.sync(oka_folder)
garciadeblase059eb62024-09-24 14:48:12 +020039 self.logger.info("OKA Folder: {} OKA filename: {}".format(oka_folder, oka_filename))
40 # TODO: check if file exists
41 # if not self.fs.file_exists(f"{oka_folder}/{oka_filename}"):
42 # raise LcmException(message="Not able to find oka", bad_args=["oka_path"])
43 self.logger.debug("Processing....")
garciadeblas96b94f52024-07-08 16:18:21 +020044
45 # Create temporary volume for the OKA package and copy the content
46 temp_volume_name = f"temp-pvc-oka-{op_id}"
47 await self._kubectl.create_pvc_with_content(
48 name=temp_volume_name,
49 namespace="osm-workflows",
garciadeblase059eb62024-09-24 14:48:12 +020050 src_file=f"{oka_folder}/{oka_filename}",
51 dest_filename=f"{oka_name}.tar.gz",
garciadeblas96b94f52024-07-08 16:18:21 +020052 )
53
54 # Render workflow
55 manifest = self.render_jinja_template(
56 workflow_template,
57 output_file=None,
58 workflow_name=workflow_name,
59 git_fleet_url=f"{self._repo_base_url}/{self._repo_user}/fleet-osm.git",
60 git_sw_catalogs_url=f"{self._repo_base_url}/{self._repo_user}/sw-catalogs-osm.git",
61 oka_name=oka_name,
62 oka_type=oka_type,
63 osm_project_name=osm_project_name,
64 temp_volume_name=temp_volume_name,
65 workflow_debug=self._workflow_debug,
66 workflow_dry_run=self._workflow_dry_run,
67 )
68 self.logger.info(manifest)
69
70 # Submit workflow
71 self._kubectl.create_generic_object(
72 namespace="osm-workflows",
73 manifest_dict=yaml.safe_load(manifest),
74 api_group="argoproj.io",
75 api_plural="workflows",
76 api_version="v1alpha1",
77 )
garciadeblasadb81e82024-11-08 01:11:46 +010078 return True, workflow_name
garciadeblas96b94f52024-07-08 16:18:21 +020079
80
81async def update_oka(self, op_id, op_params, content):
garciadeblas9e532812024-10-22 14:04:36 +020082 self.logger.info(f"update_oka Enter. Operation {op_id}. Params: {op_params}")
83 # self.logger.debug(f"Content: {content}")
garciadeblas96b94f52024-07-08 16:18:21 +020084
85 workflow_template = "launcher-update-oka.j2"
86 workflow_name = f"update-oka-{content['_id']}"
87
88 # Additional params for the workflow
89 oka_name = content["git_name"].lower()
90 oka_type = "infra-controllers"
91 osm_project_name = "osm_admin" # TODO: get project name from content
92
93 # Get the OKA package
94 oka_fs_info = content["_admin"]["storage"]
95 oka_folder = (
96 f"{oka_fs_info['path']}/{oka_fs_info['folder']}/{oka_fs_info['zipfile']}"
97 )
98 oka_filename = "package.tar.gz"
99 # Sync fs?
100
101 # Create temporary volume for the OKA package and copy the content
102 temp_volume_name = f"temp-pvc-oka-{op_id}"
103 await self._kubectl.create_pvc_with_content(
104 name=temp_volume_name,
105 namespace="osm-workflows",
106 src_folder=oka_folder,
107 filename=oka_filename,
108 )
109
110 # Render workflow
111 manifest = self.render_jinja_template(
112 workflow_template,
113 output_file=None,
114 workflow_name=workflow_name,
115 git_fleet_url=f"{self._repo_base_url}/{self._repo_user}/fleet-osm.git",
116 git_sw_catalogs_url=f"{self._repo_base_url}/{self._repo_user}/sw-catalogs-osm.git",
117 oka_name=oka_name,
118 oka_type=oka_type,
119 osm_project_name=osm_project_name,
120 temp_volume_name=temp_volume_name,
121 workflow_debug=self._workflow_debug,
122 workflow_dry_run=self._workflow_dry_run,
123 )
124 self.logger.info(manifest)
125
126 # Submit workflow
127 self._kubectl.create_generic_object(
128 namespace="osm-workflows",
129 manifest_dict=yaml.safe_load(manifest),
130 api_group="argoproj.io",
131 api_plural="workflows",
132 api_version="v1alpha1",
133 )
garciadeblasadb81e82024-11-08 01:11:46 +0100134 return True, workflow_name
garciadeblas96b94f52024-07-08 16:18:21 +0200135
136
137async def delete_oka(self, op_id, op_params, content):
garciadeblas9e532812024-10-22 14:04:36 +0200138 self.logger.info(f"delete_oka Enter. Operation {op_id}. Params: {op_params}")
139 # self.logger.debug(f"Content: {content}")
garciadeblas96b94f52024-07-08 16:18:21 +0200140
141 workflow_template = "launcher-delete-oka.j2"
142 workflow_name = f"delete-oka-{content['_id']}"
143
144 # Additional params for the workflow
145 oka_name = content["git_name"].lower()
146 oka_type = "infra-controllers"
147 osm_project_name = "osm_admin" # TODO: get project name from content
148
149 # Render workflow
150 manifest = self.render_jinja_template(
151 workflow_template,
152 output_file=None,
153 workflow_name=workflow_name,
154 git_fleet_url=f"{self._repo_base_url}/{self._repo_user}/fleet-osm.git",
155 git_sw_catalogs_url=f"{self._repo_base_url}/{self._repo_user}/sw-catalogs-osm.git",
156 oka_name=oka_name,
157 oka_type=oka_type,
158 osm_project_name=osm_project_name,
159 workflow_debug=self._workflow_debug,
160 workflow_dry_run=self._workflow_dry_run,
161 )
162 self.logger.info(manifest)
163
164 # Submit workflow
165 self._kubectl.create_generic_object(
166 namespace="osm-workflows",
167 manifest_dict=yaml.safe_load(manifest),
168 api_group="argoproj.io",
169 api_plural="workflows",
170 api_version="v1alpha1",
171 )
garciadeblasadb81e82024-11-08 01:11:46 +0100172 return True, workflow_name