@task
def reboot_server(name):
    """
    Simply reboot a server by name.
    The trick here is to change the env vars to that of the server
    to be rebooted. Perform the reboot and change env vars back
    to their original value.

    Usage:
        fab reboot_server:name
    """
    __shared_setup()
    try:
        server = [s for s in env.bootmachine_servers if s.name == name][0]
    except IndexError:
        abort("The server '{0}' was not found.".format(name))
    original_user = env.user
    original_host_string = env.host_string
    try:
        env.port = 22
        telnetlib.Telnet(server.public_ip, env.port)
        env.user = "root"
    except __HOLE__:
        env.port = int(settings.SSH_PORT)
        env.user = getpass.getuser()
        telnetlib.Telnet(server.public_ip, env.port)
    env.host_string = "{0}:{1}".format(server.public_ip, env.port)

    env.keepalive = 30  # keep the ssh key active, see fabric issue #402
    with fabric_settings(warn_only=True):
        reboot()

    env.user = original_user
    env.host_string = original_host_string
dataset/ETHPy150Open rizumu/bootmachine/bootmachine/core.py/reboot_server