| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1 | ####################################################################################### |
| 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 | |
| 19 | import yaml |
| 20 | |
| 21 | |
| 22 | async def create_profile(self, op_id, op_params, content): |
| garciadeblas | 9e53281 | 2024-10-22 14:04:36 +0200 | [diff] [blame] | 23 | self.logger.info(f"create_profile Enter. Operation {op_id}. Params: {op_params}") |
| 24 | # self.logger.debug(f"Content: {content}") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 25 | |
| 26 | workflow_template = "launcher-create-profile.j2" |
| 27 | workflow_name = f"create-profile-{content['_id']}" |
| 28 | |
| 29 | # Additional params for the workflow |
| 30 | profile_name = content["git_name"].lower() |
| 31 | profile_type = content["profile_type"] |
| 32 | osm_project_name = "osm_admin" # TODO: get project name from content |
| 33 | |
| 34 | # Render workflow |
| 35 | manifest = self.render_jinja_template( |
| 36 | workflow_template, |
| 37 | output_file=None, |
| 38 | workflow_name=workflow_name, |
| garciadeblas | 56c3aa8 | 2025-05-26 15:29:46 +0200 | [diff] [blame] | 39 | git_fleet_url=self._repo_fleet_url, |
| 40 | git_sw_catalogs_url=self._repo_sw_catalogs_url, |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 41 | profile_name=profile_name, |
| 42 | profile_type=profile_type, |
| 43 | osm_project_name=osm_project_name, |
| 44 | workflow_debug=self._workflow_debug, |
| 45 | workflow_dry_run=self._workflow_dry_run, |
| 46 | ) |
| 47 | self.logger.info(manifest) |
| 48 | |
| 49 | # Submit workflow |
| 50 | self._kubectl.create_generic_object( |
| 51 | namespace="osm-workflows", |
| 52 | manifest_dict=yaml.safe_load(manifest), |
| 53 | api_group="argoproj.io", |
| 54 | api_plural="workflows", |
| 55 | api_version="v1alpha1", |
| 56 | ) |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 57 | return True, workflow_name |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 58 | |
| 59 | |
| 60 | async def delete_profile(self, op_id, op_params, content): |
| garciadeblas | 9e53281 | 2024-10-22 14:04:36 +0200 | [diff] [blame] | 61 | self.logger.info(f"delete_profile Enter. Operation {op_id}. Params: {op_params}") |
| 62 | # self.logger.debug(f"Content: {content}") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 63 | |
| 64 | workflow_template = "launcher-delete-profile.j2" |
| 65 | workflow_name = f"delete-profile-{content['_id']}" |
| 66 | |
| 67 | # Additional params for the workflow |
| 68 | profile_name = content["git_name"].lower() |
| 69 | profile_type = content["profile_type"] |
| 70 | osm_project_name = "osm_admin" # TODO: get project name from content |
| 71 | |
| 72 | # Render workflow |
| 73 | manifest = self.render_jinja_template( |
| 74 | workflow_template, |
| 75 | output_file=None, |
| 76 | workflow_name=workflow_name, |
| garciadeblas | 56c3aa8 | 2025-05-26 15:29:46 +0200 | [diff] [blame] | 77 | git_fleet_url=self._repo_fleet_url, |
| 78 | git_sw_catalogs_url=self._repo_sw_catalogs_url, |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 79 | profile_name=profile_name, |
| 80 | profile_type=profile_type, |
| 81 | osm_project_name=osm_project_name, |
| 82 | workflow_debug=self._workflow_debug, |
| 83 | workflow_dry_run=self._workflow_dry_run, |
| 84 | ) |
| 85 | self.logger.info(manifest) |
| 86 | |
| 87 | # Submit workflow |
| 88 | self._kubectl.create_generic_object( |
| 89 | namespace="osm-workflows", |
| 90 | manifest_dict=yaml.safe_load(manifest), |
| 91 | api_group="argoproj.io", |
| 92 | api_plural="workflows", |
| 93 | api_version="v1alpha1", |
| 94 | ) |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 95 | return True, workflow_name |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 96 | |
| 97 | |
| 98 | async def attach_profile_to_cluster(self, op_id, op_params, content): |
| garciadeblas | 9e53281 | 2024-10-22 14:04:36 +0200 | [diff] [blame] | 99 | self.logger.info( |
| 100 | f"attach_profile_to_cluster Enter. Operation {op_id}. Params: {op_params}" |
| 101 | ) |
| 102 | # self.logger.debug(f"Content: {content}") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 103 | |
| 104 | profile = content["profile"] |
| 105 | cluster = content["cluster"] |
| 106 | workflow_template = "launcher-attach-profile.j2" |
| 107 | workflow_name = f"attach-profile-{op_id}" |
| 108 | |
| 109 | # Additional params for the workflow |
| 110 | profile_name = profile["git_name"].lower() |
| 111 | profile_type = profile["profile_type"] |
| 112 | cluster_kustomization_name = cluster["git_name"].lower() |
| 113 | osm_project_name = "osm_admin" # TODO: get project name from content |
| 114 | |
| 115 | # Render workflow |
| 116 | manifest = self.render_jinja_template( |
| 117 | workflow_template, |
| 118 | output_file=None, |
| 119 | workflow_name=workflow_name, |
| garciadeblas | 56c3aa8 | 2025-05-26 15:29:46 +0200 | [diff] [blame] | 120 | git_fleet_url=self._repo_fleet_url, |
| 121 | git_sw_catalogs_url=self._repo_sw_catalogs_url, |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 122 | profile_name=profile_name, |
| 123 | profile_type=profile_type, |
| 124 | cluster_kustomization_name=cluster_kustomization_name, |
| 125 | osm_project_name=osm_project_name, |
| 126 | workflow_debug=self._workflow_debug, |
| 127 | workflow_dry_run=self._workflow_dry_run, |
| 128 | ) |
| 129 | self.logger.info(manifest) |
| 130 | |
| 131 | # Submit workflow |
| 132 | self._kubectl.create_generic_object( |
| 133 | namespace="osm-workflows", |
| 134 | manifest_dict=yaml.safe_load(manifest), |
| 135 | api_group="argoproj.io", |
| 136 | api_plural="workflows", |
| 137 | api_version="v1alpha1", |
| 138 | ) |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 139 | return True, workflow_name |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 140 | |
| 141 | |
| 142 | async def detach_profile_from_cluster(self, op_id, op_params, content): |
| garciadeblas | 9e53281 | 2024-10-22 14:04:36 +0200 | [diff] [blame] | 143 | self.logger.info( |
| 144 | f"detach_profile_from_cluster Enter. Operation {op_id}. Params: {op_params}" |
| 145 | ) |
| 146 | # self.logger.debug(f"Content: {content}") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 147 | |
| 148 | profile = content["profile"] |
| 149 | cluster = content["cluster"] |
| 150 | workflow_template = "launcher-detach-profile.j2" |
| 151 | workflow_name = f"detach-profile-{op_id}" |
| 152 | |
| 153 | # Additional params for the workflow |
| 154 | # Additional params for the workflow |
| 155 | profile_name = profile["git_name"].lower() |
| 156 | profile_type = profile["profile_type"] |
| 157 | cluster_kustomization_name = cluster["git_name"].lower() |
| 158 | osm_project_name = "osm_admin" # TODO: get project name from content |
| 159 | |
| 160 | # Render workflow |
| 161 | manifest = self.render_jinja_template( |
| 162 | workflow_template, |
| 163 | output_file=None, |
| 164 | workflow_name=workflow_name, |
| garciadeblas | 56c3aa8 | 2025-05-26 15:29:46 +0200 | [diff] [blame] | 165 | git_fleet_url=self._repo_fleet_url, |
| 166 | git_sw_catalogs_url=self._repo_sw_catalogs_url, |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 167 | profile_name=profile_name, |
| 168 | profile_type=profile_type, |
| 169 | cluster_kustomization_name=cluster_kustomization_name, |
| 170 | osm_project_name=osm_project_name, |
| 171 | workflow_debug=self._workflow_debug, |
| 172 | workflow_dry_run=self._workflow_dry_run, |
| 173 | ) |
| 174 | self.logger.info(manifest) |
| 175 | |
| 176 | # Submit workflow |
| 177 | self._kubectl.create_generic_object( |
| 178 | namespace="osm-workflows", |
| 179 | manifest_dict=yaml.safe_load(manifest), |
| 180 | api_group="argoproj.io", |
| 181 | api_plural="workflows", |
| 182 | api_version="v1alpha1", |
| 183 | ) |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 184 | return True, workflow_name |