diff --git a/etc/murano-repository.conf b/etc/murano-repository.conf index 78ed421..6169ab7 100644 --- a/etc/murano-repository.conf +++ b/etc/murano-repository.conf @@ -3,6 +3,8 @@ host = 0.0.0.0 # Port the bind the server to port = 8084 +# Directory for cache, OS temp directory is used by default +#cache_dir = # Provide information about data types # absolute or relative path to manifest location(root directory) diff --git a/muranorepository/api/utils.py b/muranorepository/api/utils.py index 3ba2a02..aa9329e 100644 --- a/muranorepository/api/utils.py +++ b/muranorepository/api/utils.py @@ -13,7 +13,6 @@ from muranorepository.consts import DATA_TYPES, MANIFEST from muranorepository.consts import CLIENTS_DICT from muranorepository.consts import ARCHIVE_PKG_NAME from muranorepository.config import cfg -from muranorepository.consts import CACHE_DIR import logging as log CONF = cfg.CONF @@ -26,7 +25,7 @@ def update_cache(data_type): break if not client: abort(404) - cache_dir = os.path.join(CACHE_DIR, client) + cache_dir = os.path.join(CONF.cache_dir, client) if not os.path.exists(cache_dir): os.mkdir(cache_dir) manifests = ManifestParser().parse() @@ -40,7 +39,7 @@ def update_cache(data_type): def get_archive(client, hash_sum): types = CLIENTS_DICT.get(client) archive_manager = Archiver() - cache_dir = os.path.join(CACHE_DIR, client) + cache_dir = os.path.join(CONF.cache_dir, client) if not os.path.exists(cache_dir): os.mkdir(cache_dir) existing_hash = archive_manager.get_existing_hash(cache_dir) @@ -195,6 +194,6 @@ def save_archive(request): filename = secure_filename(file_to_upload.filename) else: return err_resp - path_to_archive = os.path.join(CACHE_DIR, filename) + path_to_archive = os.path.join(CONF.cache_dir, filename) file_to_upload.save(path_to_archive) return path_to_archive diff --git a/muranorepository/api/v1.py b/muranorepository/api/v1.py index 6810099..6b48e62 100644 --- a/muranorepository/api/v1.py +++ b/muranorepository/api/v1.py @@ -22,9 +22,11 @@ from muranorepository.api import utils as api from muranorepository.utils.parser import ManifestParser from muranorepository.utils.archiver import Archiver from muranorepository.consts import DATA_TYPES, MANIFEST -from muranorepository.consts import CLIENTS_DICT, CACHE_DIR +from muranorepository.consts import CLIENTS_DICT +from oslo.config import cfg import logging as log v1_api = Blueprint('v1', __name__) +CONF = cfg.CONF @v1_api.route('/client/') @@ -210,8 +212,8 @@ def toggleEnabled(service_name): @v1_api.route('/admin/reset_caches', methods=['POST']) def reset_caches(): try: - shutil.rmtree(CACHE_DIR, ignore_errors=True) - os.mkdir(CACHE_DIR) + shutil.rmtree(CONF.cache_dir, ignore_errors=True) + os.mkdir(CONF.cache_dir) return jsonify(result='success') except: return make_response('Unable to perform operation', 500) diff --git a/muranorepository/cmd/run.py b/muranorepository/cmd/run.py index 1728794..cd7ccbc 100644 --- a/muranorepository/cmd/run.py +++ b/muranorepository/cmd/run.py @@ -18,6 +18,7 @@ import os import sys import eventlet +import tempfile from eventlet import wsgi from oslo.config import cfg # If ../murano_service/__init__.py exists, add ../ to Python search path, @@ -51,6 +52,15 @@ def main(): config.parse_configs(sys.argv[1:], config_files) log.setup('muranorepository') + #configuring and initializing cache directory + if cfg.CONF.cache_dir is None: + cfg.CONF.cache_dir = os.path.join( + tempfile.gettempdir(), 'murano-cache' + ) + if not os.path.exists(cfg.CONF.cache_dir): + os.mkdir(cfg.CONF.cache_dir) + log.debug('Cache is located at: {0}'.format(cfg.CONF.cache_dir)) + app = server.make_app({ 'auth_host': cfg.CONF.keystone.auth_host, 'auth_port': cfg.CONF.keystone.auth_port, diff --git a/muranorepository/config.py b/muranorepository/config.py index 08659c3..4f2a45c 100644 --- a/muranorepository/config.py +++ b/muranorepository/config.py @@ -20,6 +20,8 @@ server_opts = [ cfg.StrOpt('host', default='127.0.0.1'), cfg.IntOpt('port', default=5000)] +cache_opt = cfg.StrOpt('cache_dir') + keystone_opts = [ cfg.StrOpt('auth_host', default='localhost'), cfg.IntOpt('auth_port', default=5000), @@ -40,7 +42,7 @@ CONF.register_cli_opts(server_opts) CONF.register_opts(type_dirs_opts) CONF.register_opts(type_dirs_opts, group='output') CONF.register_opts(keystone_opts, group='keystone') - +CONF.register_opt(cache_opt) ARGV = [] diff --git a/muranorepository/consts.py b/muranorepository/consts.py index 2b35225..a09a33b 100644 --- a/muranorepository/consts.py +++ b/muranorepository/consts.py @@ -27,10 +27,3 @@ CLIENTS_DICT = {'conductor': (WORKFLOW, HEAT, AGENT, SCRIPTS), 'ui': (UI,)} ARCHIVE_PKG_NAME = 'data.tar.gz' - -CACHE_DIR = os.path.normpath(os.path.join(os.path.abspath(__file__), - os.pardir, - 'cache')) - -if not os.path.exists(CACHE_DIR): - os.mkdir(CACHE_DIR)