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