def __getattr__(self, attr): try: return self._apidict[attr] except KeyError: msg = 'Unknown attribute "%(attr)s" on APIResource object ' \ 'of type "%(cls)s"' % {'attr': attr, 'cls': self.__class__} LOG.debug(exceptions.error_color(msg)) raise AttributeError(msg)
def __getattr__(self, attr): if attr in self._attrs: # __getattr__ won't find properties return self._apiresource.__getattribute__(attr) else: msg = ('Attempted to access unknown attribute "%s" on ' 'APIResource object of type "%s" wrapping resource of ' 'type "%s".') % (attr, self.__class__, self._apiresource.__class__) LOG.debug(exceptions.error_color(msg)) raise AttributeError(attr)
def rack(self): try: if not hasattr(self, '_rack'): # FIXME the node.rack association should be stored somewhere self._rack = None for rack in Rack.list(self.request): for node_obj in rack.list_nodes: if node_obj.id == self.id: self._rack = rack return self._rack except Exception: msg = "Could not obtain Nodes's rack" LOG.debug(exceptions.error_color(msg)) return None