From 00563c7dc2e1f7fc4cd3c9f859afb36adef9daa0 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 8 Dec 2019 13:51:40 +0100 Subject: [PATCH 1/2] [filescanner] use configparser --- conf/ucloud.conf | 11 ++++++++++- ucloud/filescanner/main.py | 9 ++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/conf/ucloud.conf b/conf/ucloud.conf index e0e3c27..2a06c81 100644 --- a/conf/ucloud.conf +++ b/conf/ucloud.conf @@ -41,8 +41,17 @@ USER_PREFIX = users VM_PREFIX = vms [storage] -STORAGE_BACKEND = #values = filesystem, +#values = filesystem, ceph +STORAGE_BACKEND = + +# if STORAGE_BACKEND = filesystem VM_DIR = IMG_DIR = + +# if STORAGE_BACKEND = ceph CEPH_VM_POOL = CEPH_IMG_POOL = + +# Importing uploaded files +FILE_DIR = /var/lib/ucloud/files +FILE_PREFIX = noclue-ahmed \ No newline at end of file diff --git a/ucloud/filescanner/main.py b/ucloud/filescanner/main.py index b70cb5b..ef6fee6 100755 --- a/ucloud/filescanner/main.py +++ b/ucloud/filescanner/main.py @@ -6,7 +6,7 @@ import time from uuid import uuid4 from . import logger -from ucloud.config import env_vars, etcd_client +from ucloud.config import config, etcd_client def getxattr(file, attr): @@ -37,7 +37,7 @@ def setxattr(file, attr, value): def sha512sum(file: str): """Use sha512sum utility to compute sha512 sum of arg:file - + IF arg:file does not exists: raise FileNotFoundError exception ELSE IF sum successfully computer: @@ -69,9 +69,8 @@ except Exception as e: def main(): - BASE_DIR = env_vars.get("BASE_DIR") - - FILE_PREFIX = env_vars.get("FILE_PREFIX") + BASE_DIR = config['storage']["FILE_DIR"] + FILE_PREFIX = config['storage']["FILE_PREFIX"] # Recursively Get All Files and Folder below BASE_DIR files = glob.glob("{}/**".format(BASE_DIR), recursive=True) From b2de2772447d8c8793fa0b3455503457f45b86af Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 8 Dec 2019 13:51:52 +0100 Subject: [PATCH 2/2] [conf] add values for filescanner --- ucloud/config.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/ucloud/config.py b/ucloud/config.py index b8b4dcf..834d51e 100644 --- a/ucloud/config.py +++ b/ucloud/config.py @@ -5,18 +5,14 @@ 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 - # Replacing decouple inline import configparser import os import os.path import logging - log = logging.getLogger("ucloud.config") - conf_name = "ucloud.conf" try: @@ -34,14 +30,6 @@ try: except FileNotFoundError: log.warn("Configuration file not found - using defaults") - -# 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': config['etcd']['ETCD_URL'],