Esempio n. 1
0
def inspect_cluster(cluster_id: str, verbose: int) -> None:
    """
    Show cluster details.
    """
    set_logging(verbosity_level=verbose)
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(),
    )
    cluster_vms = ClusterVMs(cluster_id=cluster_id)
    keys = {
        'masters': cluster_vms.masters,
        'agents': cluster_vms.agents,
        'public_agents': cluster_vms.public_agents,
    }
    master = next(iter(cluster_vms.cluster.masters))
    web_ui = 'http://' + str(master.private_ip_address)
    nodes = {
        key: [VMInspectView(vm).to_dict() for vm in vms]
        for key, vms in keys.items()
    }

    data = {
        'Cluster ID': cluster_id,
        'Web UI': web_ui,
        'Nodes': nodes,
    }  # type: Dict[Any, Any]
    click.echo(
        json.dumps(data, indent=4, separators=(',', ': '), sort_keys=True),
    )
Esempio n. 2
0
def wait(
    ctx: click.core.Context,
    cluster_id: str,
    superuser_username: str,
    superuser_password: str,
    transport: Transport,
    skip_http_checks: bool,
    enable_spinner: bool,
) -> None:
    """
    Wait for DC/OS to start.
    """
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(),
    )
    cluster_containers = ClusterContainers(
        cluster_id=cluster_id,
        transport=transport,
    )

    http_checks = not skip_http_checks
    doctor_command_name = command_path(sibling_ctx=ctx, command=doctor)

    wait_for_dcos(
        cluster=cluster_containers.cluster,
        superuser_username=superuser_username,
        superuser_password=superuser_password,
        http_checks=http_checks,
        doctor_command_name=doctor_command_name,
        enable_spinner=enable_spinner,
    )
Esempio n. 3
0
def wait(
    ctx: click.core.Context,
    cluster_id: str,
    superuser_username: str,
    superuser_password: str,
    aws_region: str,
) -> None:
    """
    Wait for DC/OS to start.
    """
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(aws_region=aws_region),
    )
    cluster_instances = ClusterInstances(
        cluster_id=cluster_id,
        aws_region=aws_region,
    )
    doctor_command_name = command_path(sibling_ctx=ctx, command=doctor)
    wait_for_dcos(
        cluster=cluster_instances.cluster,
        superuser_username=superuser_username,
        superuser_password=superuser_password,
        http_checks=True,
        doctor_command_name=doctor_command_name,
    )
Esempio n. 4
0
def wait(
    ctx: click.core.Context,
    cluster_id: str,
    superuser_username: str,
    superuser_password: str,
    enable_spinner: bool,
) -> None:
    """
    Wait for DC/OS to start.
    """
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(),
    )
    cluster_vms = ClusterVMs(cluster_id=cluster_id)

    doctor_command_name = command_path(sibling_ctx=ctx, command=doctor)
    wait_for_dcos(
        cluster=cluster_vms.cluster,
        superuser_username=superuser_username,
        superuser_password=superuser_password,
        http_checks=True,
        doctor_command_name=doctor_command_name,
        enable_spinner=enable_spinner,
    )
Esempio n. 5
0
def wait(
    ctx: click.core.Context,
    cluster_id: str,
    superuser_username: str,
    superuser_password: str,
    transport: Transport,
    skip_http_checks: bool,
    verbose: int,
) -> None:
    """
    Wait for DC/OS to start.
    """
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(),
    )
    set_logging(verbosity_level=verbose)
    cluster_containers = ClusterContainers(
        cluster_id=cluster_id,
        transport=transport,
    )

    http_checks = not skip_http_checks

    wait_for_dcos(
        dcos_variant=cluster_containers.dcos_variant,
        cluster=cluster_containers.cluster,
        superuser_username=superuser_username,
        superuser_password=superuser_password,
        http_checks=http_checks,
        doctor_command=doctor,
        sibling_ctx=ctx,
    )
