Beispiel #1
0
    # Warn if quiet and verbosity are both specified
    check_verbosity(opt)

    # Parse source connection values
    try:
        source_values = parse_connection(opt.source, None, opt)
    except FormatError:
        _, err, _ = sys.exc_info()
        parser.error("Source connection values invalid: %s." % err)
    except UtilError:
        _, err, _ = sys.exc_info()
        parser.error("Source connection values invalid: %s." % err.errmsg)

    if opt.list_users and opt.destination:
        print(WARN_OPT_NOT_REQUIRED.format(opt='--destination', cmd="--list"))
        opt.destination = None

    if opt.dump and opt.destination:
        print(WARN_OPT_NOT_REQUIRED.format(opt='--destination', cmd="--dump"))
        opt.destination = None

    if opt.list_users:
        try:
            userclone.show_users(source_values, opt.verbosity, opt.format,
                                 opt.dump)
        except UtilError:
            _, e, _ = sys.exc_info()
            print("ERROR: {0}".format(e.errmsg))
            sys.exit(1)
    if command in ['start', 'stop', 'reset'] and not opt.slaves:
        req_opts = '--slaves'
        parser.error(PARSE_ERR_OPTS_REQ_BY_CMD.format(cmd=command,
                                                      opts=req_opts))

    # Validate the required options for the failover command
    if command == 'failover':
        # --discover-slaves-login is invalid (as it will require a master)
        # instead --slaves needs to be used.
        if opt.discover:
            invalid_opt = '--discover-slaves-login'
            parser.error(PARSE_ERR_OPT_INVALID_CMD_TIP.format(
                opt=invalid_opt, cmd=command, opt_tip='--slaves'))
        # --master will be ignored
        if opt.master:
            print(WARN_OPT_NOT_REQUIRED.format(opt='--master', cmd=command))
            opt.master = None

    # --ping only used by 'health' command
    if opt.ping and not command == 'health':
        print(WARN_OPT_NOT_REQUIRED_ONLY_FOR.format(opt='--ping', cmd=command,
                                                    only_cmd='health'))
        opt.ping = None

    # --exec-after only used by 'failover' or 'switchover' command
    if opt.exec_after and command not in ['switchover', 'failover']:
        only_used_cmds = 'failover or switchover'
        print(WARN_OPT_NOT_REQUIRED_ONLY_FOR.format(opt='--exec-after',
                                                    cmd=command,
                                                    only_cmd=only_used_cmds))
        opt.exec_after = None
    # Warn if quiet and verbosity are both specified
    check_verbosity(opt)

    # Parse source connection values
    try:
        source_values = parse_connection(opt.source, None, opt)
    except FormatError:
        _, err, _ = sys.exc_info()
        parser.error("Source connection values invalid: %s." % err)
    except UtilError:
        _, err, _ = sys.exc_info()
        parser.error("Source connection values invalid: %s." % err.errmsg)

    if opt.list_users and opt.destination:
        print(WARN_OPT_NOT_REQUIRED.format(opt='--destination', cmd="--list"))
        opt.destination = None

    if opt.dump and opt.destination:
        print(WARN_OPT_NOT_REQUIRED.format(opt='--destination', cmd="--dump"))
        opt.destination = None

    if opt.list_users:
        try:
            userclone.show_users(source_values, opt.verbosity, opt.format,
                                 opt.dump)
        except UtilError:
            _, e, _ = sys.exc_info()
            print("ERROR: {0}".format(e.errmsg))
            sys.exit(1)
Beispiel #4
0
        parser.error(
            PARSE_ERR_OPTS_REQ_BY_CMD.format(cmd=command, opts=req_opts))

    # Validate the required options for the failover command
    if command == 'failover':
        # --discover-slaves-login is invalid (as it will require a master)
        # instead --slaves needs to be used.
        if opt.discover:
            invalid_opt = '--discover-slaves-login'
            parser.error(
                PARSE_ERR_OPT_INVALID_CMD_TIP.format(opt=invalid_opt,
                                                     cmd=command,
                                                     opt_tip='--slaves'))
        # --master will be ignored
        if opt.master:
            print(WARN_OPT_NOT_REQUIRED.format(opt='--master', cmd=command))
            opt.master = None
        if not opt.slaves:
            req_opts = '--slaves'
            parser.error(
                PARSE_ERR_OPTS_REQ_BY_CMD.format(cmd=command, opts=req_opts))

    # --ping only used by 'health' command
    if opt.ping and command != 'health':
        print(
            WARN_OPT_NOT_REQUIRED_ONLY_FOR.format(opt='--ping',
                                                  cmd=command,
                                                  only_cmd='health'))
        opt.ping = None

    # --exec-after only used by 'failover' or 'switchover' command