Пример #1
0
def connect(state, host):
    if not host.connection:
        host.connection = ssh.connect(state, host)

    if "docker_container_id" in host.host_data:  # user can provide a docker_container_id
        return host.connection

    try:
        with progress_spinner({"docker run"}):
            # last line is the container ID
            status, stdout, stderr = ssh.run_shell_command(
                state,
                host,
                "docker run -d {0} tail -f /dev/null".format(
                    host.data.docker_image),
            )
            if not status:
                raise IOError("\n".join(stderr))
            container_id = stdout[-1]

    except PyinfraError as e:
        host.connection = None  # fail connection
        raise ConnectError(e.args[0])

    host.host_data["docker_container_id"] = container_id
    return host.connection
Пример #2
0
def _start_docker_image(image_name):
    try:
        return local.shell(
            'docker run -d {0} tail -f /dev/null'.format(image_name),
            splitlines=True,
        )[-1]  # last line is the container ID
    except PyinfraError as e:
        raise ConnectError(e.args[0])
Пример #3
0
def _get_sftp_connection(host):
    transport = host.connection.get_transport()

    try:
        return SFTPClient.from_transport(transport)
    except SSHException as e:
        raise ConnectError((
            "Unable to establish SFTP connection. Check that the SFTP subsystem "
            "for the SSH service at {0} is enabled.").format(host), ) from e
Пример #4
0
def _get_sftp_connection(host):
    transport = host.connection.get_transport()

    try:
        return SFTPClient.from_transport(transport)
    except SSHException as e:
        six.raise_from(
            ConnectError((
                'Unable to establish SFTP connection. Check that the SFTP subsystem '
                'for the SSH service at {0} is enabled.').format(host)), e)
Пример #5
0
def connect(state, host, for_fact=None):
    chroot_directory = host.data.chroot_directory

    try:
        with progress_spinner({'chroot run'}):
            local.shell(
                'chroot {0} ls'.format(chroot_directory), splitlines=True,
            )
    except PyinfraError as e:
        raise ConnectError(e.args[0])

    host.host_data['chroot_directory'] = chroot_directory
    return True
Пример #6
0
def connect(state, host):
    chroot_directory = host.data.chroot_directory

    try:
        with progress_spinner({"chroot run"}):
            local.shell(
                "chroot {0} ls".format(chroot_directory),
                splitlines=True,
            )
    except PyinfraError as e:
        raise ConnectError(e.args[0])

    host.connector_data["chroot_directory"] = chroot_directory
    return True
Пример #7
0
def connect(state, host, for_fact=None):
    if 'docker_container_id' in host.host_data:  # user can provide a docker_container_id
        return True

    try:
        with progress_spinner({'docker run'}):
            container_id = local.shell(
                'docker run -d {0} tail -f /dev/null'.format(host.data.docker_image),
                splitlines=True,
            )[-1]  # last line is the container ID
    except PyinfraError as e:
        raise ConnectError(e.args[0])

    host.host_data['docker_container_id'] = container_id
    return True
Пример #8
0
def _raise_connect_error(host, message, data):
    message = '{0} ({1})'.format(message, data)
    raise ConnectError(message)