Esempio n. 6
0
def wait(
    ctx: click.core.Context,
    cluster_id: str,
    superuser_username: str,
    superuser_password: str,
    verbose: int,
) -> None:
    """
    Wait for DC/OS to start.
    """
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(),
    )
    set_logging(verbosity_level=verbose)
    cluster_vms = ClusterVMs(cluster_id=cluster_id)

    wait_for_dcos(
        dcos_variant=cluster_vms.dcos_variant,
        cluster=cluster_vms.cluster,
        superuser_username=superuser_username,
        superuser_password=superuser_password,
        http_checks=True,
        doctor_command=doctor,
        sibling_ctx=ctx,
    )
Esempio n. 7
0
def run(
    ctx: click.core.Context,
    cluster_id: str,
    node_args: Tuple[str],
    sync_dir: Tuple[Path],
    dcos_login_uname: str,
    dcos_login_pw: str,
    test_env: bool,
    node: Tuple[str],
    env: Dict[str, str],
    transport: Transport,
) -> None:
    """
    Run an arbitrary command on a node or multiple nodes.

    To use special characters such as single quotes in your command, wrap the
    whole command in double quotes.
    """
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(),
    )

    cluster_containers = ClusterContainers(
        cluster_id=cluster_id,
        transport=transport,
    )
    cluster = cluster_containers.cluster

    for dcos_checkout_dir in sync_dir:
        sync_code_to_masters(
            cluster=cluster,
            dcos_checkout_dir=dcos_checkout_dir,
            sudo=False,
        )

    inspect_command_name = command_path(
        sibling_ctx=ctx,
        command=inspect_cluster,
    )

    hosts = get_nodes(
        cluster_id=cluster_id,
        cluster_representation=cluster_containers,
        node_references=node,
        inspect_command_name=inspect_command_name,
    )

    for host in hosts:
        run_command(
            args=list(node_args),
            cluster=cluster,
            host=host,
            use_test_env=test_env,
            dcos_login_uname=dcos_login_uname,
            dcos_login_pw=dcos_login_pw,
            env=env,
            transport=transport,
        )
Esempio n. 8
0
def destroy(cluster_id: str) -> None:
    """
    Destroy a cluster.
    """
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(),
    )
    cluster_vms = ClusterVMs(cluster_id=cluster_id)
    with click_spinner.spinner():
        cluster_vms.destroy()
    click.echo(cluster_id)
Esempio n. 9
0
def destroy_cluster(cluster_id: str) -> None:
    """
    Destroy a cluster.

    Args:
        cluster_id: The ID of the cluster.
    """
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(),
    )
    cluster_vms = ClusterVMs(cluster_id=cluster_id)
    cluster_vms.destroy()
Esempio n. 10
0
def web(cluster_id: str) -> None:
    """
    Open the browser at the web UI.

    Note that the web UI may not be available at first.
    Consider using ``minidcos vagrant wait`` before running this command.
    """
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(),
    )
    cluster_vms = ClusterVMs(cluster_id=cluster_id)
    launch_web_ui(cluster=cluster_vms.cluster)
Esempio n. 11
0
def inspect_cluster(cluster_id: str) -> None:
    """
    Show cluster details.
    """
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(),
    )
    cluster_vms = ClusterVMs(cluster_id=cluster_id)
    show_cluster_details(
        cluster_id=cluster_id,
        cluster_representation=cluster_vms,
    )
Esempio n. 12
0
def run(
    cluster_id: str,
    node_args: Tuple[str],
    sync_dir: Tuple[Path],
    dcos_login_uname: str,
    dcos_login_pw: str,
    test_env: bool,
    env: Dict[str, str],
    aws_region: str,
    verbose: int,
    node: str,
) -> None:
    """
    Run an arbitrary command on a node.

    To use special characters such as single quotes in your command, wrap the
    whole command in double quotes.
    """  # noqa: E501
    set_logging(verbosity_level=verbose)
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(aws_region=aws_region),
    )
    cluster_instances = ClusterInstances(
        cluster_id=cluster_id,
        aws_region=aws_region,
    )
    cluster = cluster_instances.cluster
    host = _get_node(
        cluster_id=cluster_id,
        node_reference=node,
        aws_region=aws_region,
    )

    for dcos_checkout_dir in sync_dir:
        sync_code_to_masters(
            cluster=cluster,
            dcos_checkout_dir=dcos_checkout_dir,
            dcos_variant=cluster_instances.dcos_variant,
        )

    run_command(
        args=list(node_args),
        cluster=cluster,
        host=host,
        use_test_env=test_env,
        dcos_login_uname=dcos_login_uname,
        dcos_login_pw=dcos_login_pw,
        env=env,
        transport=Transport.SSH,
    )
