Merge "Fix AttributeError on Rack.resource_class_id for unassigned racks."

This commit is contained in:
Jenkins 2013-09-27 17:46:19 +00:00 committed by Gerrit Code Review
commit e759d3d1c5

View File

@ -110,7 +110,10 @@ class StringIdAPIResourceWrapper(base.APIResourceWrapper):
if issubclass(self._apiresource.__class__, dict): if issubclass(self._apiresource.__class__, dict):
return self._apiresource.get(attr) return self._apiresource.get(attr)
else: else:
try:
return self._apiresource.__getattribute__(attr) return self._apiresource.__getattribute__(attr)
except AttributeError:
return None
else: else:
raise AttributeError(attr) raise AttributeError(attr)
@ -352,7 +355,7 @@ class Rack(StringIdAPIResourceWrapper):
if only_free_racks: if only_free_racks:
return [Rack(r, request) for r in return [Rack(r, request) for r in
tuskarclient(request).racks.list() if ( tuskarclient(request).racks.list() if (
r.resource_class is None)] getattr(r, 'resource_class', None) is None)]
else: else:
return [Rack(r, request) for r in return [Rack(r, request) for r in
tuskarclient(request).racks.list()] tuskarclient(request).racks.list()]
@ -388,7 +391,8 @@ class Rack(StringIdAPIResourceWrapper):
@property @property
def resource_class_id(self): def resource_class_id(self):
rclass = self.resource_class rclass = self.resource_class
return rclass['id'] if rclass else None resource_class_id = rclass['id'] if rclass else None
return resource_class_id
@property @property
def get_resource_class(self): def get_resource_class(self):