Replace oslo-incubator with oslo_context

openstack.common.context is currently moved out of the incubator
to a standalone project, hence replace it with oslo_context in nova.

Change-Id: I6cbf5d719f33072a5a871c250760512a439a7daf
Closes-Bug: #1210261
This commit is contained in:
Tomofumi Hayashi 2015-02-14 04:40:41 +09:00
parent 1935fa87e1
commit 24fd271994
8 changed files with 6 additions and 129 deletions

View File

@ -23,11 +23,10 @@ Responses for APIv3 are taken care of by the request_id middleware provided
in oslo.
"""
from oslo_context import context
from oslo_middleware import base
import webob.dec
from nova.openstack.common import context
ENV_REQUEST_ID = 'openstack.request_id'
HTTP_RESP_HEADER_REQUEST_ID = 'x-compute-request-id'

View File

@ -21,6 +21,7 @@ Starting point for routing EC2 requests.
import hashlib
from oslo_config import cfg
from oslo_context import context as common_context
from oslo_serialization import jsonutils
from oslo_utils import importutils
from oslo_utils import netutils
@ -40,7 +41,6 @@ from nova import exception
from nova.i18n import _
from nova.i18n import _LE
from nova.i18n import _LW
from nova.openstack.common import context as common_context
from nova.openstack.common import log as logging
from nova.openstack.common import memorycache
from nova import wsgi

View File

@ -21,11 +21,11 @@ import copy
from keystoneclient import auth
from keystoneclient import service_catalog
from oslo_context import context
from oslo_utils import timeutils
import six
from nova import exception
from nova.openstack.common import context
from nova.i18n import _, _LW
from nova.openstack.common import local
from nova.openstack.common import log as logging

View File

@ -21,6 +21,7 @@ the system.
import datetime
from oslo_config import cfg
from oslo_context import context as common_context
from oslo_utils import excutils
from oslo_utils import timeutils
import six
@ -32,7 +33,6 @@ from nova.image import glance
from nova import network
from nova.network import model as network_model
from nova.objects import base as obj_base
from nova.openstack.common import context as common_context
from nova.openstack.common import log
from nova import rpc
from nova import utils

View File

@ -1,122 +0,0 @@
# Copyright 2011 OpenStack Foundation.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""
Simple class that stores security context information in the web request.
Projects should subclass this class if they wish to enhance the request
context or provide additional information in their specific WSGI pipeline.
"""
import itertools
import uuid
def generate_request_id():
return b'req-' + str(uuid.uuid4()).encode('ascii')
class RequestContext(object):
"""Helper class to represent useful information about a request context.
Stores information about the security context under which the user
accesses the system, as well as additional request information.
"""
user_idt_format = '{user} {tenant} {domain} {user_domain} {p_domain}'
def __init__(self, auth_token=None, user=None, tenant=None, domain=None,
user_domain=None, project_domain=None, is_admin=False,
read_only=False, show_deleted=False, request_id=None,
instance_uuid=None):
self.auth_token = auth_token
self.user = user
self.tenant = tenant
self.domain = domain
self.user_domain = user_domain
self.project_domain = project_domain
self.is_admin = is_admin
self.read_only = read_only
self.show_deleted = show_deleted
self.instance_uuid = instance_uuid
if not request_id:
request_id = generate_request_id()
self.request_id = request_id
def to_dict(self):
user_idt = (
self.user_idt_format.format(user=self.user or '-',
tenant=self.tenant or '-',
domain=self.domain or '-',
user_domain=self.user_domain or '-',
p_domain=self.project_domain or '-'))
return {'user': self.user,
'tenant': self.tenant,
'domain': self.domain,
'user_domain': self.user_domain,
'project_domain': self.project_domain,
'is_admin': self.is_admin,
'read_only': self.read_only,
'show_deleted': self.show_deleted,
'auth_token': self.auth_token,
'request_id': self.request_id,
'instance_uuid': self.instance_uuid,
'user_identity': user_idt}
@classmethod
def from_dict(cls, ctx):
return cls(
auth_token=ctx.get("auth_token"),
user=ctx.get("user"),
tenant=ctx.get("tenant"),
domain=ctx.get("domain"),
user_domain=ctx.get("user_domain"),
project_domain=ctx.get("project_domain"),
is_admin=ctx.get("is_admin", False),
read_only=ctx.get("read_only", False),
show_deleted=ctx.get("show_deleted", False),
request_id=ctx.get("request_id"),
instance_uuid=ctx.get("instance_uuid"))
def get_admin_context(show_deleted=False):
context = RequestContext(None,
tenant=None,
is_admin=True,
show_deleted=show_deleted)
return context
def get_context_from_function_and_args(function, args, kwargs):
"""Find an arg of type RequestContext and return it.
This is useful in a couple of decorators where we don't
know much about the function we're wrapping.
"""
for arg in itertools.chain(kwargs.values(), args):
if isinstance(arg, RequestContext):
return arg
return None
def is_user_context(context):
"""Indicates if the request context is a normal user."""
if not context or context.is_admin:
return False
return context.user_id and context.project_id

View File

@ -14,12 +14,12 @@
# under the License.
from oslo_context import context
from testtools import matchers
import webob
import webob.dec
from nova.api import compute_req_id
from nova.openstack.common import context
from nova import test

View File

@ -2,7 +2,6 @@
# The list of modules to copy from oslo-incubator
module=cliutils
module=context
module=eventlet_backdoor
module=fileutils
module=fixture.logging

View File

@ -32,6 +32,7 @@ websockify>=0.6.0,<0.7
wsgiref>=0.1.2
oslo.concurrency>=1.4.1 # Apache-2.0
oslo.config>=1.6.0 # Apache-2.0
oslo.context>=0.1.0 # Apache-2.0
oslo.serialization>=1.2.0 # Apache-2.0
oslo.utils>=1.2.0 # Apache-2.0
oslo.db>=1.4.1 # Apache-2.0