From 2a1e80dbc57cd83a64fecc1988b4f6786d14d4c4 Mon Sep 17 00:00:00 2001 From: llnu Date: Sun, 8 Dec 2019 14:11:19 +0100 Subject: [PATCH] [imagescanner] main.py refactored from env_vars to config --- ucloud/imagescanner/main.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ucloud/imagescanner/main.py b/ucloud/imagescanner/main.py index 6ff01f8..df4dfad 100755 --- a/ucloud/imagescanner/main.py +++ b/ucloud/imagescanner/main.py @@ -3,7 +3,7 @@ import os import subprocess from os.path import join as join_path -from ucloud.config import etcd_client, env_vars, image_storage_handler +from ucloud.config import etcd_client, config, image_storage_handler from ucloud.imagescanner import logger @@ -20,9 +20,9 @@ def qemu_img_type(path): def check(): """ check whether settings are sane, refuse to start if they aren't """ - if env_vars.get('STORAGE_BACKEND') == 'filesystem' and not isdir(env_vars.get('IMAGE_DIR')): + if config['etcd']['STORAGE_BACKEND'] == 'filesystem' and not isdir(config['etcd']['IMAGE_DIR']): print("You have set STORAGE_BACKEND to filesystem, but " - "{} does not exist. Refusing to start".format(env_vars.get('IMAGE_DIR'))) + "{} does not exist. Refusing to start".format(config['etcd']['IMAGE_DIR'])) sys.exit(1) try: @@ -34,7 +34,7 @@ def check(): def main(): # We want to get images entries that requests images to be created - images = etcd_client.get_prefix(env_vars.get('IMAGE_PREFIX'), value_in_json=True) + images = etcd_client.get_prefix(config['etcd']['IMAGE_PREFIX'], value_in_json=True) images_to_be_created = list(filter(lambda im: im.value['status'] == 'TO_BE_CREATED', images)) for image in images_to_be_created: @@ -43,9 +43,9 @@ def main(): image_owner = image.value['owner'] image_filename = image.value['filename'] image_store_name = image.value['store_name'] - image_full_path = join_path(env_vars.get('BASE_DIR'), image_owner, image_filename) + image_full_path = join_path(config['etcd']['BASE_DIR'], image_owner, image_filename) - image_stores = etcd_client.get_prefix(env_vars.get('IMAGE_STORE_PREFIX'), value_in_json=True) + image_stores = etcd_client.get_prefix(config['etcd']['IMAGE_STORE_PREFIX'], value_in_json=True) user_image_store = next(filter( lambda s, store_name=image_store_name: s.value["name"] == store_name, image_stores