1 # Copyright 2022 Whitestack, LLC
2 # *************************************************************
4 # This file is part of OSM Monitoring module
5 # All Rights Reserved to Whitestack, LLC
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
11 # http://www.apache.org/licenses/LICENSE-2.0
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
19 # For those usages not covered by the Apache License, Version 2.0 please
20 # contact: lvega@whitestack.com
23 from configman
import ConfigMan
24 from glom
import glom
, assign
27 class OsmConfigman(ConfigMan
):
28 def __init__(self
, config_dict
=None):
30 self
.set_from_dict(config_dict
)
31 self
.set_auto_env("OSMLCM")
33 def get(self
, key
, defaultValue
):
34 return self
.to_dict()[key
]
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
)
42 self
._run
_func
_for
_all
_premitives
(func
)
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()
54 # Configs from lcm.cfg
57 class GlobalConfig(OsmConfigman
):
58 loglevel
: str = "DEBUG"
60 nologging
: bool = False
63 class Timeout(OsmConfigman
):
64 nsi_deploy
: int = 2 * 3600 # default global timeout for deployment a nsi
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 = (
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
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
87 class RoConfig(OsmConfigman
):
93 loglevel
: str = "ERROR"
95 logger_name
: str = None
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"
107 class VcaConfig(OsmConfigman
):
113 k8s_cloud
: str = None
115 helm3path
: str = None
116 kubectlpath
: str = None
118 public_key
: 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 eegrpc_pod_admission_policy
: str = "baseline"
126 loglevel
: str = "DEBUG"
128 ca_store
: str = "/etc/ssl/certs/osm-ca.crt"
129 client_cert_path
: str = "/etc/ssl/lcm-client/tls.crt"
130 client_key_path
: str = "/etc/ssl/lcm-client/tls.key"
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
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
147 class DatabaseConfig(OsmConfigman
):
153 replicaset
: str = None
156 commonkey
: str = None
157 loglevel
: str = "DEBUG"
159 logger_name
: str = None
162 self
.logger_name
= "lcm.db"
165 class StorageConfig(OsmConfigman
):
167 path
: str = "/app/storage"
168 loglevel
: str = "DEBUG"
170 logger_name
: str = None
171 collection
: str = None
175 self
.logger_name
= "lcm.fs"
178 class MessageConfig(OsmConfigman
):
183 loglevel
: str = "DEBUG"
186 logger_name
: str = None
189 self
.logger_name
= "lcm.msg"
192 class TsdbConfig(OsmConfigman
):
196 loglevel
: str = "DEBUG"
198 logger_name
: str = None
201 self
.logger_name
= "lcm.prometheus"
204 # Main configuration Template
207 class LcmCfg(OsmConfigman
):
208 globalConfig
: GlobalConfig
= GlobalConfig()
209 timeout
: Timeout
= Timeout()
210 RO
: RoConfig
= RoConfig()
211 VCA
: VcaConfig
= VcaConfig()
212 database
: DatabaseConfig
= DatabaseConfig()
213 storage
: StorageConfig
= StorageConfig()
214 message
: MessageConfig
= MessageConfig()
215 tsdb
: TsdbConfig
= TsdbConfig()
218 for attribute
in dir(self
):
219 method
= getattr(self
, attribute
)
220 if isinstance(method
, OsmConfigman
):
224 class SubOperation(OsmConfigman
):
225 STATUS_NOT_FOUND
: int = -1
227 STATUS_SKIP
: int = -3
230 class LCMConfiguration(OsmConfigman
):
231 suboperation
: SubOperation
= SubOperation()
232 task_name_deploy_vca
= "Deploying VCA"