From 6cdb946663dddfa7953f6191149b1c74fba5c457 Mon Sep 17 00:00:00 2001 From: Zhongyue Luo Date: Tue, 25 Feb 2014 23:28:53 +0900 Subject: [PATCH] Update context from Oslo Following changes were updated: 13eb01c Adding domain to context and log 12bcdb7 Remove vim header bdabd51 Remove uuidutils imports in oslo modules 44e8222 Revert "Removes generate_uuid from uuidutils" 571a78a Removes generate_uuid from uuidutils 36859e5 Adding instance_uuid to context and log As of this update uuidutils is not used anymore in murano-conductor. Change-Id: Idb68ad50a7eff588322f53c3ffa639fef3bc1675 Closes-bug: #1253497 --- muranoconductor/openstack/common/context.py | 44 +++++++++++++++---- muranoconductor/openstack/common/uuidutils.py | 39 ---------------- openstack-common.conf | 5 +-- 3 files changed, 37 insertions(+), 51 deletions(-) delete mode 100644 muranoconductor/openstack/common/uuidutils.py diff --git a/muranoconductor/openstack/common/context.py b/muranoconductor/openstack/common/context.py index 39e47dd..09019ee 100644 --- a/muranoconductor/openstack/common/context.py +++ b/muranoconductor/openstack/common/context.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2011 OpenStack Foundation. # All Rights Reserved. # @@ -23,12 +21,11 @@ context or provide additional information in their specific WSGI pipeline. """ import itertools - -from muranoconductor.openstack.common import uuidutils +import uuid def generate_request_id(): - return 'req-%s' % uuidutils.generate_uuid() + return 'req-%s' % str(uuid.uuid4()) class RequestContext(object): @@ -39,26 +36,46 @@ class RequestContext(object): accesses the system, as well as additional request information. """ - def __init__(self, auth_token=None, user=None, tenant=None, is_admin=False, - read_only=False, show_deleted=False, request_id=None): + 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} + 'request_id': self.request_id, + 'instance_uuid': self.instance_uuid, + 'user_identity': user_idt} def get_admin_context(show_deleted=False): @@ -81,3 +98,14 @@ def get_context_from_function_and_args(function, args, kwargs): return arg return None + + +def is_user_context(context): + """Indicates if the request context is a normal user.""" + if not context: + return False + if context.is_admin: + return False + if not context.user_id or not context.project_id: + return False + return True diff --git a/muranoconductor/openstack/common/uuidutils.py b/muranoconductor/openstack/common/uuidutils.py deleted file mode 100644 index 7608acb..0000000 --- a/muranoconductor/openstack/common/uuidutils.py +++ /dev/null @@ -1,39 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright (c) 2012 Intel Corporation. -# 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. - -""" -UUID related utilities and helper functions. -""" - -import uuid - - -def generate_uuid(): - return str(uuid.uuid4()) - - -def is_uuid_like(val): - """Returns validation of a value as a UUID. - - For our purposes, a UUID is a canonical form string: - aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa - - """ - try: - return str(uuid.UUID(val)) == val - except (TypeError, ValueError, AttributeError): - return False diff --git a/openstack-common.conf b/openstack-common.conf index 63c5923..3cde621 100644 --- a/openstack-common.conf +++ b/openstack-common.conf @@ -16,11 +16,8 @@ module=timeutils module=eventlet_backdoor module=threadgroup module=loopingcall -module=uuidutils -module=uuidutils -module=uuidutils module=fileutils module=lockutils # The base module to hold the copy of openstack.common -base=muranoconductor \ No newline at end of file +base=muranoconductor