def flush(cluster_name: str, group: Optional[int],
          member_names: List[str], force: bool, role: CtlPostgresqlRole, target: str) -> None:
    """Process ``flush`` command of ``patronictl`` utility.

    Discard scheduled restart or switchover events.

    :param cluster_name: name of the Patroni cluster.
    :param group: filter which Citus group we should flush an event. Refer to the module note for more details.
    :param member_names: name of the members which events should be flushed.
    :param force: perform the operation without asking for confirmations.
    :param role: role to filter members. See :func:`get_all_members` for available options.
    :param target: the event that should be flushed -- ``restart`` or ``switchover``.
    """
    dcs = get_dcs(cluster_name, group)
    cluster = dcs.get_cluster()

    if target == 'restart':
        for member in get_members(cluster, cluster_name, member_names, role, force, 'flush', group=group):
            if member.data.get('scheduled_restart'):
                r = request_patroni(member, 'delete', 'restart')
                check_response(r, member.name, 'flush scheduled restart')
            else:
                click.echo('No scheduled restart for member {0}'.format(member.name))
    elif target == 'switchover':
        failover = cluster.failover
        if not failover or not failover.scheduled_at:
            return click.echo('No pending scheduled switchover')
        for member in get_all_members_leader_first(cluster):
            try:
                r = request_patroni(member, 'delete', 'switchover')
                if r.status in (200, 404):
                    prefix = 'Success' if r.status == 200 else 'Failed'
                    return click.echo('{0}: {1}'.format(prefix, r.data.decode('utf-8')))

                click.echo('Failed: member={0}, status_code={1}, ({2})'.format(
                    member.name, r.status, r.data.decode('utf-8')))
            except Exception as err:
                logging.warning(str(err))
                logging.warning('Member %s is not accessible', member.name)

        logging.warning('Failing over to DCS')
        click.echo('{0} Could not find any accessible member of cluster {1}'.format(timestamp(), cluster_name))
        dcs.manual_failover('', '', version=failover.version)
Process ``flush`` command of ``patronictl`` utility.

    Discard scheduled restart or switchover events.

    :param cluster_name: name of the Patroni cluster.
    :param group: filter which Citus group we should flush an event. Refer to the module note for more details.
    :param member_names: name of the members which events should be flushed.
    :param force: perform the operation without asking for confirmations.
    :param role: role to filter members. See :func:`get_all_members` for available options.
    :param target: the event that should be flushed -- ``restart`` or ``switchover``.
    
patroni/ctl.py