refactor the getid method in keystoneclient/base.py

Refer to a merged commit.
https://review.openstack.org/#/c/588983/

TrivialFix

Change-Id: Ie3a02843e35382dd24230e91534b6ed72846957d
This commit is contained in:
zhubx007 2018-08-08 10:25:10 +08:00
parent 783655f546
commit 31a7ce67fe
1 changed files with 4 additions and 10 deletions

View File

@ -38,16 +38,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: # nosec(cjschaef): 'obj' doesn't contain attribute
# 'uuid', return attribute 'id' or the 'obj'
pass
try:
return obj.id
except AttributeError:
return obj
if getattr(obj, 'uuid', None):
return obj.uuid
else:
return getattr(obj, 'id', obj)
def filter_none(**kwargs):