Esempio n. 13
0
def destroy_cluster(cluster_id: str, enable_spinner: bool) -> None:
    """
    Destroy a cluster.

    Args:
        cluster_id: The ID of the cluster.
        enable_spinner: Whether to enable the spinner animation.
    """
    with Halo(enabled=enable_spinner):
        check_cluster_id_exists(
            new_cluster_id=cluster_id,
            existing_cluster_ids=existing_cluster_ids(),
        )
        cluster_vms = ClusterVMs(cluster_id=cluster_id)
        cluster_vms.destroy()
Esempio n. 14
0
def destroy(cluster_id: str, transport: Transport) -> None:
    """
    Destroy a cluster.
    """
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(),
    )
    cluster_containers = ClusterContainers(
        cluster_id=cluster_id,
        transport=transport,
    )
    with click_spinner.spinner():
        cluster_containers.destroy()
    click.echo(cluster_id)
Esempio n. 15
0
def web(cluster_id: str, aws_region: str) -> None:
    """
    Open the browser at the web UI.

    Note that the web UI may not be available at first.
    Consider using ``minidcos aws wait`` before running this command.
    """
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(aws_region=aws_region),
    )
    cluster_instances = ClusterInstances(
        cluster_id=cluster_id,
        aws_region=aws_region,
    )
    launch_web_ui(cluster=cluster_instances.cluster)
Esempio n. 16
0
def inspect_cluster(cluster_id: str, aws_region: str) -> None:
    """
    Show cluster details.
    """
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(aws_region=aws_region),
    )
    cluster_instances = ClusterInstances(
        cluster_id=cluster_id,
        aws_region=aws_region,
    )
    show_cluster_details(
        cluster_id=cluster_id,
        cluster_representation=cluster_instances,
    )
Esempio n. 17
0
def web(cluster_id: str, transport: Transport) -> None:
    """
    Open the browser at the web UI.

    Note that the web UI may not be available at first.
    Consider using ``minidcos docker wait`` before running this command.
    """
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(),
    )
    cluster_containers = ClusterContainers(
        cluster_id=cluster_id,
        transport=transport,
    )
    launch_web_ui(cluster=cluster_containers.cluster)
Esempio n. 18
0
def web(cluster_id: str, verbose: int) -> None:
    """
    Open the browser at the web UI.

    Note that the web UI may not be available at first.
    Consider using ``minidcos vagrant wait`` before running this command.
    """
    set_logging(verbosity_level=verbose)
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(),
    )
    cluster_vms = ClusterVMs(cluster_id=cluster_id)
    cluster = cluster_vms.cluster
    master = next(iter(cluster.masters))
    web_ui = 'http://' + str(master.public_ip_address)
    click.launch(web_ui)
Esempio n. 19
0
def _destroy_cluster(cluster_id: str, transport: Transport) -> None:
    """
    Destroy a cluster.

    Args:
        cluster_id: The ID of the cluster.
        transport: The transport to use for any communication with the cluster.
    """
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(),
    )
    cluster_containers = ClusterContainers(
        cluster_id=cluster_id,
        transport=transport,
    )
    cluster_containers.destroy()
Esempio n. 20
0
def sync_code(
    cluster_id: str,
    dcos_checkout_dir: Path,
) -> None:
    """
    Sync files from a DC/OS checkout to master nodes.
    """
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(),
    )
    cluster_vms = ClusterVMs(cluster_id=cluster_id)
    cluster = cluster_vms.cluster
    sync_code_to_masters(
        cluster=cluster,
        dcos_checkout_dir=dcos_checkout_dir,
        sudo=True,
    )
