Exemplo n.º 1
0
def download(hostname, remote_path, local_path, ignore_failure=False, password=None):
    """
    Download a file.
    """

    # See issue #39.
    # XXX: Revise this once we're using Fabric 2.0.

    LOG.debug(_("downloading {host}:{path} -> {target}").format(
        host=hostname, path=remote_path, target=local_path))
    env.host_string = hostname
    env.password = password
    fabric_result = _fabric_sudo(
        "base64 {}".format(quote(remote_path)),
        shell=True,
        pty=False,
        combine_stderr=False,
    )
    if fabric_result.succeeded:
        with open(local_path, "w") as f:
            f.write(b64decode(fabric_result.stdout))
    elif not ignore_failure:
        raise RemoteException(_(
            "reading file '{path}' on {host} failed: {error}").format(
                error=fabric_result.stderr,
                host=hostname,
                path=remote_path,
            )
        )
Exemplo n.º 2
0
def remote(hostname, command, ignore_failure=False):
    """
    Runs a command on a remote system via sudo.
    """
    env.host_string = hostname
    
    LOG.debug("running on {}: {}".format(
        hostname,
        command
    ))
    with prefix("export LANG=C"):
        result = _fabric_sudo(
            command,
            shell=True,
            pty=True,
            combine_stderr=False,
        )
    
    if not result.succeeded and not ignore_failure:
        raise RemoteOperationException(
            "Non-zero return code running '{}' on '{}': {}".format(
                command,
                hostname,
                result
            )
        )
    return result