summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhubx007 <zhu.boxiang@99cloud.net>2018-08-08 10:55:44 +0800
committerzhubx007 <zhu.boxiang@99cloud.net>2018-08-08 10:55:44 +0800
commit42b598d1098d3ee3eb403d606252bab6cc130bd5 (patch)
tree7ad864f719de95793eb3ec0c481a16f84b326d46
parent460229c6099719dec0d027f798f9c751b8ec7e44 (diff)
downloadpython-cinderclient-42b598d1098d3ee3eb403d606252bab6cc130bd5.tar.gz
refactor the getid method base.py
Refer to a merged commit. https://review.openstack.org/#/c/588983/ Refactor the getid method both in cinderclient/base.py and in cinderclient/apiclient/base.py TrivialFix Change-Id: I4d1fb81f6876ab072ded3f14004ad064dcc949d3
-rw-r--r--cinderclient/apiclient/base.py13
-rw-r--r--cinderclient/base.py5
2 files changed, 5 insertions, 13 deletions
diff --git a/cinderclient/apiclient/base.py b/cinderclient/apiclient/base.py
index e1f611c..9011d8f 100644
--- a/cinderclient/apiclient/base.py
+++ b/cinderclient/apiclient/base.py
@@ -41,15 +41,10 @@ def getid(obj):
Abstracts the common pattern of allowing both an object or an object's ID
(UUID) as a parameter when dealing with relationships.
"""
- try:
- if obj.uuid:
- return obj.uuid
- except AttributeError:
- pass
- try:
- return obj.id
- except AttributeError:
- return obj
+ if getattr(obj, 'uuid', None):
+ return obj.uuid
+ else:
+ return getattr(obj, 'id', obj)
# TODO(aababilov): call run_hooks() in HookableMixin's child classes
diff --git a/cinderclient/base.py b/cinderclient/base.py
index 5f6fb25..44d1149 100644
--- a/cinderclient/base.py
+++ b/cinderclient/base.py
@@ -53,10 +53,7 @@ def getid(obj):
Abstracts the common pattern of allowing both an object or an object's ID
as a parameter when dealing with relationships.
"""
- try:
- return obj.id
- except AttributeError:
- return obj
+ return getattr(obj, 'id', obj)
class Manager(common_base.HookableMixin):