uncloud/ucloud/config.py

41 lines
1.6 KiB
Python

from etcd3_wrapper import Etcd3Wrapper
from ucloud.common.host import HostPool
from ucloud.common.request import RequestPool
from ucloud.common.vm import VmPool
from ucloud.common.storage_handlers import FileSystemBasedImageStorageHandler, CEPHBasedImageStorageHandler
from decouple import Config, RepositoryEnv, RepositoryEmpty
# Try importing config, but don't fail if it does not exist
try:
env_vars = Config(RepositoryEnv('/etc/ucloud/ucloud.conf'))
except FileNotFoundError:
env_vars = Config(RepositoryEmpty())
etcd_wrapper_args = ()
etcd_wrapper_kwargs = {
'host': env_vars.get('ETCD_URL', 'localhost'),
'port': env_vars.get('ETCD_PORT', 2379),
'ca_cert': env_vars.get('CA_CERT', None),
'cert_cert': env_vars.get('CERT_CERT', None),
'cert_key': env_vars.get('CERT_KEY', None)
}
etcd_client = Etcd3Wrapper(*etcd_wrapper_args, **etcd_wrapper_kwargs)
host_pool = HostPool(etcd_client, env_vars.get('HOST_PREFIX', "hosts"))
vm_pool = VmPool(etcd_client, env_vars.get('VM_PREFIX', "vms"))
request_pool = RequestPool(etcd_client, env_vars.get('REQUEST_PREFIX', "requests"))
running_vms = []
__storage_backend = env_vars.get("STORAGE_BACKEND", "filesystem")
if __storage_backend == "filesystem":
image_storage_handler = FileSystemBasedImageStorageHandler(vm_base=env_vars.get("VM_DIR"),
image_base=env_vars.get("IMAGE_DIR"))
elif __storage_backend == "ceph":
image_storage_handler = CEPHBasedImageStorageHandler(vm_base="ssd", image_base="ssd")
else:
raise Exception("Unknown Image Storage Handler")