Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix bug lp:1019230,update rpc from openstack-common.
Change-Id: I498e578affef4fa9df6c50cd7284ebd7e3f9a64e
- Loading branch information
1 parent
bab54aa
commit 6f99f4f
Showing
20 changed files
with
4,006 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[DEFAULT] | ||
|
||
# The list of modules to copy from openstack-common | ||
modules=cfg,exception,importutils,iniparser,jsonutils,policy,setup | ||
modules=cfg,context,exception,excutils,gettextutils,importutils,iniparser,jsonutils,local,policy,rpc,setup | ||
|
||
# The base module to hold the copy of openstack.common | ||
base=quantum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# vim: tabstop=4 shiftwidth=4 softtabstop=4 | ||
|
||
# Copyright 2011 OpenStack LLC. | ||
# 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 'req-' + str(uuid.uuid4()) | ||
|
||
|
||
class RequestContext(object): | ||
|
||
""" | ||
Stores information about the security context under which the user | ||
accesses the system, as well as additional request information. | ||
""" | ||
|
||
def __init__(self, auth_tok=None, user=None, tenant=None, is_admin=False, | ||
read_only=False, show_deleted=False, request_id=None): | ||
self.auth_tok = auth_tok | ||
self.user = user | ||
self.tenant = tenant | ||
self.is_admin = is_admin | ||
self.read_only = read_only | ||
self.show_deleted = show_deleted | ||
if not request_id: | ||
request_id = generate_request_id() | ||
self.request_id = request_id | ||
|
||
def to_dict(self): | ||
return {'user': self.user, | ||
'tenant': self.tenant, | ||
'is_admin': self.is_admin, | ||
'read_only': self.read_only, | ||
'show_deleted': self.show_deleted, | ||
'auth_token': self.auth_tok, | ||
'request_id': self.request_id} | ||
|
||
|
||
def get_admin_context(show_deleted="no"): | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
Exceptions common to OpenStack projects | ||
""" | ||
|
||
import itertools | ||
import logging | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# vim: tabstop=4 shiftwidth=4 softtabstop=4 | ||
|
||
# Copyright 2011 OpenStack LLC. | ||
# Copyright 2012, Red Hat, Inc. | ||
# | ||
# 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. | ||
|
||
""" | ||
Exception related utilities. | ||
""" | ||
|
||
import contextlib | ||
import logging | ||
import sys | ||
import traceback | ||
|
||
|
||
@contextlib.contextmanager | ||
def save_and_reraise_exception(): | ||
"""Save current exception, run some code and then re-raise. | ||
In some cases the exception context can be cleared, resulting in None | ||
being attempted to be reraised after an exception handler is run. This | ||
can happen when eventlet switches greenthreads or when running an | ||
exception handler, code raises and catches an exception. In both | ||
cases the exception context will be cleared. | ||
To work around this, we save the exception state, run handler code, and | ||
then re-raise the original exception. If another exception occurs, the | ||
saved exception is logged and the new exception is reraised. | ||
""" | ||
type_, value, tb = sys.exc_info() | ||
try: | ||
yield | ||
except Exception: | ||
logging.error('Original exception being dropped: %s' % | ||
(traceback.format_exception(type_, value, tb))) | ||
raise | ||
raise type_, value, tb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# vim: tabstop=4 shiftwidth=4 softtabstop=4 | ||
|
||
# Copyright 2012 Red Hat, Inc. | ||
# 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. | ||
|
||
""" | ||
gettext for openstack-common modules. | ||
Usual usage in an openstack.common module: | ||
from openstack.common.gettextutils import _ | ||
""" | ||
|
||
import gettext | ||
|
||
|
||
t = gettext.translation('openstack-common', 'locale', fallback=True) | ||
|
||
|
||
def _(msg): | ||
return t.ugettext(msg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# vim: tabstop=4 shiftwidth=4 softtabstop=4 | ||
|
||
# Copyright 2011 OpenStack LLC. | ||
# 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. | ||
|
||
"""Greenthread local storage of variables using weak references""" | ||
|
||
import weakref | ||
|
||
from eventlet import corolocal | ||
|
||
|
||
class WeakLocal(corolocal.local): | ||
def __getattribute__(self, attr): | ||
rval = corolocal.local.__getattribute__(self, attr) | ||
if rval: | ||
rval = rval() | ||
return rval | ||
|
||
def __setattr__(self, attr, value): | ||
value = weakref.ref(value) | ||
return corolocal.local.__setattr__(self, attr, value) | ||
|
||
|
||
store = WeakLocal() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.