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:
@@ -24,6 +24,9 @@ CONNECTION_OPTS = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
PROCESSOR_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',
|
cfg.StrOpt('default-data-uri',
|
||||||
default='https://git.openstack.org/cgit/'
|
default='https://git.openstack.org/cgit/'
|
||||||
'openstack/stackalytics/plain/etc/default_data.json',
|
'openstack/stackalytics/plain/etc/default_data.json',
|
||||||
|
|||||||
@@ -312,7 +312,10 @@ def main():
|
|||||||
runtime_storage_inst = runtime_storage.get_runtime_storage(
|
runtime_storage_inst = runtime_storage.get_runtime_storage(
|
||||||
cfg.CONF.runtime_storage_uri)
|
cfg.CONF.runtime_storage_uri)
|
||||||
|
|
||||||
default_data = utils.read_json_from_uri(cfg.CONF.default_data_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:
|
if not default_data:
|
||||||
LOG.critical('Unable to load default data')
|
LOG.critical('Unable to load default data')
|
||||||
return not 0
|
return not 0
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import re
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
import iso8601
|
import iso8601
|
||||||
|
import json
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
import requests
|
import requests
|
||||||
@@ -151,6 +152,12 @@ def read_json_from_uri(uri, session=None):
|
|||||||
{'error': e, 'uri': uri})
|
{'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):
|
def read_yaml_from_uri(uri):
|
||||||
try:
|
try:
|
||||||
return yaml.safe_load(read_uri(uri))
|
return yaml.safe_load(read_uri(uri))
|
||||||
|
|||||||
Reference in New Issue
Block a user