Exemplo n.º 1
0
def deploy_aws(args: argparse.Namespace) -> None:
    if args.aws_profile:
        boto3_session = boto3.Session(profile_name=args.aws_profile, region_name=args.region)
    else:
        boto3_session = boto3.Session(region_name=args.region)

    if boto3_session.region_name not in constants.misc.SUPPORTED_REGIONS:
        print(
            f"det-deploy is only supported in {constants.misc.SUPPORTED_REGIONS} - "
            f"tried to deploy to {boto3_session.region_name}"
        )
        print("use the --region argument to deploy to a supported region")
        sys.exit(1)

    if not re.match(constants.misc.CLOUDFORMATION_REGEX, args.cluster_id):
        print("Deployment Failed - cluster-id much match ^[a-zA-Z][-a-zA-Z0-9]*$")
        sys.exit(1)

    if args.command == "down":
        try:
            aws.delete(args.cluster_id, boto3_session)
        except Exception as e:
            print(e)
            print("Stack Deletion Failed. Check the AWS CloudFormation Console for details.")
            sys.exit(1)

        print("Delete Successful")
        return

    deployment_type_map = {
        constants.deployment_types.SIMPLE: simple.Simple,
        constants.deployment_types.SECURE: secure.Secure,
        constants.deployment_types.VPC: vpc.VPC,
    }  # type: Dict[str, Union[Type[simple.Simple], Type[secure.Secure], Type[vpc.VPC]]]

    det_configs = {
        constants.cloudformation.KEYPAIR: args.keypair,
        constants.cloudformation.MASTER_INSTANCE_TYPE: args.master_instance_type,
        constants.cloudformation.AGENT_INSTANCE_TYPE: args.agent_instance_type,
        constants.cloudformation.CLUSTER_ID: args.cluster_id,
        constants.cloudformation.BOTO3_SESSION: boto3_session,
        constants.cloudformation.VERSION: args.det_version,
        constants.cloudformation.INBOUND_CIDR: args.inbound_cidr,
        constants.cloudformation.DB_PASSWORD: args.db_password,
        constants.cloudformation.MAX_IDLE_AGENT_PERIOD: args.max_idle_agent_period,
        constants.cloudformation.MAX_AGENT_STARTING_PERIOD: args.max_agent_starting_period,
        constants.cloudformation.MAX_DYNAMIC_AGENTS: args.max_dynamic_agents,
    }

    deployment_object = deployment_type_map[args.deployment_type](det_configs)

    if args.dry_run:
        deployment_object.print()
        return

    print("Starting Determined Deployment")
    try:
        deployment_object.deploy()
    except Exception as e:
        print(e)
        print("Stack Deployment Failed. Check the AWS CloudFormation Console for details.")
        sys.exit(1)

    print("Determined Deployment Successful")
