Added ability to configure cache directory
Change-Id: I9ec2eda729a5db98bd437e148fba1ef4b39e17b1
This commit is contained in:
parent
b8c433b2c1
commit
6973b53150
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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/<path:client_type>')
|
||||
@ -209,8 +211,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)
|
||||
|
@ -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,
|
||||
|
@ -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 = []
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user