Add API header config to JSON ingester

Add the 'api_default_headers' field which specifies a hash/dict
of headers to pass with each API call w.r.t. that JSON ingester.
Main usage is to specify API microversion. For example:

api_default_headers:
  X-OpenStack-Nova-API-Version: "2.26"

Change-Id: Ie859e45ea03135aa21196fe19767f28627e76c3b
partially-implements: bp json-data-model
This commit is contained in:
Eric Kao 2019-03-06 11:33:17 -08:00
parent 5da6e463ff
commit 86a778ca59
4 changed files with 14 additions and 5 deletions

View File

@ -160,7 +160,7 @@ def inspect_methods(client, api_prefix):
# Note (thread-safety): blocking function
def get_keystone_session(creds):
def get_keystone_session(creds, headers=None):
auth_details = {}
auth_details['auth_url'] = creds['auth_url']
@ -174,6 +174,11 @@ def get_keystone_session(creds):
'Default')
loader = kaloading.get_plugin_loader('password')
auth_plugin = loader.load_from_options(**auth_details)
session = kaloading.session.Session().load_from_options(
auth=auth_plugin)
if headers is None:
session = kaloading.session.Session().load_from_options(
auth=auth_plugin)
else:
session = kaloading.session.Session().load_from_options(
auth=auth_plugin, additional_headers=headers)
return session

View File

@ -51,7 +51,8 @@ class ExecApiManager(object):
+ config.get('api_endpoint_path', '').lstrip('/'))
self._exec_api_sessions[
name] = datasource_utils.get_keystone_session(
config['authentication']['config'])
config['authentication']['config'],
headers=config.get('api_default_headers', {}))
@lockutils.synchronized('congress_json_ingester_exec_api')
def evaluate_and_execute_actions(self):

View File

@ -216,7 +216,8 @@ class JsonIngester(datasource_driver.PollingDataSourceDriver):
def _initialize_session(self):
if 'authentication' in self._config:
self._session = datasource_utils.get_keystone_session(
self._config['authentication']['config'])
self._config['authentication']['config'],
headers=self._config.get('api_default_headers', {}))
def _initialize_update_methods(self):
for table_name in self._config['tables']:

View File

@ -4,6 +4,8 @@ allow_exec_api: true
authentication: !ref keystone_admin_auth_config
api_endpoint_host: !ref primary_host
api_endpoint_path: compute/v2.1/
api_default_headers:
X-OpenStack-Nova-API-Version: "2.26"
tables:
flavors:
poll: