diff --git a/cinderclient/apiclient/base.py b/cinderclient/apiclient/base.py index e1f611cf7..9011d8fc8 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 5f6fb2532..44d1149fc 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):