Esempio n. 21
0
def sync_code(
    cluster_id: str,
    dcos_checkout_dir: str,
    verbose: int,
) -> None:
    """
    Sync files from a DC/OS checkout to master nodes.
    """
    set_logging(verbosity_level=verbose)
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(),
    )
    cluster_vms = ClusterVMs(cluster_id=cluster_id)
    cluster = cluster_vms.cluster
    sync_code_to_masters(
        cluster=cluster,
        dcos_checkout_dir=Path(dcos_checkout_dir),
        dcos_variant=cluster_vms.dcos_variant,
    )
Esempio n. 22
0
def web(cluster_id: str, verbose: int) -> None:
    """
    Open the browser at the web UI.

    Note that the web UI may not be available at first.
    Consider using ``minidcos docker wait`` before running this command.
    """
    set_logging(verbosity_level=verbose)
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(),
    )
    cluster_containers = ClusterContainers(
        cluster_id=cluster_id,
        # The transport is not used so does not matter.
        transport=Transport.DOCKER_EXEC,
    )
    cluster = cluster_containers.cluster
    master = next(iter(cluster.masters))
    web_ui = 'http://' + str(master.public_ip_address)
    click.launch(web_ui)
Esempio n. 23
0
def inspect_cluster(
    cluster_id: str,
    transport: Transport,
) -> None:
    """
    Show cluster details.
    """
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(),
    )

    cluster_containers = ClusterContainers(
        cluster_id=cluster_id,
        transport=transport,
    )

    show_cluster_details(
        cluster_id=cluster_id,
        cluster_representation=cluster_containers,
    )
Esempio n. 24
0
def send_file(
    ctx: click.core.Context,
    cluster_id: str,
    node: Tuple[str],
    transport: Transport,
    source: str,
    destination: str,
) -> None:
    """
    Send a file to a node or multiple nodes.
    """
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(),
    )

    cluster_containers = ClusterContainers(
        cluster_id=cluster_id,
        transport=transport,
    )

    inspect_command_name = command_path(
        sibling_ctx=ctx,
        command=inspect_cluster,
    )

    hosts = get_nodes(
        cluster_id=cluster_id,
        cluster_representation=cluster_containers,
        node_references=node,
        inspect_command_name=inspect_command_name,
    )

    for host in hosts:
        host.send_file(
            local_path=Path(source),
            remote_path=Path(destination),
            transport=transport,
            sudo=False,
        )
Esempio n. 25
0
def sync_code(
    cluster_id: str,
    dcos_checkout_dir: Path,
    transport: Transport,
) -> None:
    """
    Sync files from a DC/OS checkout to master nodes.
    """
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(),
    )
    cluster_containers = ClusterContainers(
        cluster_id=cluster_id,
        transport=transport,
    )
    cluster = cluster_containers.cluster
    sync_code_to_masters(
        cluster=cluster,
        dcos_checkout_dir=dcos_checkout_dir,
        sudo=False,
    )
Esempio n. 26
0
def sync_code(
    cluster_id: str,
    dcos_checkout_dir: Path,
    aws_region: str,
) -> None:
    """
    Sync files from a DC/OS checkout to master nodes.
    """
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(aws_region=aws_region),
    )
    cluster_instances = ClusterInstances(
        cluster_id=cluster_id,
        aws_region=aws_region,
    )
    cluster = cluster_instances.cluster
    sync_code_to_masters(
        cluster=cluster,
        dcos_checkout_dir=dcos_checkout_dir,
        sudo=True,
    )
Esempio n. 27
0
def destroy_cluster(
    cluster_id: str,
    enable_spinner: bool,
    aws_region: str,
) -> None:
    """
    Destroy a cluster.

    Args:
        cluster_id: The ID of the cluster.
        enable_spinner: Whether to enable the spinner animation.
        aws_region: The region the cluster is in.
    """
    with Halo(enabled=enable_spinner):
        check_cluster_id_exists(
            new_cluster_id=cluster_id,
            existing_cluster_ids=existing_cluster_ids(aws_region=aws_region),
        )
        cluster_vms = ClusterInstances(
            cluster_id=cluster_id,
            aws_region=aws_region,
        )
        cluster_vms.destroy()