Exemplo n.º 2
0
def deploy_aws(args: argparse.Namespace) -> None:
    if args.aws_profile:
        boto3_session = boto3.Session(profile_name=args.aws_profile,
                                      region_name=args.region)
    else:
        boto3_session = boto3.Session(region_name=args.region)

    if boto3_session.region_name not in constants.misc.SUPPORTED_REGIONS:
        print(
            f"det-deploy is only supported in {constants.misc.SUPPORTED_REGIONS} - "
            f"tried to deploy to {boto3_session.region_name}")
        print("use the --region argument to deploy to a supported region")
        sys.exit(1)

    # TODO(DET-4258) Uncomment this when we fully support all P3 regions.
    # if boto3_session.region_name == "eu-west-2" and args.agent_instance_type is None:
    #     print(
    #         "the default agent instance type for det-deploy (p2.8xlarge) is not available in "
    #         "eu-west-2 (London).  Please specify an --agent-instance-type argument."
    #     )
    #     sys.exit(1)

    if not re.match(constants.misc.CLOUDFORMATION_REGEX, args.cluster_id):
        print(
            "Deployment Failed - cluster-id much match ^[a-zA-Z][-a-zA-Z0-9]*$"
        )
        sys.exit(1)

    if args.command == "down":
        try:
            aws.delete(args.cluster_id, boto3_session)
        except Exception as e:
            print(e)
            print(
                "Stack Deletion Failed. Check the AWS CloudFormation Console for details."
            )
            sys.exit(1)

        print("Delete Successful")
        return

    if (args.cpu_env_image
            and not args.gpu_env_image) or (args.gpu_env_image
                                            and not args.cpu_env_image):
        print(
            "If a CPU or GPU environment image is specified, both should be.")
        sys.exit(1)

    deployment_type_map = {
        constants.deployment_types.SIMPLE: simple.Simple,
        constants.deployment_types.SECURE: secure.Secure,
        constants.deployment_types.VPC: vpc.VPC,
        constants.deployment_types.EFS: vpc.EFS,
        constants.deployment_types.FSX: vpc.FSx,
    }  # type: Dict[str, Union[Type[base.DeterminedDeployment]]]

    if args.deployment_type != constants.deployment_types.SIMPLE:
        if args.agent_subnet_id != "":
            raise ValueError(
                f"The agent-subnet-id can only be set if the deployment-type=simple. "
                f"The agent-subnet-id was set to '{args.agent_subnet_id}', but the "
                f"deployment-type={args.deployment_type}.")

    master_tls_cert = master_tls_key = ""
    if args.master_tls_cert:
        with open(args.master_tls_cert, "rb") as f:
            master_tls_cert = base64.b64encode(f.read()).decode()
    if args.master_tls_key:
        with open(args.master_tls_key, "rb") as f:
            master_tls_key = base64.b64encode(f.read()).decode()

    det_configs = {
        constants.cloudformation.KEYPAIR: args.keypair,
        constants.cloudformation.ENABLE_CORS: args.enable_cors,
        constants.cloudformation.MASTER_TLS_CERT: master_tls_cert,
        constants.cloudformation.MASTER_TLS_KEY: master_tls_key,
        constants.cloudformation.MASTER_CERT_NAME: args.master_cert_name,
        constants.cloudformation.MASTER_INSTANCE_TYPE:
        args.master_instance_type,
        constants.cloudformation.AGENT_INSTANCE_TYPE: args.agent_instance_type,
        constants.cloudformation.CLUSTER_ID: args.cluster_id,
        constants.cloudformation.BOTO3_SESSION: boto3_session,
        constants.cloudformation.VERSION: args.det_version,
        constants.cloudformation.INBOUND_CIDR: args.inbound_cidr,
        constants.cloudformation.DB_PASSWORD: args.db_password,
        constants.cloudformation.MAX_IDLE_AGENT_PERIOD:
        args.max_idle_agent_period,
        constants.cloudformation.MAX_AGENT_STARTING_PERIOD:
        args.max_agent_starting_period,
        constants.cloudformation.MIN_DYNAMIC_AGENTS: args.min_dynamic_agents,
        constants.cloudformation.MAX_DYNAMIC_AGENTS: args.max_dynamic_agents,
        constants.cloudformation.SPOT_ENABLED: args.spot,
        constants.cloudformation.SPOT_MAX_PRICE: args.spot_max_price,
        constants.cloudformation.SUBNET_ID_KEY: args.agent_subnet_id,
        constants.cloudformation.SCHEDULER_TYPE: args.scheduler_type,
        constants.cloudformation.PREEMPTION_ENABLED: args.preemption_enabled,
        constants.cloudformation.CPU_ENV_IMAGE: args.cpu_env_image,
        constants.cloudformation.GPU_ENV_IMAGE: args.gpu_env_image,
    }

    deployment_object = deployment_type_map[args.deployment_type](det_configs)

    if args.dry_run:
        deployment_object.print()
        return

    print("Starting Determined Deployment")
    try:
        deployment_object.deploy()
    except Exception as e:
        print(e)
        print(
            "Stack Deployment Failed. Check the AWS CloudFormation Console for details."
        )
        sys.exit(1)

    print("Determined Deployment Successful")
Exemplo n.º 3
0
def deploy_aws(args: argparse.Namespace) -> None:
    if args.aws_profile:
        boto3_session = boto3.Session(profile_name=args.aws_profile,
                                      region_name=args.region)
    else:
        boto3_session = boto3.Session(region_name=args.region)

    if not re.match(constants.misc.CLOUDFORMATION_REGEX, args.cluster_id):
        print(
            "Deployment Failed - cluster-id much match ^[a-zA-Z][-a-zA-Z0-9]*$"
        )
        sys.exit(1)

    if args.command == "down":
        try:
            aws.delete(args.cluster_id, boto3_session)
        except Exception as e:
            print(e)
            print(
                "Stack Deletion Failed. Check the AWS CloudFormation Console for details."
            )
        print("Delete Successful")
        return

    deployment_type_map = {
        constants.deployment_types.SIMPLE: simple.Simple,
        constants.deployment_types.SECURE: secure.Secure,
        constants.deployment_types.VPC: vpc.VPC,
    }

    det_configs = {
        constants.cloudformation.MASTER_AMI: args.master_ami,
        constants.cloudformation.AGENT_AMI: args.agent_ami,
        constants.cloudformation.KEYPAIR: args.keypair,
        constants.cloudformation.MASTER_INSTANCE_TYPE:
        args.master_instance_type,
        constants.cloudformation.AGENT_INSTANCE_TYPE: args.agent_instance_type,
        constants.cloudformation.CLUSTER_ID: args.cluster_id,
        constants.cloudformation.BOTO3_SESSION: boto3_session,
        constants.cloudformation.VERSION: args.det_version,
        constants.cloudformation.INBOUND_CIDR: args.inbound_cidr,
        constants.cloudformation.DB_PASSWORD: args.db_password,
        constants.cloudformation.HASURA_SECRET: args.hasura_secret,
        constants.cloudformation.MAX_IDLE_AGENT_PERIOD:
        args.max_idle_agent_period,
        constants.cloudformation.MAX_INSTANCES: args.max_instances,
    }

    deployment_object = deployment_type_map[args.deployment_type](det_configs)

    if args.dry_run:
        deployment_object.print()
        return

    print("Starting Determined Deployment")
    try:
        deployment_object.deploy()
    except Exception as e:
        print(e)
        print(
            "Stack Deployment Failed. Check the AWS CloudFormation Console for details."
        )
        sys.exit(1)

    print("Determined Deployment Successful")