| 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") |
| 32 | |
| 33 | def get(self, key, defaultValue): |
| 34 | return self.to_dict()[key] |
| 35 | |
| 36 | def set_from_dict(self, config_dict): |
| 37 | def func(attr_path: str, _: type) -> None: |
| 38 | conf_val = glom(config_dict, attr_path, default=None) |
| 39 | if conf_val is not None: |
| 40 | assign(self, attr_path, conf_val) |
| 41 | |
| 42 | self._run_func_for_all_premitives(func) |
| 43 | |
| 44 | def _get_env_name(self, path: str, prefix: str = None) -> str: |
| 45 | path_parts = path.split(".") |
| 46 | if prefix is not None: |
| 47 | path_parts.insert(0, prefix) |
| 48 | return "_".join(path_parts).upper() |
| 49 | |
| 50 | def transform(self): |
| 51 | pass |
| 52 | |
| 53 | |
| 54 | # Configs from lcm.cfg |
| 55 | |
| 56 | |
| 57 | class GlobalConfig(OsmConfigman): |
| 58 | loglevel: str = "DEBUG" |
| 59 | logfile: str = None |
| 60 | nologging: bool = False |
| 61 | |
| 62 | |
| 63 | class Timeout(OsmConfigman): |
| Gabriel Cuba | a89a5a7 | 2022-11-26 18:55:15 -0500 | [diff] [blame] | 64 | nsi_deploy: int = 2 * 3600 # default global timeout for deployment a nsi |
| Luis Vega | a27dc53 | 2022-11-11 20:10:49 +0000 | [diff] [blame] | 65 | vca_on_error: int = ( |
| 66 | 5 * 60 |
| 67 | ) # Time for charm from first time at blocked,error status to mark as failed |
| 68 | ns_deploy: int = 2 * 3600 # default global timeout for deployment a ns |
| 69 | ns_terminate: int = 1800 # default global timeout for un deployment a ns |
| 70 | ns_heal: int = 1800 # default global timeout for un deployment a ns |
| 71 | charm_delete: int = 10 * 60 |
| 72 | primitive: int = 30 * 60 # timeout for primitive execution |
| 73 | ns_update: int = 30 * 60 # timeout for ns update |
| 74 | progress_primitive: int = ( |
| 75 | 10 * 60 |
| 76 | ) # timeout for some progress in a primitive execution |
| 77 | migrate: int = 1800 # default global timeout for migrating vnfs |
| 78 | operate: int = 1800 # default global timeout for migrating vnfs |
| 79 | verticalscale: int = 1800 # default global timeout for Vertical Sclaing |
| 80 | scale_on_error = ( |
| 81 | 5 * 60 |
| 82 | ) # Time for charm from first time at blocked,error status to mark as failed |
| 83 | 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 |
| 84 | primitive_outer_factor = 1.05 # Factor in relation to timeout_primitive related to the timeout to be applied within the asyncio.wait_for coroutine |
| 85 | |
| 86 | |
| 87 | class RoConfig(OsmConfigman): |
| 88 | host: str = None |
| 89 | ng: bool = False |
| 90 | port: int = None |
| 91 | uri: str = None |
| 92 | tenant: str = "osm" |
| Gabriel Cuba | a89a5a7 | 2022-11-26 18:55:15 -0500 | [diff] [blame] | 93 | loglevel: str = "ERROR" |
| Luis Vega | a27dc53 | 2022-11-11 20:10:49 +0000 | [diff] [blame] | 94 | logfile: str = None |
| 95 | logger_name: str = None |
| 96 | |
| 97 | def transform(self): |
| 98 | if not self.uri: |
| 99 | self.uri = "http://{}:{}/".format(self.host, self.port) |
| 100 | elif "/ro" in self.uri[-4:] or "/openmano" in self.uri[-10:]: |
| 101 | # uri ends with '/ro', '/ro/', '/openmano', '/openmano/' |
| 102 | index = self.uri[-1].rfind("/") |
| 103 | self.uri = self.uri[index + 1] |
| 104 | self.logger_name = "lcm.roclient" |
| 105 | |
| 106 | |
| 107 | class VcaConfig(OsmConfigman): |
| 108 | host: str = None |
| 109 | port: int = None |
| 110 | user: str = None |
| 111 | secret: str = None |
| 112 | cloud: str = None |
| 113 | k8s_cloud: str = None |
| 114 | helmpath: str = None |
| 115 | helm3path: str = None |
| 116 | kubectlpath: str = None |
| 117 | jujupath: str = None |
| 118 | public_key: str = None |
| 119 | ca_cert: str = None |
| 120 | api_proxy: str = None |
| 121 | apt_mirror: str = None |
| 122 | eegrpcinittimeout: int = None |
| 123 | eegrpctimeout: int = None |
| 124 | eegrpc_tls_enforce: bool = False |
| Gabriel Cuba | 2dc9cdb | 2023-05-17 01:32:50 -0500 | [diff] [blame] | 125 | eegrpc_pod_admission_policy: str = "baseline" |
| Luis Vega | a27dc53 | 2022-11-11 20:10:49 +0000 | [diff] [blame] | 126 | loglevel: str = "DEBUG" |
| 127 | logfile: str = None |
| 128 | ca_store: str = "/etc/ssl/certs/osm-ca.crt" |
| Gabriel Cuba | eb585dd | 2023-04-25 16:48:41 -0500 | [diff] [blame] | 129 | client_cert_path: str = "/etc/ssl/lcm-client/tls.crt" |
| 130 | client_key_path: str = "/etc/ssl/lcm-client/tls.key" |
| Luis Vega | a27dc53 | 2022-11-11 20:10:49 +0000 | [diff] [blame] | 131 | kubectl_osm_namespace: str = "osm" |
| 132 | kubectl_osm_cluster_name: str = "_system-osm-k8s" |
| 133 | helm_ee_service_port: int = 50050 |
| 134 | helm_max_initial_retry_time: int = 600 |
| 135 | helm_max_retry_time: int = 30 # Max retry time for normal operations |
| 136 | helm_ee_retry_delay: int = ( |
| 137 | 10 # time between retries, retry time after a connection error is raised |
| 138 | ) |
| 139 | |
| 140 | def transform(self): |
| 141 | if self.eegrpcinittimeout: |
| 142 | self.helm_max_initial_retry_time = self.eegrpcinittimeout |
| 143 | if self.eegrpctimeout: |
| 144 | self.helm_max_retry_time = self.eegrpctimeout |
| 145 | |
| 146 | |
| 147 | class DatabaseConfig(OsmConfigman): |
| 148 | driver: str = None |
| 149 | host: str = None |
| 150 | port: int = None |
| 151 | uri: str = None |
| 152 | name: str = None |
| 153 | replicaset: str = None |
| 154 | user: str = None |
| 155 | password: str = None |
| 156 | commonkey: str = None |
| 157 | loglevel: str = "DEBUG" |
| 158 | logfile: str = None |
| 159 | logger_name: str = None |
| 160 | |
| 161 | def transform(self): |
| 162 | self.logger_name = "lcm.db" |
| 163 | |
| 164 | |
| 165 | class StorageConfig(OsmConfigman): |
| 166 | driver: str = None |
| 167 | path: str = "/app/storage" |
| 168 | loglevel: str = "DEBUG" |
| 169 | logfile: str = None |
| 170 | logger_name: str = None |
| 171 | collection: str = None |
| 172 | uri: str = None |
| 173 | |
| 174 | def transform(self): |
| 175 | self.logger_name = "lcm.fs" |
| 176 | |
| 177 | |
| 178 | class MessageConfig(OsmConfigman): |
| 179 | driver: str = None |
| 180 | path: str = None |
| 181 | host: str = None |
| 182 | port: int = None |
| 183 | loglevel: str = "DEBUG" |
| 184 | logfile: str = None |
| 185 | group_id: str = None |
| 186 | logger_name: str = None |
| 187 | |
| 188 | def transform(self): |
| 189 | self.logger_name = "lcm.msg" |
| 190 | |
| 191 | |
| 192 | class TsdbConfig(OsmConfigman): |
| 193 | driver: str = None |
| 194 | path: str = None |
| 195 | uri: str = None |
| 196 | loglevel: str = "DEBUG" |
| 197 | logfile: str = None |
| 198 | logger_name: str = None |
| 199 | |
| 200 | def transform(self): |
| 201 | self.logger_name = "lcm.prometheus" |
| 202 | |
| 203 | |
| Rahul Kumar | 54671c5 | 2024-05-09 15:34:01 +0530 | [diff] [blame] | 204 | class MonitoringConfig(OsmConfigman): |
| 205 | old_sa: bool = True |
| 206 | |
| 207 | |
| Luis Vega | a27dc53 | 2022-11-11 20:10:49 +0000 | [diff] [blame] | 208 | # Main configuration Template |
| 209 | |
| 210 | |
| 211 | class LcmCfg(OsmConfigman): |
| 212 | globalConfig: GlobalConfig = GlobalConfig() |
| 213 | timeout: Timeout = Timeout() |
| 214 | RO: RoConfig = RoConfig() |
| 215 | VCA: VcaConfig = VcaConfig() |
| 216 | database: DatabaseConfig = DatabaseConfig() |
| 217 | storage: StorageConfig = StorageConfig() |
| 218 | message: MessageConfig = MessageConfig() |
| 219 | tsdb: TsdbConfig = TsdbConfig() |
| Rahul Kumar | 54671c5 | 2024-05-09 15:34:01 +0530 | [diff] [blame] | 220 | servicekpi: MonitoringConfig = MonitoringConfig() |
| Luis Vega | a27dc53 | 2022-11-11 20:10:49 +0000 | [diff] [blame] | 221 | |
| 222 | def transform(self): |
| 223 | for attribute in dir(self): |
| 224 | method = getattr(self, attribute) |
| 225 | if isinstance(method, OsmConfigman): |
| 226 | method.transform() |
| 227 | |
| 228 | |
| 229 | class SubOperation(OsmConfigman): |
| 230 | STATUS_NOT_FOUND: int = -1 |
| 231 | STATUS_NEW: int = -2 |
| 232 | STATUS_SKIP: int = -3 |
| 233 | |
| 234 | |
| 235 | class LCMConfiguration(OsmConfigman): |
| 236 | suboperation: SubOperation = SubOperation() |
| 237 | task_name_deploy_vca = "Deploying VCA" |