def get_all_members(cluster: Cluster, group: Optional[int],
                    role: CtlPostgresqlRole = CtlPostgresqlRole.LEADER) -> Iterator[Member]:
    """Get all cluster members that have the given *role*.

    :param cluster: the Patroni cluster.
    :param group: filter which Citus group we should get members from. If ``None`` get from all groups.
    :param role: role to filter members. One of :class:`CtlPostgresqlRole` values.

    :yields: members that have the given *role*.
    """
    clusters = {0: cluster}
    if is_citus_cluster() and group is None:
        clusters.update(cluster.workers)
    if role in (CtlPostgresqlRole.LEADER, CtlPostgresqlRole.PRIMARY, CtlPostgresqlRole.STANDBY_LEADER):
        # In the DCS the members' role can be one among: ``primary``, ``master``, ``replica`` or ``standby_leader``.
        # ``primary`` and ``master`` are the same thing.
        for cluster in clusters.values():
            if cluster.leader is not None and cluster.leader.name and\
                (role == CtlPostgresqlRole.LEADER
                 or cluster.leader.data.get('role') not in (PostgresqlRole.PRIMARY, PostgresqlRole.MASTER)
                 and role == CtlPostgresqlRole.STANDBY_LEADER
                 or cluster.leader.data.get('role') != PostgresqlRole.STANDBY_LEADER
                 and role == CtlPostgresqlRole.PRIMARY):
                yield cluster.leader.member
        return

    for cluster in clusters.values():
        leader_name = (cluster.leader.member.name if cluster.leader else None)
        for m in cluster.members:
            if role == CtlPostgresqlRole.ANY or\
                    role in (CtlPostgresqlRole.REPLICA, CtlPostgresqlRole.STANDBY) and m.name != leader_name:
                yield m
Get all cluster members that have the given *role*.

    :param cluster: the Patroni cluster.
    :param group: filter which Citus group we should get members from. If ``None`` get from all groups.
    :param role: role to filter members. One of :class:`CtlPostgresqlRole` values.

    :yields: members that have the given *role*.
    
patroni/ctl.py