Create host inventory services (api, conductor and agent) and
python-inventoryclient.
The inventory service collects the host resources and provides a
REST API and client to expose the host resources.
Create plugin for integration with system configuration (sysinv)
service.
This is the initial inventory service infratructure commit.
Puppet configuration, SM integration and host integration with
sysinv(systemconfig) changes are pending and planned to be
delivered in future commits.
Tests Performed:
Verify the changes are inert on config_controller installation
and provisioning.
Puppet and spec changes are required in order to create keystone,
database and activate inventory services.
Unit tests performed (when puppet configuration for keystone, database
is applied):
Trigger host configure_check, configure signals into
systemconfig(sysinv).
Verify python-inventoryclient and api service:
Disks and related storage resources are pending.
inventory host-cpu-list/show
inventory host-device-list/show/modify
inventory host-ethernetport-list/show
inventory host-lldp-neighbor-list
inventory host-lldp-agent-list/show
inventory host-memory-list/show
inventory host-node-list/show
inventory host-port-list/show
Tox Unit tests:
inventory: pep8
python-inventoryclient: py27, pep8, cover, pylint
Change-Id: I744ac0de098608c55b9356abf180cc36601cfb8d
Story: 2002950
Task: 22952
Signed-off-by: John Kung <john.kung@windriver.com>
111 lines
3.2 KiB
Python
111 lines
3.2 KiB
Python
#
|
|
# Copyright (c) 2018 Wind River Systems, Inc.
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
|
|
from inventory.common import context
|
|
from inventory.common.i18n import _
|
|
from inventory.conductor import rpcapi
|
|
from inventory.db import api as dbapi
|
|
from inventory.systemconfig import plugin as systemconfig_plugin
|
|
from oslo_config import cfg
|
|
from oslo_log import log
|
|
from oslo_serialization import jsonutils
|
|
from pecan import hooks
|
|
import webob
|
|
|
|
CONF = cfg.CONF
|
|
LOG = log.getLogger(__name__)
|
|
|
|
|
|
class ContextHook(hooks.PecanHook):
|
|
"""Configures a request context and attaches it to the request.
|
|
|
|
The following HTTP request headers are used:
|
|
|
|
X-User-Name:
|
|
Used for context.user_name.
|
|
|
|
X-User-Id:
|
|
Used for context.user_id.
|
|
|
|
X-Project-Name:
|
|
Used for context.project.
|
|
|
|
X-Project-Id:
|
|
Used for context.project_id.
|
|
|
|
X-Auth-Token:
|
|
Used for context.auth_token.
|
|
|
|
X-Roles:
|
|
Used for context.roles.
|
|
|
|
X-Service_Catalog:
|
|
Used for context.service_catalog.
|
|
"""
|
|
|
|
def before(self, state):
|
|
headers = state.request.headers
|
|
environ = state.request.environ
|
|
user_name = headers.get('X-User-Name')
|
|
user_id = headers.get('X-User-Id')
|
|
project = headers.get('X-Project-Name')
|
|
project_id = headers.get('X-Project-Id')
|
|
domain_id = headers.get('X-User-Domain-Id')
|
|
domain_name = headers.get('X-User-Domain-Name')
|
|
auth_token = headers.get('X-Auth-Token')
|
|
roles = headers.get('X-Roles', '').split(',')
|
|
catalog_header = headers.get('X-Service-Catalog')
|
|
service_catalog = None
|
|
if catalog_header:
|
|
try:
|
|
service_catalog = jsonutils.loads(catalog_header)
|
|
except ValueError:
|
|
raise webob.exc.HTTPInternalServerError(
|
|
_('Invalid service catalog json.'))
|
|
|
|
auth_token_info = environ.get('keystone.token_info')
|
|
auth_url = CONF.keystone_authtoken.auth_uri
|
|
|
|
state.request.context = context.make_context(
|
|
auth_token=auth_token,
|
|
auth_url=auth_url,
|
|
auth_token_info=auth_token_info,
|
|
user_name=user_name,
|
|
user_id=user_id,
|
|
project_name=project,
|
|
project_id=project_id,
|
|
domain_id=domain_id,
|
|
domain_name=domain_name,
|
|
roles=roles,
|
|
service_catalog=service_catalog
|
|
)
|
|
|
|
|
|
class DBHook(hooks.PecanHook):
|
|
"""Attach the dbapi object to the request so controllers can get to it."""
|
|
|
|
def before(self, state):
|
|
state.request.dbapi = dbapi.get_instance()
|
|
|
|
|
|
class RPCHook(hooks.PecanHook):
|
|
"""Attach the rpcapi object to the request so controllers can get to it."""
|
|
|
|
def before(self, state):
|
|
state.request.rpcapi = rpcapi.ConductorAPI()
|
|
|
|
|
|
class SystemConfigHook(hooks.PecanHook):
|
|
"""Attach the rpcapi object to the request so controllers can get to it."""
|
|
|
|
def before(self, state):
|
|
state.request.systemconfig = systemconfig_plugin.SystemConfigPlugin(
|
|
invoke_kwds={'context': state.request.context})
|
|
|
|
# state.request.systemconfig = systemconfig.SystemConfigOperator(
|
|
# state.request.context,
|
|
# state.request.dbapi)
|