Esempio n. 1
0
def _rsync(project, local, remote, server, rsync_opts, up):
    """Sync files from or to server."""

    project_id, server_id = _resolve_server(project, server)

    client = faculty.client("server")
    details = client.get_ssh_details(project_id, server_id)

    escaped_remote = faculty_cli.shell.quote(remote)
    if up:
        path_from = local
        path_to = u"{}@{}:{}".format(details.username, details.hostname,
                                     escaped_remote)
    else:
        path_from = u"{}@{}:{}".format(details.username, details.hostname,
                                       escaped_remote)
        path_to = local

    with _save_key_to_file(details.key) as filename:
        ssh_cmd = "ssh {} -p {} -i {}".format(" ".join(SSH_OPTIONS),
                                              details.port, filename)

        rsync_cmd = ["rsync", "-a", "-e", ssh_cmd, path_from, path_to]
        rsync_cmd += list(rsync_opts)

        _run_ssh_cmd(rsync_cmd)
Esempio n. 2
0
def get(project, remote, local, server):
    """Copy a file from Faculty workspace to the local machine."""

    project_id, server_id = _resolve_server(project, server)

    client = faculty.client("server")
    details = client.get_ssh_details(project_id, server_id)

    escaped_remote = faculty_cli.shell.quote(remote)

    with _save_key_to_file(details.key) as filename:
        cmd = (["scp"] + SSH_OPTIONS + [
            "-i",
            filename,
            "-P",
            str(details.port),
            u"{}@{}:{}".format(details.username, details.hostname,
                               escaped_remote),
            os.path.expanduser(local),
        ])
        _run_ssh_cmd(cmd)
Esempio n. 3
0
def shell(project, server, ssh_opts):
    """Open a shell on a Faculty server.

    Any additional arguments given are passed on to SSH. This allows you to set
    up, for example, port forwarding:

    $ faculty shell <project> <server> -L 9000:localhost:8888

    """

    project_id, server_id = _resolve_server(project, server)
    client = faculty.client("server")
    details = client.get_ssh_details(project_id, server_id)

    with _save_key_to_file(details.key) as filename:
        cmd = (["ssh"] + SSH_OPTIONS + [
            "-p",
            str(details.port),
            "-i",
            filename,
            "{}@{}".format(details.username, details.hostname),
        ])
        cmd += list(ssh_opts)
        _run_ssh_cmd(cmd)
Esempio n. 4
0
def _get_ssh_details(project, server):
    project_id, server_id = _resolve_server(project, server)
    client = faculty.client("server")
    return client.get_ssh_details(project_id, server_id)