| Luis Vega | a27dc53 | 2022-11-11 20:10:49 +0000 | [diff] [blame] | 1 | # Copyright 2022 Whitestack, LLC |
| 2 | # ************************************************************* |
| 3 | # |
| 4 | # This file is part of OSM Monitoring module |
| 5 | # All Rights Reserved to Whitestack, LLC |
| 6 | # |
| 7 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 8 | # not use this file except in compliance with the License. You may obtain |
| 9 | # a copy of the License at |
| 10 | # |
| 11 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | # |
| 13 | # Unless required by applicable law or agreed to in writing, software |
| 14 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 15 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 16 | # License for the specific language governing permissions and limitations |
| 17 | # under the License. |
| 18 | # |
| 19 | # For those usages not covered by the Apache License, Version 2.0 please |
| 20 | # contact: lvega@whitestack.com |
| 21 | ## |
| 22 | |
| 23 | from configman import ConfigMan |
| 24 | from glom import glom, assign |
| 25 | |
| 26 | |
| 27 | class OsmConfigman(ConfigMan): |
| 28 | def __init__(self, config_dict=None): |
| 29 | super().__init__() |
| 30 | self.set_from_dict(config_dict) |
| 31 | self.set_auto_env("OSMLCM") |
| garciadeblas | 3364c47 | 2024-09-11 14:30:26 +0200 | [diff] [blame] | 32 | self.set_auto_env("OSM") |
| Luis Vega | a27dc53 | 2022-11-11 20:10:49 +0000 | [diff] [blame] | 33 | |
| 34 | def get(self, key, defaultValue): |
| 35 | return self.to_dict()[key] |
| 36 | |
| 37 | def set_from_dict(self, config_dict): |
| 38 | def func(attr_path: str, _: type) -> None: |
| 39 | conf_val = glom(config_dict, attr_path, default=None) |
| 40 | if conf_val is not None: |
| 41 | assign(self, attr_path, conf_val) |
| 42 | |
| 43 | self._run_func_for_all_premitives(func) |
| 44 | |
| 45 | def _get_env_name(self, path: str, prefix: str = None) -> str: |
| 46 | path_parts = path.split(".") |
| 47 | if prefix is not None: |
| 48 | path_parts.insert(0, prefix) |
| 49 | return "_".join(path_parts).upper() |
| 50 | |
| 51 | def transform(self): |
| 52 | pass |
| 53 | |
| 54 | |
| 55 | # Configs from lcm.cfg |
| 56 | |
| 57 | |
| 58 | class GlobalConfig(OsmConfigman): |
| 59 | loglevel: str = "DEBUG" |
| 60 | logfile: str = None |
| 61 | nologging: bool = False |
| 62 | |
| 63 | |
| 64 | class Timeout(OsmConfigman): |
| Gabriel Cuba | a89a5a7 | 2022-11-26 18:55:15 -0500 | [diff] [blame] | 65 | nsi_deploy: int = 2 * 3600 # default global timeout for deployment a nsi |
| Luis Vega | a27dc53 | 2022-11-11 20:10:49 +0000 | [diff] [blame] | 66 | vca_on_error: int = ( |
| 67 | 5 * 60 |
| 68 | ) # Time for charm from first time at blocked,error status to mark as failed |
| 69 | ns_deploy: int = 2 * 3600 # default global timeout for deployment a ns |
| 70 | ns_terminate: int = 1800 # default global timeout for un deployment a ns |
| 71 | ns_heal: int = 1800 # default global timeout for un deployment a ns |
| 72 | charm_delete: int = 10 * 60 |
| 73 | primitive: int = 30 * 60 # timeout for primitive execution |
| 74 | ns_update: int = 30 * 60 # timeout for ns update |
| 75 | progress_primitive: int = ( |
| 76 | 10 * 60 |
| 77 | ) # timeout for some progress in a primitive execution |
| 78 | migrate: int = 1800 # default global timeout for migrating vnfs |
| 79 | operate: int = 1800 # default global timeout for migrating vnfs |
| 80 | verticalscale: int = 1800 # default global timeout for Vertical Sclaing |
| 81 | scale_on_error = ( |
| 82 | 5 * 60 |
| 83 | ) # Time for charm from first time at blocked,error status to mark as failed |
| 84 | scale_on_error_outer_factor = 1.05 # Factor in relation to timeout_scale_on_error related to the timeout to be applied within the asyncio.wait_for coroutine |
| 85 | primitive_outer_factor = 1.05 # Factor in relation to timeout_primitive related to the timeout to be applied within the asyncio.wait_for coroutine |
| 86 | |
| 87 | |
| 88 | class RoConfig(OsmConfigman): |
| 89 | host: str = None |
| 90 | ng: bool = False |
| 91 | port: int = None |
| 92 | uri: str = None |
| 93 | tenant: str = "osm" |
| Gabriel Cuba | a89a5a7 | 2022-11-26 18:55:15 -0500 | [diff] [blame] | 94 | loglevel: str = "ERROR" |
| Luis Vega | a27dc53 | 2022-11-11 20:10:49 +0000 | [diff] [blame] | 95 | logfile: str = None |
| 96 | logger_name: str = None |
| 97 | |
| 98 | def transform(self): |
| 99 | if not self.uri: |
| 100 | self.uri = "http://{}:{}/".format(self.host, self.port) |
| 101 | elif "/ro" in self.uri[-4:] or "/openmano" in self.uri[-10:]: |
| 102 | # uri ends with '/ro', '/ro/', '/openmano', '/openmano/' |
| 103 | index = self.uri[-1].rfind("/") |
| 104 | self.uri = self.uri[index + 1] |
| 105 | self.logger_name = "lcm.roclient" |
| 106 | |
| 107 | |
| 108 | class VcaConfig(OsmConfigman): |
| 109 | host: str = None |
| 110 | port: int = None |
| 111 | user: str = None |
| 112 | secret: str = None |
| 113 | cloud: str = None |
| 114 | k8s_cloud: str = None |
| 115 | helmpath: str = None |
| 116 | helm3path: str = None |
| 117 | kubectlpath: str = None |
| 118 | jujupath: str = None |
| 119 | public_key: str = None |
| 120 | ca_cert: str = None |
| 121 | api_proxy: str = None |
| 122 | apt_mirror: str = None |
| 123 | eegrpcinittimeout: int = None |
| 124 | eegrpctimeout: int = None |
| 125 | eegrpc_tls_enforce: bool = False |
| Gabriel Cuba | 2dc9cdb | 2023-05-17 01:32:50 -0500 | [diff] [blame] | 126 | eegrpc_pod_admission_policy: str = "baseline" |
| Luis Vega | a27dc53 | 2022-11-11 20:10:49 +0000 | [diff] [blame] | 127 | loglevel: str = "DEBUG" |
| 128 | logfile: str = None |
| 129 | ca_store: str = "/etc/ssl/certs/osm-ca.crt" |
| Gabriel Cuba | eb585dd | 2023-04-25 16:48:41 -0500 | [diff] [blame] | 130 | client_cert_path: str = "/etc/ssl/lcm-client/tls.crt" |
| 131 | client_key_path: str = "/etc/ssl/lcm-client/tls.key" |
| Luis Vega | a27dc53 | 2022-11-11 20:10:49 +0000 | [diff] [blame] | 132 | kubectl_osm_namespace: str = "osm" |
| 133 | kubectl_osm_cluster_name: str = "_system-osm-k8s" |
| 134 | helm_ee_service_port: int = 50050 |
| 135 | helm_max_initial_retry_time: int = 600 |
| 136 | helm_max_retry_time: int = 30 # Max retry time for normal operations |
| 137 | helm_ee_retry_delay: int = ( |
| 138 | 10 # time between retries, retry time after a connection error is raised |
| 139 | ) |
| 140 | |
| 141 | def transform(self): |
| 142 | if self.eegrpcinittimeout: |
| 143 | self.helm_max_initial_retry_time = self.eegrpcinittimeout |
| 144 | if self.eegrpctimeout: |
| 145 | self.helm_max_retry_time = self.eegrpctimeout |
| 146 | |
| 147 | |
| 148 | class DatabaseConfig(OsmConfigman): |
| 149 | driver: str = None |
| 150 | host: str = None |
| 151 | port: int = None |
| 152 | uri: str = None |
| 153 | name: str = None |
| 154 | replicaset: str = None |
| 155 | user: str = None |
| 156 | password: str = None |
| 157 | commonkey: str = None |
| 158 | loglevel: str = "DEBUG" |
| 159 | logfile: str = None |
| 160 | logger_name: str = None |
| 161 | |
| 162 | def transform(self): |
| 163 | self.logger_name = "lcm.db" |
| 164 | |
| 165 | |
| 166 | class StorageConfig(OsmConfigman): |
| 167 | driver: str = None |
| 168 | path: str = "/app/storage" |
| 169 | loglevel: str = "DEBUG" |
| 170 | logfile: str = None |
| 171 | logger_name: str = None |
| 172 | collection: str = None |
| 173 | uri: str = None |
| 174 | |
| 175 | def transform(self): |
| 176 | self.logger_name = "lcm.fs" |
| 177 | |
| 178 | |
| 179 | class MessageConfig(OsmConfigman): |
| 180 | driver: str = None |
| 181 | path: str = None |
| 182 | host: str = None |
| 183 | port: int = None |
| 184 | loglevel: str = "DEBUG" |
| 185 | logfile: str = None |
| 186 | group_id: str = None |
| 187 | logger_name: str = None |
| 188 | |
| 189 | def transform(self): |
| 190 | self.logger_name = "lcm.msg" |
| 191 | |
| 192 | |
| 193 | class TsdbConfig(OsmConfigman): |
| 194 | driver: str = None |
| 195 | path: str = None |
| 196 | uri: str = None |
| 197 | loglevel: str = "DEBUG" |
| 198 | logfile: str = None |
| 199 | logger_name: str = None |
| 200 | |
| 201 | def transform(self): |
| 202 | self.logger_name = "lcm.prometheus" |
| 203 | |
| 204 | |
| Rahul Kumar | 54671c5 | 2024-05-09 15:34:01 +0530 | [diff] [blame] | 205 | class MonitoringConfig(OsmConfigman): |
| 206 | old_sa: bool = True |
| 207 | |
| 208 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 209 | class GitopsConfig(OsmConfigman): |
| garciadeblas | 3364c47 | 2024-09-11 14:30:26 +0200 | [diff] [blame] | 210 | git_base_url: str = None |
| 211 | user: str = None |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 212 | pubkey: str = None |
| garciadeblas | 3364c47 | 2024-09-11 14:30:26 +0200 | [diff] [blame] | 213 | mgmtcluster_kubeconfig: str = None |
| garciadeblas | 0283bb2 | 2025-01-27 11:16:27 +0100 | [diff] [blame] | 214 | workflow_debug: bool = True |
| 215 | workflow_dry_run: bool = False |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 216 | loglevel: str = "DEBUG" |
| 217 | logfile: str = None |
| 218 | logger_name: str = None |
| 219 | |
| 220 | def transform(self): |
| 221 | self.logger_name = "lcm.gitops" |
| 222 | |
| 223 | |
| Luis Vega | a27dc53 | 2022-11-11 20:10:49 +0000 | [diff] [blame] | 224 | # Main configuration Template |
| 225 | |
| 226 | |
| 227 | class LcmCfg(OsmConfigman): |
| 228 | globalConfig: GlobalConfig = GlobalConfig() |
| 229 | timeout: Timeout = Timeout() |
| 230 | RO: RoConfig = RoConfig() |
| 231 | VCA: VcaConfig = VcaConfig() |
| 232 | database: DatabaseConfig = DatabaseConfig() |
| 233 | storage: StorageConfig = StorageConfig() |
| 234 | message: MessageConfig = MessageConfig() |
| 235 | tsdb: TsdbConfig = TsdbConfig() |
| Rahul Kumar | 54671c5 | 2024-05-09 15:34:01 +0530 | [diff] [blame] | 236 | servicekpi: MonitoringConfig = MonitoringConfig() |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 237 | gitops: GitopsConfig = GitopsConfig() |
| Luis Vega | a27dc53 | 2022-11-11 20:10:49 +0000 | [diff] [blame] | 238 | |
| 239 | def transform(self): |
| 240 | for attribute in dir(self): |
| 241 | method = getattr(self, attribute) |
| 242 | if isinstance(method, OsmConfigman): |
| 243 | method.transform() |
| 244 | |
| 245 | |
| 246 | class SubOperation(OsmConfigman): |
| 247 | STATUS_NOT_FOUND: int = -1 |
| 248 | STATUS_NEW: int = -2 |
| 249 | STATUS_SKIP: int = -3 |
| 250 | |
| 251 | |
| 252 | class LCMConfiguration(OsmConfigman): |
| 253 | suboperation: SubOperation = SubOperation() |
| 254 | task_name_deploy_vca = "Deploying VCA" |