| sousaedu | ccfacbb | 2020-11-04 21:44:01 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 2 | # Copyright 2021 Canonical Ltd. |
| sousaedu | ccfacbb | 2020-11-04 21:44:01 +0000 | [diff] [blame] | 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # 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, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | # |
| 16 | # For those usages not covered by the Apache License, Version 2.0 please |
| 17 | # contact: legal@canonical.com |
| 18 | # |
| 19 | # To get in touch with the maintainers, please contact: |
| 20 | # osm-charmers@lists.launchpad.net |
| 21 | ## |
| 22 | |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 23 | # pylint: disable=E0213 |
| 24 | |
| David Garcia | 5d1ec6e | 2021-03-25 15:04:52 +0100 | [diff] [blame] | 25 | import base64 |
| sousaedu | ccfacbb | 2020-11-04 21:44:01 +0000 | [diff] [blame] | 26 | import logging |
| David Garcia | cafe31e | 2021-11-18 16:45:05 +0100 | [diff] [blame] | 27 | from typing import Dict, NoReturn, Optional |
| sousaedu | ccfacbb | 2020-11-04 21:44:01 +0000 | [diff] [blame] | 28 | |
| David Garcia | 4a0db7c | 2022-02-21 11:48:11 +0100 | [diff] [blame] | 29 | from charms.kafka_k8s.v0.kafka import KafkaEvents, KafkaRequires |
| sousaedu | ccfacbb | 2020-11-04 21:44:01 +0000 | [diff] [blame] | 30 | from ops.main import main |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 31 | from opslib.osm.charm import CharmedOsmBase, RelationsMissing |
| David Garcia | c753dc5 | 2021-03-17 15:28:47 +0100 | [diff] [blame] | 32 | from opslib.osm.interfaces.mongo import MongoClient |
| 33 | from opslib.osm.interfaces.mysql import MysqlClient |
| David Garcia | 141d935 | 2021-09-08 17:48:40 +0200 | [diff] [blame] | 34 | from opslib.osm.pod import ( |
| 35 | ContainerV3Builder, |
| 36 | FilesV3Builder, |
| 37 | PodRestartPolicy, |
| 38 | PodSpecV3Builder, |
| 39 | ) |
| David Garcia | c753dc5 | 2021-03-17 15:28:47 +0100 | [diff] [blame] | 40 | from opslib.osm.validator import ModelValidator, validator |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 41 | |
| sousaedu | ccfacbb | 2020-11-04 21:44:01 +0000 | [diff] [blame] | 42 | logger = logging.getLogger(__name__) |
| 43 | |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 44 | PORT = 9090 |
| sousaedu | ccfacbb | 2020-11-04 21:44:01 +0000 | [diff] [blame] | 45 | |
| 46 | |
| David Garcia | 5d1ec6e | 2021-03-25 15:04:52 +0100 | [diff] [blame] | 47 | def _check_certificate_data(name: str, content: str): |
| 48 | if not name or not content: |
| 49 | raise ValueError("certificate name and content must be a non-empty string") |
| 50 | |
| 51 | |
| 52 | def _extract_certificates(certs_config: str): |
| 53 | certificates = {} |
| 54 | if certs_config: |
| 55 | cert_list = certs_config.split(",") |
| 56 | for cert in cert_list: |
| 57 | name, content = cert.split(":") |
| 58 | _check_certificate_data(name, content) |
| 59 | certificates[name] = content |
| 60 | return certificates |
| 61 | |
| 62 | |
| 63 | def decode(content: str): |
| 64 | return base64.b64decode(content.encode("utf-8")).decode("utf-8") |
| 65 | |
| 66 | |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 67 | class ConfigModel(ModelValidator): |
| 68 | enable_ng_ro: bool |
| 69 | database_commonkey: str |
| sousaedu | 996a560 | 2021-05-03 00:22:43 +0200 | [diff] [blame] | 70 | mongodb_uri: Optional[str] |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 71 | log_level: str |
| sousaedu | 996a560 | 2021-05-03 00:22:43 +0200 | [diff] [blame] | 72 | mysql_host: Optional[str] |
| 73 | mysql_port: Optional[int] |
| 74 | mysql_user: Optional[str] |
| 75 | mysql_password: Optional[str] |
| 76 | mysql_root_password: Optional[str] |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 77 | vim_database: str |
| 78 | ro_database: str |
| 79 | openmano_tenant: str |
| David Garcia | 5d1ec6e | 2021-03-25 15:04:52 +0100 | [diff] [blame] | 80 | certificates: Optional[str] |
| sousaedu | 0dc25b3 | 2021-08-30 16:33:33 +0100 | [diff] [blame] | 81 | image_pull_policy: str |
| sousaedu | 540d937 | 2021-09-29 01:53:30 +0100 | [diff] [blame] | 82 | debug_mode: bool |
| 83 | security_context: bool |
| aticig | bd32485 | 2022-06-30 03:50:07 +0300 | [diff] [blame] | 84 | period_refresh_active: Optional[int] |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 85 | |
| 86 | @validator("log_level") |
| 87 | def validate_log_level(cls, v): |
| 88 | if v not in {"INFO", "DEBUG"}: |
| 89 | raise ValueError("value must be INFO or DEBUG") |
| 90 | return v |
| sousaedu | ccfacbb | 2020-11-04 21:44:01 +0000 | [diff] [blame] | 91 | |
| David Garcia | 5d1ec6e | 2021-03-25 15:04:52 +0100 | [diff] [blame] | 92 | @validator("certificates") |
| 93 | def validate_certificates(cls, v): |
| 94 | # Raises an exception if it cannot extract the certificates |
| 95 | _extract_certificates(v) |
| 96 | return v |
| 97 | |
| sousaedu | 996a560 | 2021-05-03 00:22:43 +0200 | [diff] [blame] | 98 | @validator("mongodb_uri") |
| 99 | def validate_mongodb_uri(cls, v): |
| 100 | if v and not v.startswith("mongodb://"): |
| 101 | raise ValueError("mongodb_uri is not properly formed") |
| 102 | return v |
| 103 | |
| 104 | @validator("mysql_port") |
| 105 | def validate_mysql_port(cls, v): |
| 106 | if v and (v <= 0 or v >= 65535): |
| 107 | raise ValueError("Mysql port out of range") |
| 108 | return v |
| 109 | |
| sousaedu | 3ddbbd1 | 2021-08-24 19:57:24 +0100 | [diff] [blame] | 110 | @validator("image_pull_policy") |
| 111 | def validate_image_pull_policy(cls, v): |
| 112 | values = { |
| 113 | "always": "Always", |
| 114 | "ifnotpresent": "IfNotPresent", |
| 115 | "never": "Never", |
| 116 | } |
| 117 | v = v.lower() |
| 118 | if v not in values.keys(): |
| 119 | raise ValueError("value must be always, ifnotpresent or never") |
| 120 | return values[v] |
| 121 | |
| David Garcia | 5d1ec6e | 2021-03-25 15:04:52 +0100 | [diff] [blame] | 122 | @property |
| 123 | def certificates_dict(cls): |
| 124 | return _extract_certificates(cls.certificates) if cls.certificates else {} |
| 125 | |
| aticig | bd32485 | 2022-06-30 03:50:07 +0300 | [diff] [blame] | 126 | @validator("period_refresh_active") |
| 127 | def validate_vim_refresh_period(cls, v): |
| 128 | if v and v < 60 and v != -1: |
| 129 | raise ValueError( |
| 130 | "Refresh Period is too tight, insert >= 60 seconds or disable using -1" |
| 131 | ) |
| 132 | return v |
| 133 | |
| sousaedu | ccfacbb | 2020-11-04 21:44:01 +0000 | [diff] [blame] | 134 | |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 135 | class RoCharm(CharmedOsmBase): |
| 136 | """GrafanaCharm Charm.""" |
| sousaedu | ccfacbb | 2020-11-04 21:44:01 +0000 | [diff] [blame] | 137 | |
| David Garcia | 4a0db7c | 2022-02-21 11:48:11 +0100 | [diff] [blame] | 138 | on = KafkaEvents() |
| 139 | |
| sousaedu | ccfacbb | 2020-11-04 21:44:01 +0000 | [diff] [blame] | 140 | def __init__(self, *args) -> NoReturn: |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 141 | """Prometheus Charm constructor.""" |
| David Garcia | d680be4 | 2021-08-17 11:03:55 +0200 | [diff] [blame] | 142 | super().__init__( |
| 143 | *args, |
| 144 | oci_image="image", |
| David Garcia | d680be4 | 2021-08-17 11:03:55 +0200 | [diff] [blame] | 145 | vscode_workspace=VSCODE_WORKSPACE, |
| 146 | ) |
| David Garcia | cafe31e | 2021-11-18 16:45:05 +0100 | [diff] [blame] | 147 | if self.config.get("debug_mode"): |
| 148 | self.enable_debug_mode( |
| 149 | pubkey=self.config.get("debug_pubkey"), |
| 150 | hostpaths={ |
| 151 | "osm_common": { |
| 152 | "hostpath": self.config.get("debug_common_local_path"), |
| 153 | "container-path": "/usr/lib/python3/dist-packages/osm_common", |
| 154 | }, |
| 155 | **_get_ro_host_paths(self.config.get("debug_ro_local_path")), |
| 156 | }, |
| 157 | ) |
| David Garcia | 4a0db7c | 2022-02-21 11:48:11 +0100 | [diff] [blame] | 158 | self.kafka = KafkaRequires(self) |
| 159 | self.framework.observe(self.on.kafka_available, self.configure_pod) |
| 160 | self.framework.observe(self.on.kafka_broken, self.configure_pod) |
| sousaedu | ccfacbb | 2020-11-04 21:44:01 +0000 | [diff] [blame] | 161 | |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 162 | self.mysql_client = MysqlClient(self, "mysql") |
| 163 | self.framework.observe(self.on["mysql"].relation_changed, self.configure_pod) |
| 164 | self.framework.observe(self.on["mysql"].relation_broken, self.configure_pod) |
| sousaedu | ccfacbb | 2020-11-04 21:44:01 +0000 | [diff] [blame] | 165 | |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 166 | self.mongodb_client = MongoClient(self, "mongodb") |
| 167 | self.framework.observe(self.on["mongodb"].relation_changed, self.configure_pod) |
| 168 | self.framework.observe(self.on["mongodb"].relation_broken, self.configure_pod) |
| sousaedu | ccfacbb | 2020-11-04 21:44:01 +0000 | [diff] [blame] | 169 | |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 170 | self.framework.observe(self.on["ro"].relation_joined, self._publish_ro_info) |
| sousaedu | ccfacbb | 2020-11-04 21:44:01 +0000 | [diff] [blame] | 171 | |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 172 | def _publish_ro_info(self, event): |
| sousaedu | ccfacbb | 2020-11-04 21:44:01 +0000 | [diff] [blame] | 173 | """Publishes RO information. |
| 174 | |
| 175 | Args: |
| 176 | event (EventBase): RO relation event. |
| 177 | """ |
| 178 | if self.unit.is_leader(): |
| 179 | rel_data = { |
| 180 | "host": self.model.app.name, |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 181 | "port": str(PORT), |
| sousaedu | ccfacbb | 2020-11-04 21:44:01 +0000 | [diff] [blame] | 182 | } |
| 183 | for k, v in rel_data.items(): |
| 184 | event.relation.data[self.app][k] = v |
| 185 | |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 186 | def _check_missing_dependencies(self, config: ConfigModel): |
| 187 | missing_relations = [] |
| 188 | |
| 189 | if config.enable_ng_ro: |
| David Garcia | 4a0db7c | 2022-02-21 11:48:11 +0100 | [diff] [blame] | 190 | if not self.kafka.host or not self.kafka.port: |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 191 | missing_relations.append("kafka") |
| sousaedu | 996a560 | 2021-05-03 00:22:43 +0200 | [diff] [blame] | 192 | if not config.mongodb_uri and self.mongodb_client.is_missing_data_in_unit(): |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 193 | missing_relations.append("mongodb") |
| sousaedu | ccfacbb | 2020-11-04 21:44:01 +0000 | [diff] [blame] | 194 | else: |
| sousaedu | 996a560 | 2021-05-03 00:22:43 +0200 | [diff] [blame] | 195 | if not config.mysql_host and self.mysql_client.is_missing_data_in_unit(): |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 196 | missing_relations.append("mysql") |
| 197 | if missing_relations: |
| 198 | raise RelationsMissing(missing_relations) |
| sousaedu | ccfacbb | 2020-11-04 21:44:01 +0000 | [diff] [blame] | 199 | |
| sousaedu | 996a560 | 2021-05-03 00:22:43 +0200 | [diff] [blame] | 200 | def _validate_mysql_config(self, config: ConfigModel): |
| 201 | invalid_values = [] |
| 202 | if not config.mysql_user: |
| 203 | invalid_values.append("Mysql user is empty") |
| 204 | if not config.mysql_password: |
| 205 | invalid_values.append("Mysql password is empty") |
| 206 | if not config.mysql_root_password: |
| 207 | invalid_values.append("Mysql root password empty") |
| 208 | |
| 209 | if invalid_values: |
| 210 | raise ValueError("Invalid values: " + ", ".join(invalid_values)) |
| 211 | |
| David Garcia | 5d1ec6e | 2021-03-25 15:04:52 +0100 | [diff] [blame] | 212 | def _build_cert_files( |
| 213 | self, |
| 214 | config: ConfigModel, |
| 215 | ): |
| 216 | cert_files_builder = FilesV3Builder() |
| 217 | for name, content in config.certificates_dict.items(): |
| 218 | cert_files_builder.add_file(name, decode(content), mode=0o600) |
| 219 | return cert_files_builder.build() |
| 220 | |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 221 | def build_pod_spec(self, image_info): |
| 222 | # Validate config |
| 223 | config = ConfigModel(**dict(self.config)) |
| sousaedu | 996a560 | 2021-05-03 00:22:43 +0200 | [diff] [blame] | 224 | |
| 225 | if config.enable_ng_ro: |
| 226 | if config.mongodb_uri and not self.mongodb_client.is_missing_data_in_unit(): |
| 227 | raise Exception( |
| 228 | "Mongodb data cannot be provided via config and relation" |
| 229 | ) |
| 230 | else: |
| 231 | if config.mysql_host and not self.mysql_client.is_missing_data_in_unit(): |
| 232 | raise Exception("Mysql data cannot be provided via config and relation") |
| 233 | |
| 234 | if config.mysql_host: |
| 235 | self._validate_mysql_config(config) |
| 236 | |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 237 | # Check relations |
| 238 | self._check_missing_dependencies(config) |
| sousaedu | 996a560 | 2021-05-03 00:22:43 +0200 | [diff] [blame] | 239 | |
| sousaedu | 540d937 | 2021-09-29 01:53:30 +0100 | [diff] [blame] | 240 | security_context_enabled = ( |
| 241 | config.security_context if not config.debug_mode else False |
| 242 | ) |
| 243 | |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 244 | # Create Builder for the PodSpec |
| sousaedu | 540d937 | 2021-09-29 01:53:30 +0100 | [diff] [blame] | 245 | pod_spec_builder = PodSpecV3Builder( |
| 246 | enable_security_context=security_context_enabled |
| 247 | ) |
| sousaedu | 996a560 | 2021-05-03 00:22:43 +0200 | [diff] [blame] | 248 | |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 249 | # Build Container |
| sousaedu | 3ddbbd1 | 2021-08-24 19:57:24 +0100 | [diff] [blame] | 250 | container_builder = ContainerV3Builder( |
| sousaedu | 540d937 | 2021-09-29 01:53:30 +0100 | [diff] [blame] | 251 | self.app.name, |
| 252 | image_info, |
| 253 | config.image_pull_policy, |
| 254 | run_as_non_root=security_context_enabled, |
| sousaedu | 3ddbbd1 | 2021-08-24 19:57:24 +0100 | [diff] [blame] | 255 | ) |
| David Garcia | 5d1ec6e | 2021-03-25 15:04:52 +0100 | [diff] [blame] | 256 | certs_files = self._build_cert_files(config) |
| sousaedu | 996a560 | 2021-05-03 00:22:43 +0200 | [diff] [blame] | 257 | |
| David Garcia | 5d1ec6e | 2021-03-25 15:04:52 +0100 | [diff] [blame] | 258 | if certs_files: |
| 259 | container_builder.add_volume_config("certs", "/certs", certs_files) |
| sousaedu | 996a560 | 2021-05-03 00:22:43 +0200 | [diff] [blame] | 260 | |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 261 | container_builder.add_port(name=self.app.name, port=PORT) |
| 262 | container_builder.add_http_readiness_probe( |
| 263 | "/ro/" if config.enable_ng_ro else "/openmano/tenants", |
| 264 | PORT, |
| 265 | initial_delay_seconds=10, |
| 266 | period_seconds=10, |
| 267 | timeout_seconds=5, |
| 268 | failure_threshold=3, |
| 269 | ) |
| 270 | container_builder.add_http_liveness_probe( |
| 271 | "/ro/" if config.enable_ng_ro else "/openmano/tenants", |
| 272 | PORT, |
| 273 | initial_delay_seconds=600, |
| 274 | period_seconds=10, |
| 275 | timeout_seconds=5, |
| 276 | failure_threshold=3, |
| 277 | ) |
| 278 | container_builder.add_envs( |
| 279 | { |
| 280 | "OSMRO_LOG_LEVEL": config.log_level, |
| 281 | } |
| 282 | ) |
| aticig | bd32485 | 2022-06-30 03:50:07 +0300 | [diff] [blame] | 283 | if config.period_refresh_active: |
| 284 | container_builder.add_envs( |
| 285 | { |
| 286 | "OSMRO_PERIOD_REFRESH_ACTIVE": config.period_refresh_active, |
| 287 | } |
| 288 | ) |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 289 | if config.enable_ng_ro: |
| David Garcia | 141d935 | 2021-09-08 17:48:40 +0200 | [diff] [blame] | 290 | # Add secrets to the pod |
| 291 | mongodb_secret_name = f"{self.app.name}-mongodb-secret" |
| 292 | pod_spec_builder.add_secret( |
| 293 | mongodb_secret_name, |
| 294 | { |
| 295 | "uri": config.mongodb_uri or self.mongodb_client.connection_string, |
| 296 | "commonkey": config.database_commonkey, |
| 297 | }, |
| 298 | ) |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 299 | container_builder.add_envs( |
| 300 | { |
| 301 | "OSMRO_MESSAGE_DRIVER": "kafka", |
| David Garcia | 4a0db7c | 2022-02-21 11:48:11 +0100 | [diff] [blame] | 302 | "OSMRO_MESSAGE_HOST": self.kafka.host, |
| 303 | "OSMRO_MESSAGE_PORT": self.kafka.port, |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 304 | # MongoDB configuration |
| 305 | "OSMRO_DATABASE_DRIVER": "mongo", |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 306 | } |
| sousaedu | ccfacbb | 2020-11-04 21:44:01 +0000 | [diff] [blame] | 307 | ) |
| David Garcia | 141d935 | 2021-09-08 17:48:40 +0200 | [diff] [blame] | 308 | container_builder.add_secret_envs( |
| 309 | secret_name=mongodb_secret_name, |
| 310 | envs={ |
| 311 | "OSMRO_DATABASE_URI": "uri", |
| 312 | "OSMRO_DATABASE_COMMONKEY": "commonkey", |
| 313 | }, |
| 314 | ) |
| 315 | restart_policy = PodRestartPolicy() |
| 316 | restart_policy.add_secrets(secret_names=(mongodb_secret_name,)) |
| 317 | pod_spec_builder.set_restart_policy(restart_policy) |
| sousaedu | ccfacbb | 2020-11-04 21:44:01 +0000 | [diff] [blame] | 318 | |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 319 | else: |
| 320 | container_builder.add_envs( |
| 321 | { |
| sousaedu | 996a560 | 2021-05-03 00:22:43 +0200 | [diff] [blame] | 322 | "RO_DB_HOST": config.mysql_host or self.mysql_client.host, |
| 323 | "RO_DB_OVIM_HOST": config.mysql_host or self.mysql_client.host, |
| 324 | "RO_DB_PORT": config.mysql_port or self.mysql_client.port, |
| 325 | "RO_DB_OVIM_PORT": config.mysql_port or self.mysql_client.port, |
| 326 | "RO_DB_USER": config.mysql_user or self.mysql_client.user, |
| 327 | "RO_DB_OVIM_USER": config.mysql_user or self.mysql_client.user, |
| 328 | "RO_DB_PASSWORD": config.mysql_password |
| 329 | or self.mysql_client.password, |
| 330 | "RO_DB_OVIM_PASSWORD": config.mysql_password |
| 331 | or self.mysql_client.password, |
| 332 | "RO_DB_ROOT_PASSWORD": config.mysql_root_password |
| 333 | or self.mysql_client.root_password, |
| 334 | "RO_DB_OVIM_ROOT_PASSWORD": config.mysql_root_password |
| 335 | or self.mysql_client.root_password, |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 336 | "RO_DB_NAME": config.ro_database, |
| 337 | "RO_DB_OVIM_NAME": config.vim_database, |
| 338 | "OPENMANO_TENANT": config.openmano_tenant, |
| 339 | } |
| 340 | ) |
| 341 | container = container_builder.build() |
| sousaedu | 996a560 | 2021-05-03 00:22:43 +0200 | [diff] [blame] | 342 | |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 343 | # Add container to pod spec |
| 344 | pod_spec_builder.add_container(container) |
| sousaedu | 996a560 | 2021-05-03 00:22:43 +0200 | [diff] [blame] | 345 | |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 346 | return pod_spec_builder.build() |
| sousaedu | ccfacbb | 2020-11-04 21:44:01 +0000 | [diff] [blame] | 347 | |
| 348 | |
| David Garcia | d680be4 | 2021-08-17 11:03:55 +0200 | [diff] [blame] | 349 | VSCODE_WORKSPACE = { |
| 350 | "folders": [ |
| 351 | {"path": "/usr/lib/python3/dist-packages/osm_ng_ro"}, |
| 352 | {"path": "/usr/lib/python3/dist-packages/osm_common"}, |
| 353 | {"path": "/usr/lib/python3/dist-packages/osm_ro_plugin"}, |
| 354 | {"path": "/usr/lib/python3/dist-packages/osm_rosdn_arista_cloudvision"}, |
| 355 | {"path": "/usr/lib/python3/dist-packages/osm_rosdn_dpb"}, |
| 356 | {"path": "/usr/lib/python3/dist-packages/osm_rosdn_dynpac"}, |
| 357 | {"path": "/usr/lib/python3/dist-packages/osm_rosdn_floodlightof"}, |
| 358 | {"path": "/usr/lib/python3/dist-packages/osm_rosdn_ietfl2vpn"}, |
| 359 | {"path": "/usr/lib/python3/dist-packages/osm_rosdn_juniper_contrail"}, |
| 360 | {"path": "/usr/lib/python3/dist-packages/osm_rosdn_odlof"}, |
| 361 | {"path": "/usr/lib/python3/dist-packages/osm_rosdn_onos_vpls"}, |
| 362 | {"path": "/usr/lib/python3/dist-packages/osm_rosdn_onosof"}, |
| 363 | {"path": "/usr/lib/python3/dist-packages/osm_rovim_aws"}, |
| 364 | {"path": "/usr/lib/python3/dist-packages/osm_rovim_azure"}, |
| garciadeblas | f854a61 | 2021-11-09 23:30:47 +0100 | [diff] [blame] | 365 | {"path": "/usr/lib/python3/dist-packages/osm_rovim_gcp"}, |
| David Garcia | d680be4 | 2021-08-17 11:03:55 +0200 | [diff] [blame] | 366 | {"path": "/usr/lib/python3/dist-packages/osm_rovim_openstack"}, |
| 367 | {"path": "/usr/lib/python3/dist-packages/osm_rovim_openvim"}, |
| 368 | {"path": "/usr/lib/python3/dist-packages/osm_rovim_vmware"}, |
| 369 | ], |
| 370 | "launch": { |
| 371 | "configurations": [ |
| 372 | { |
| 373 | "module": "osm_ng_ro.ro_main", |
| 374 | "name": "NG RO", |
| 375 | "request": "launch", |
| 376 | "type": "python", |
| 377 | "justMyCode": False, |
| 378 | } |
| 379 | ], |
| 380 | "version": "0.2.0", |
| 381 | }, |
| 382 | "settings": {}, |
| 383 | } |
| 384 | |
| David Garcia | cafe31e | 2021-11-18 16:45:05 +0100 | [diff] [blame] | 385 | |
| 386 | def _get_ro_host_paths(ro_host_path: str) -> Dict: |
| 387 | """Get RO host paths""" |
| 388 | return ( |
| 389 | { |
| 390 | "NG-RO": { |
| 391 | "hostpath": f"{ro_host_path}/NG-RO", |
| 392 | "container-path": "/usr/lib/python3/dist-packages/osm_ng_ro", |
| 393 | }, |
| 394 | "RO-plugin": { |
| 395 | "hostpath": f"{ro_host_path}/RO-plugin", |
| 396 | "container-path": "/usr/lib/python3/dist-packages/osm_ro_plugin", |
| 397 | }, |
| 398 | "RO-SDN-arista_cloudvision": { |
| 399 | "hostpath": f"{ro_host_path}/RO-SDN-arista_cloudvision", |
| 400 | "container-path": "/usr/lib/python3/dist-packages/osm_rosdn_arista_cloudvision", |
| 401 | }, |
| 402 | "RO-SDN-dpb": { |
| 403 | "hostpath": f"{ro_host_path}/RO-SDN-dpb", |
| 404 | "container-path": "/usr/lib/python3/dist-packages/osm_rosdn_dpb", |
| 405 | }, |
| 406 | "RO-SDN-dynpac": { |
| 407 | "hostpath": f"{ro_host_path}/RO-SDN-dynpac", |
| 408 | "container-path": "/usr/lib/python3/dist-packages/osm_rosdn_dynpac", |
| 409 | }, |
| 410 | "RO-SDN-floodlight_openflow": { |
| 411 | "hostpath": f"{ro_host_path}/RO-SDN-floodlight_openflow", |
| 412 | "container-path": "/usr/lib/python3/dist-packages/osm_rosdn_floodlightof", |
| 413 | }, |
| 414 | "RO-SDN-ietfl2vpn": { |
| 415 | "hostpath": f"{ro_host_path}/RO-SDN-ietfl2vpn", |
| 416 | "container-path": "/usr/lib/python3/dist-packages/osm_rosdn_ietfl2vpn", |
| 417 | }, |
| 418 | "RO-SDN-juniper_contrail": { |
| 419 | "hostpath": f"{ro_host_path}/RO-SDN-juniper_contrail", |
| 420 | "container-path": "/usr/lib/python3/dist-packages/osm_rosdn_juniper_contrail", |
| 421 | }, |
| 422 | "RO-SDN-odl_openflow": { |
| 423 | "hostpath": f"{ro_host_path}/RO-SDN-odl_openflow", |
| 424 | "container-path": "/usr/lib/python3/dist-packages/osm_rosdn_odlof", |
| 425 | }, |
| 426 | "RO-SDN-onos_openflow": { |
| 427 | "hostpath": f"{ro_host_path}/RO-SDN-onos_openflow", |
| 428 | "container-path": "/usr/lib/python3/dist-packages/osm_rosdn_onosof", |
| 429 | }, |
| 430 | "RO-SDN-onos_vpls": { |
| 431 | "hostpath": f"{ro_host_path}/RO-SDN-onos_vpls", |
| 432 | "container-path": "/usr/lib/python3/dist-packages/osm_rosdn_onos_vpls", |
| 433 | }, |
| 434 | "RO-VIM-aws": { |
| 435 | "hostpath": f"{ro_host_path}/RO-VIM-aws", |
| 436 | "container-path": "/usr/lib/python3/dist-packages/osm_rovim_aws", |
| 437 | }, |
| 438 | "RO-VIM-azure": { |
| 439 | "hostpath": f"{ro_host_path}/RO-VIM-azure", |
| 440 | "container-path": "/usr/lib/python3/dist-packages/osm_rovim_azure", |
| 441 | }, |
| 442 | "RO-VIM-gcp": { |
| 443 | "hostpath": f"{ro_host_path}/RO-VIM-gcp", |
| 444 | "container-path": "/usr/lib/python3/dist-packages/osm_rovim_gcp", |
| 445 | }, |
| David Garcia | cafe31e | 2021-11-18 16:45:05 +0100 | [diff] [blame] | 446 | "RO-VIM-openstack": { |
| 447 | "hostpath": f"{ro_host_path}/RO-VIM-openstack", |
| 448 | "container-path": "/usr/lib/python3/dist-packages/osm_rovim_openstack", |
| 449 | }, |
| 450 | "RO-VIM-openvim": { |
| 451 | "hostpath": f"{ro_host_path}/RO-VIM-openvim", |
| 452 | "container-path": "/usr/lib/python3/dist-packages/osm_rovim_openvim", |
| 453 | }, |
| 454 | "RO-VIM-vmware": { |
| 455 | "hostpath": f"{ro_host_path}/RO-VIM-vmware", |
| 456 | "container-path": "/usr/lib/python3/dist-packages/osm_rovim_vmware", |
| 457 | }, |
| 458 | } |
| 459 | if ro_host_path |
| 460 | else {} |
| 461 | ) |
| 462 | |
| 463 | |
| sousaedu | ccfacbb | 2020-11-04 21:44:01 +0000 | [diff] [blame] | 464 | if __name__ == "__main__": |
| 465 | main(RoCharm) |