[imagescanner] main.py refactored from env_vars to config

This commit is contained in:
llnu 2019-12-08 14:11:19 +01:00
parent c6fe2cb1c4
commit 2a1e80dbc5

View file

@ -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