Remove ucloud_common and put its files under ucloud.common subpackage.
Remove individual config.py used by every component and put them into single config.py ucloud/config.py Use /etc/ucloud/ucloud.conf for Environment Variables Refactoring and a lot of it Make ucloud repo a package and different components of ucloud a subpackage for avoiding code duplication. Improved logging.
This commit is contained in:
parent
1d2b980c74
commit
6fa77bce4d
51 changed files with 890 additions and 567 deletions
48
common/classes.py
Normal file
48
common/classes.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
from decouple import Config, RepositoryEnv, UndefinedValueError
|
||||
from etcd3_wrapper import EtcdEntry
|
||||
|
||||
|
||||
class EnvironmentVariables:
|
||||
def __init__(self, env_file):
|
||||
try:
|
||||
env_config = Config(RepositoryEnv(env_file))
|
||||
except FileNotFoundError:
|
||||
print("{} does not exists".format(env_file))
|
||||
exit(1)
|
||||
else:
|
||||
self.config = env_config
|
||||
|
||||
def get(self, *args, **kwargs):
|
||||
"""Return value of var from env_vars"""
|
||||
try:
|
||||
value = self.config.get(*args, **kwargs)
|
||||
except UndefinedValueError as e:
|
||||
print(e)
|
||||
exit(1)
|
||||
else:
|
||||
return value
|
||||
|
||||
|
||||
class SpecificEtcdEntryBase:
|
||||
def __init__(self, e: EtcdEntry):
|
||||
self.key = e.key
|
||||
|
||||
for k in e.value.keys():
|
||||
self.__setattr__(k, e.value[k])
|
||||
|
||||
def original_keys(self):
|
||||
r = dict(self.__dict__)
|
||||
if "key" in r:
|
||||
del r["key"]
|
||||
return r
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
return self.original_keys()
|
||||
|
||||
@value.setter
|
||||
def value(self, v):
|
||||
self.__dict__ = v
|
||||
|
||||
def __repr__(self):
|
||||
return str(dict(self.__dict__))
|
||||
Loading…
Add table
Add a link
Reference in a new issue