Пример #1
0
def main():
    device_opt = ["help", "version", "agent", "quiet", "verbose", "debug",
                  "action", "ipaddr", "login", "passwd", "passwd_script",
                  "secure", "identity_file", "test", "port", "separator",
                  "inet4_only", "inet6_only", "ipport",
                  "power_timeout", "shell_timeout",
                  "login_timeout", "power_wait"]

    atexit.register(atexit_handler)

    all_opt["login_timeout"]["default"] = 60

    pinput = process_input(device_opt)

    # use ssh to manipulate node
    pinput["-x"] = 1

    options = check_input(device_opt, pinput)

    if options["-o"] != "off":
        sys.exit(0)

    options["-c"] = "\[EXPECT\]#\ "

    # this string will be appended to the end of ssh command
    strict = "-t -o 'StrictHostKeyChecking=no'"
    serveralive = "-o 'ServerAliveInterval 2'"
    no_stdin = "-n"
    bash = "/bin/bash --noprofile --norc"
    options["ssh_options"] = "{0} {1} {2} '/bin/bash -c " \
                             "\"PS1={3} {4}\"'".format(
                             strict, serveralive, no_stdin, options["-c"],
                             bash)
    options["-X"] = "{0} {1} {2} '/bin/bash -c " \
                    "\"PS1={3} {4}\"'".format(
                    strict, serveralive, no_stdin, options["-c"], bash)

    docs = {}
    docs["shortdesc"] = "Fence agent that can just reboot node via ssh"
    docs["longdesc"] = "fence_ssh is an I/O Fencing agent \
which can be used to reboot nodes via ssh."
    show_docs(options, docs)

    # Operate the fencing device

    # this method will actually launch ssh command
    conn = fence_login(options)

    result = fence_action(conn, options, set_power_status,
                          get_power_status, None)

    try:
        conn.close()
    except exceptions.OSError:
        pass
    except pexpect.ExceptionPexpect:
        pass

    sys.exit(result)
def main():
    device_opt = [
        "help", "version", "agent", "verbose", "debug", "action", "ipaddr",
        "login", "passwd", "passwd_script", "secure", "identity_file", "port",
        "separator", "inet4_only", "inet6_only", "ipport", "power_timeout",
        "shell_timeout", "login_timeout", "power_wait"
    ]

    atexit.register(atexit_handler)

    all_opt["login_timeout"]["default"] = 60

    pinput = process_input(device_opt)

    # use ssh to manipulate node
    pinput["--ssh"] = 1
    pinput["--command-prompt"] = ".*"

    options = check_input(device_opt, pinput)

    if options["--action"] != "off":
        sys.exit(0)

    options["-c"] = "\[EXPECT\]#\ "

    # this string will be appended to the end of ssh command
    strict = "-t -o 'StrictHostKeyChecking=no'"
    serveralive = "-o 'ServerAliveInterval 2'"
    no_stdin = "-n"
    options["ssh_options"] = "{0} {1} {2} '/bin/bash -c \"PS1={3} /bin/bash " \
                             "--noprofile --norc\"'".format(
                             strict, serveralive, no_stdin, options["-c"])
    options["-X"] = "{0} {1} {2} '/bin/bash -c \"PS1={3}  /bin/bash " \
                    "--noprofile --norc\"'".format(
                    strict, serveralive, no_stdin, options["-c"])

    docs = {}
    docs["shortdesc"] = "Fence agent that can just reboot node via ssh"
    docs["longdesc"] = "fence_ssh is an I/O Fencing agent " \
                       "which can be used to reboot nodes via ssh."
    show_docs(options, docs)

    # Operate the fencing device

    # this method will actually launch ssh command
    conn = fence_login(options)

    result = fence_action(conn, options, set_power_status, get_power_status,
                          None)

    try:
        conn.close()
    except exceptions.OSError:
        pass
    except pexpect.ExceptionPexpect:
        pass

    sys.exit(result)