Feature 10929: LCM saga, Milestone 1.
[osm/LCM.git] / osm_lcm / data_utils / lcm_config.py
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):
64 nsi_deploy: int = None
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"
93 loglevel: str = "DEBUG"
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
125 loglevel: str = "DEBUG"
126 logfile: str = None
127 ca_store: str = "/etc/ssl/certs/osm-ca.crt"
128 kubectl_osm_namespace: str = "osm"
129 kubectl_osm_cluster_name: str = "_system-osm-k8s"
130 helm_ee_service_port: int = 50050
131 helm_max_initial_retry_time: int = 600
132 helm_max_retry_time: int = 30 # Max retry time for normal operations
133 helm_ee_retry_delay: int = (
134 10 # time between retries, retry time after a connection error is raised
135 )
136
137 def transform(self):
138 if self.eegrpcinittimeout:
139 self.helm_max_initial_retry_time = self.eegrpcinittimeout
140 if self.eegrpctimeout:
141 self.helm_max_retry_time = self.eegrpctimeout
142
143
144 class DatabaseConfig(OsmConfigman):
145 driver: str = None
146 host: str = None
147 port: int = None
148 uri: str = None
149 name: str = None
150 replicaset: str = None
151 user: str = None
152 password: str = None
153 commonkey: str = None
154 loglevel: str = "DEBUG"
155 logfile: str = None
156 logger_name: str = None
157
158 def transform(self):
159 self.logger_name = "lcm.db"
160
161
162 class StorageConfig(OsmConfigman):
163 driver: str = None
164 path: str = "/app/storage"
165 loglevel: str = "DEBUG"
166 logfile: str = None
167 logger_name: str = None
168 collection: str = None
169 uri: str = None
170
171 def transform(self):
172 self.logger_name = "lcm.fs"
173
174
175 class MessageConfig(OsmConfigman):
176 driver: str = None
177 path: str = None
178 host: str = None
179 port: int = None
180 loglevel: str = "DEBUG"
181 logfile: str = None
182 group_id: str = None
183 logger_name: str = None
184
185 def transform(self):
186 self.logger_name = "lcm.msg"
187
188
189 class TsdbConfig(OsmConfigman):
190 driver: str = None
191 path: str = None
192 uri: str = None
193 loglevel: str = "DEBUG"
194 logfile: str = None
195 logger_name: str = None
196
197 def transform(self):
198 self.logger_name = "lcm.prometheus"
199
200
201 # Main configuration Template
202
203
204 class LcmCfg(OsmConfigman):
205 globalConfig: GlobalConfig = GlobalConfig()
206 timeout: Timeout = Timeout()
207 RO: RoConfig = RoConfig()
208 VCA: VcaConfig = VcaConfig()
209 database: DatabaseConfig = DatabaseConfig()
210 storage: StorageConfig = StorageConfig()
211 message: MessageConfig = MessageConfig()
212 tsdb: TsdbConfig = TsdbConfig()
213
214 def transform(self):
215 for attribute in dir(self):
216 method = getattr(self, attribute)
217 if isinstance(method, OsmConfigman):
218 method.transform()
219
220
221 class SubOperation(OsmConfigman):
222 STATUS_NOT_FOUND: int = -1
223 STATUS_NEW: int = -2
224 STATUS_SKIP: int = -3
225
226
227 class LCMConfiguration(OsmConfigman):
228 suboperation: SubOperation = SubOperation()
229 task_name_deploy_vca = "Deploying VCA"