+def status(application: Application) -> str:
+ unit_status = []
+ for unit in application.units:
+ unit_status.append(unit.workload_status)
+ return derive_status(unit_status)
+
+
+def entity_ready(entity: ModelEntity) -> bool:
+ """
+ Check if the entity is ready
+
+ :param: entity: Model entity. It can be a machine, action, or application.
+
+ :returns: boolean saying if the entity is ready or not
+ """
+ entity_type = entity.entity_type
+ if entity_type == "machine":
+ return entity.agent_status in ["started"]
+ elif entity_type == "action":
+ return entity.status in ["completed", "failed", "cancelled"]
+ elif entity_type == "application":
+ # Workaround for bug: https://github.com/juju/python-libjuju/issues/441
+ return entity.status in ["active", "blocked"]
+ else:
+ raise EntityInvalidException("Unknown entity type: {}".format(entity_type))
+
+
+def application_ready(application: Application) -> bool:
+ """
+ Check if an application has a leader
+
+ :param: application: Application entity.
+
+ :returns: boolean saying if the application has a unit that is a leader.
+ """
+ ready_status_list = ["active", "blocked"]
+ application_ready = application.status in ready_status_list
+ units_ready = all(
+ unit.workload_status in ready_status_list for unit in application.units
+ )
+ return application_ready and units_ready
+
+