Esempio n. 28
0
def _destroy_cluster(
    cluster_id: str,
    transport: Transport,
    enable_spinner: bool,
) -> None:
    """
    Destroy a cluster.

    Args:
        cluster_id: The ID of the cluster.
        transport: The transport to use for any communication with the cluster.
        enable_spinner: Whether to enable the spinner animation.
    """
    with Halo(enabled=enable_spinner):
        check_cluster_id_exists(
            new_cluster_id=cluster_id,
            existing_cluster_ids=existing_cluster_ids(),
        )
        cluster_containers = ClusterContainers(
            cluster_id=cluster_id,
            transport=transport,
        )
        cluster_containers.destroy()
Esempio n. 29
0
def send_file(
    ctx: click.core.Context,
    cluster_id: str,
    node: Tuple[str],
    source: Path,
    destination: Path,
) -> None:
    """
    Send a file to a node or multiple nodes.
    """
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(),
    )

    cluster_vms = ClusterVMs(cluster_id=cluster_id)

    inspect_command_name = command_path(
        sibling_ctx=ctx,
        command=inspect_cluster,
    )

    hosts = get_nodes(
        cluster_id=cluster_id,
        cluster_representation=cluster_vms,
        node_references=node,
        inspect_command_name=inspect_command_name,
    )

    for host in hosts:
        host.send_file(
            local_path=source,
            remote_path=destination,
            transport=Transport.SSH,
            sudo=True,
        )
Esempio n. 30
0
def inspect_cluster(cluster_id: str, env: bool, verbose: int) -> None:
    """
    Show cluster details.

    To quickly get environment variables to use with Docker tooling, use the
    ``--env`` flag.

    Run ``eval $(minidcos docker inspect <CLUSTER_ID> --env)``, then run
    ``docker exec -it $MASTER_0`` to enter the first master, for example.
    """
    set_logging(verbosity_level=verbose)
    check_cluster_id_exists(
        new_cluster_id=cluster_id,
        existing_cluster_ids=existing_cluster_ids(),
    )
    cluster_containers = ClusterContainers(
        cluster_id=cluster_id,
        # The transport here is not relevant as we do not make calls to the
        # cluster.
        transport=Transport.DOCKER_EXEC,
    )
    master = next(iter(cluster_containers.masters))
    web_ui = 'http://' + master.attrs['NetworkSettings']['IPAddress']
    ssh_key = cluster_containers.workspace_dir / 'ssh' / 'id_rsa'

    keys = {
        'masters': cluster_containers.masters,
        'agents': cluster_containers.agents,
        'public_agents': cluster_containers.public_agents,
    }

    if env:
        env_dict = {}
        for _, containers in keys.items():
            for container in containers:
                inspect_view = ContainerInspectView(container=container)
                inspect_data = inspect_view.to_dict()
                reference = inspect_data['e2e_reference'].upper()
                env_dict[reference] = container.id
                node_ip_key = reference + '_IP'
                node_ip = container.attrs['NetworkSettings']['IPAddress']
                env_dict[node_ip_key] = node_ip
        env_dict['WEB_UI'] = web_ui
        env_dict['SSH_KEY'] = ssh_key
        for key, value in env_dict.items():
            click.echo('export {key}={value}'.format(key=key, value=value))
        return

    nodes = {
        key: [
            ContainerInspectView(container).to_dict()
            for container in containers
        ]
        for key, containers in keys.items()
    }

    data = {
        'Cluster ID': cluster_id,
        'Web UI': web_ui,
        'Nodes': nodes,
        'SSH key': str(ssh_key),
    }  # type: Dict[Any, Any]
    click.echo(
        json.dumps(data, indent=4, separators=(',', ': '), sort_keys=True), )