Add config option default_data_file

It is useful to specify local file instead of uri if we want to
use stackalytics locally.
This patch adds default_data_file for doing that.

Change-Id: I52953a7727da297c3648dc94f9ff4681c8fad170
This commit is contained in:
Ken'ichi Ohmichi
2017-02-24 17:23:59 -08:00
parent 636ede7bfa
commit 1888bfb60c
3 changed files with 14 additions and 1 deletions

View File

@@ -24,6 +24,9 @@ CONNECTION_OPTS = [
]
PROCESSOR_OPTS = [
cfg.StrOpt('default-data-file',
help='Default data file. This file is used instead of '
'default-data-uri if specifying.'),
cfg.StrOpt('default-data-uri',
default='https://git.openstack.org/cgit/'
'openstack/stackalytics/plain/etc/default_data.json',

View File

@@ -312,6 +312,9 @@ def main():
runtime_storage_inst = runtime_storage.get_runtime_storage(
cfg.CONF.runtime_storage_uri)
if cfg.CONF.default_data_file:
default_data = utils.read_json_from_file(cfg.CONF.default_data_file)
else:
default_data = utils.read_json_from_uri(cfg.CONF.default_data_uri)
if not default_data:
LOG.critical('Unable to load default data')

View File

@@ -22,6 +22,7 @@ import re
import time
import iso8601
import json
from oslo_config import cfg
from oslo_log import log as logging
import requests
@@ -151,6 +152,12 @@ def read_json_from_uri(uri, session=None):
{'error': e, 'uri': uri})
def read_json_from_file(filename):
with open(filename) as json_data:
data = json.load(json_data)
return data
def read_yaml_from_uri(uri):
try:
return yaml.safe_load(read_uri(uri))