docs: def is_elected_leader(resource):
      """
      Returns True if the charm executing this is the elected cluster leader.
  
      It relies on two mechanisms to determine leadership:
          1. If juju is sufficiently new and leadership election is supported,
          the is_leader command will be used.
          2. If the charm is part of a corosync cluster, call corosync to
          determine leadership.
          3. If the charm is not part of a corosync cluster, the leader is
          determined as being "the alive unit with the lowest unit numer". In
          other words, the oldest surviving unit.
      """
      try:
          return juju_is_leader()
      except NotImplementedError:
          log('Juju leadership election feature not enabled'
              ', using fallback support',
              level=WARNING)
  
      if is_clustered():
          if not is_crm_leader(resource):
              log('Deferring action to CRM leader.', level=INFO)
              return False
      else:
          peers = peer_units()
          if peers and not oldest_peer(peers):
              log('Deferring action to oldest service unit.', level=INFO)
              return False
      return True