From 416457de4db4d06468fd783b3a604521e0853ee8 Mon Sep 17 00:00:00 2001 From: LiuNanke Date: Fri, 8 Jan 2016 15:48:00 +0800 Subject: [PATCH] Use the oslo.utils.reflection to extract the class name The oslo.utils reflection module/code handles more variations of where a class name may come from (on python 2 and python 3) so its usage allows getting more accurate class names so we might as well use it. Change-Id: I7b130d6acb183a06a4efe648ee2c3fbd2905cdd5 --- troveclient/compat/base.py | 5 ++++- troveclient/openstack/common/apiclient/base.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/troveclient/compat/base.py b/troveclient/compat/base.py index e47c6da..3e894ae 100644 --- a/troveclient/compat/base.py +++ b/troveclient/compat/base.py @@ -22,6 +22,7 @@ Base utilities to build API operation managers and objects on top of. import contextlib import hashlib import os +from oslo_utils import reflection from troveclient.compat import exceptions from troveclient.compat import utils @@ -264,7 +265,9 @@ class Resource(object): reprkeys = sorted(k for k in self.__dict__.keys() if k[0] != '_' and k != 'manager') info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys) - return "<%s %s>" % (self.__class__.__name__, info) + self_cls_name = reflection.get_class_name(self, + fully_qualified=False) + return "<%s %s>" % (self_cls_name, info) def get(self): # set_loaded() first ... so if we have to bail, we know we tried. diff --git a/troveclient/openstack/common/apiclient/base.py b/troveclient/openstack/common/apiclient/base.py index 13b195f..3e87266 100644 --- a/troveclient/openstack/common/apiclient/base.py +++ b/troveclient/openstack/common/apiclient/base.py @@ -26,6 +26,7 @@ Base utilities to build API operation managers and objects on top of. import abc import copy +from oslo_utils import reflection import six from six.moves.urllib import parse @@ -435,7 +436,9 @@ class Resource(object): for k in self.__dict__.keys() if k[0] != '_' and k != 'manager') info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys) - return "<%s %s>" % (self.__class__.__name__, info) + self_cls_name = reflection.get_class_name(self, + fully_qualified=False) + return "<%s %s>" % (self_cls_name, info) @property def human_id(self):