def get_entity(
self, entity_type, entity_id, history_index=-1, connected=True):
"""Return an object instance for the given entity_type and id.
By default the object state matches the most recent state from
Juju. To get an instance of the object in an older state, pass
history_index, an index into the history deque for the entity.
"""
if history_index < 0 and history_index != -1:
history_index += len(self.entity_history(entity_type, entity_id))
if history_index < 0:
return None
try:
self.entity_data(entity_type, entity_id, history_index)
except IndexError:
return None
entity_class = get_entity_class(entity_type)
return entity_class(
entity_id, self.model, history_index=history_index,
connected=connected)
评论列表
文章目录