def configure(args): # Check for invalid path (eg. a directory) if args.config_file and os.path.exists( args.config_file) and not os.path.isfile(args.config_file): error("Invalid configuration file path: {0}".format(args.config_file)) pcluster_config = PclusterConfig(config_file=args.config_file, fail_on_error=False, auto_refresh=False) # FIXME: Overriding HIT config files is currently not supported. if pcluster_config.cluster_model == ClusterModel.HIT: error( "Configuration in file {0} cannot be overwritten. Please specify a different file path" .format(pcluster_config.config_file)) if os.path.exists(pcluster_config.config_file): msg = "WARNING: Configuration file {0} will be overwritten." else: msg = "INFO: Configuration file {0} will be written." print(msg.format(pcluster_config.config_file)) print("Press CTRL-C to interrupt the procedure.\n\n") if not args.region: # Use built in boto regions as an available option available_regions = get_regions() default_region = pcluster_config.get_section("aws").get_param_value( "aws_region_name") aws_region_name = prompt_iterable("AWS Region ID", available_regions, default_value=default_region) # Set provided region into os environment for suggestions and validations from here on os.environ["AWS_DEFAULT_REGION"] = aws_region_name else: aws_region_name = args.region cluster_section = pcluster_config.get_section("cluster") global_config = pcluster_config.get_section("global") cluster_label = global_config.get_param_value("cluster_template") vpc_section = pcluster_config.get_section("vpc") vpc_label = vpc_section.label # Get the key name from the current region, if any available_keys = _get_keys() default_key = cluster_section.get_param_value("key_name") key_name = prompt_iterable("EC2 Key Pair Name", available_keys, default_value=default_key) scheduler = prompt_iterable( "Scheduler", get_supported_schedulers(), default_value=cluster_section.get_param_value("scheduler")) cluster_config = ClusterConfigureHelper(cluster_section, scheduler) cluster_config.prompt_os() cluster_config.prompt_cluster_size() cluster_config.prompt_instance_types() vpc_parameters = _create_vpc_parameters(vpc_section, cluster_config) # Here is the end of prompt. Code below assembles config and write to file cluster_parameters = {"key_name": key_name, "scheduler": scheduler} cluster_parameters.update(cluster_config.get_scheduler_parameters()) # Remove parameters from the past configuration that can conflict with the user's choices. _reset_config_params(cluster_section, cluster_config.get_parameters_to_reset()) _reset_config_params( vpc_section, ("compute_subnet_id", "use_public_ips", "compute_subnet_cidr")) # Update configuration values according to user's choices pcluster_config.region = aws_region_name cluster_section.label = cluster_label for param_key, param_value in cluster_parameters.items(): param = cluster_section.get_param(param_key) param.value = param.get_value_from_string(param_value) vpc_section.label = vpc_label for param_key, param_value in vpc_parameters.items(): param = vpc_section.get_param(param_key) param.value = param.get_value_from_string(param_value) # Update internal params according to provided parameters and enable auto-refresh before eventual hit conversion pcluster_config.refresh() pcluster_config.auto_refresh = True # Convert file if needed HitConverter(pcluster_config).convert(prepare_to_file=True) # Update config file by overriding changed settings pcluster_config.to_file() print("Configuration file written to {0}".format( pcluster_config.config_file)) print( "You can edit your configuration file or simply run 'pcluster create -c {0} cluster-name' " "to create your cluster".format(pcluster_config.config_file))
def configure(args): # Check for invalid path (eg. a directory) if args.config_file and os.path.exists( args.config_file) and not os.path.isfile(args.config_file): error("Invalid configuration file path: {0}".format(args.config_file)) pcluster_config = PclusterConfig(config_file=args.config_file, fail_on_error=False) if os.path.exists(pcluster_config.config_file): msg = "WARNING: Configuration file {0} will be overwritten." else: msg = "INFO: Configuration file {0} will be written." print(msg.format(pcluster_config.config_file)) print("Press CTRL-C to interrupt the procedure.\n\n") cluster_section = pcluster_config.get_section("cluster") global_config = pcluster_config.get_section("global") cluster_label = global_config.get_param_value("cluster_template") vpc_section = pcluster_config.get_section("vpc") vpc_label = vpc_section.label # Use built in boto regions as an available option available_regions = get_regions() default_region = pcluster_config.get_section("aws").get_param_value( "aws_region_name") aws_region_name = prompt_iterable( "AWS Region ID", available_regions, default_value=default_region if default_region in available_regions else None, ) # Set provided region into os environment for suggestions and validations from here on os.environ["AWS_DEFAULT_REGION"] = aws_region_name # Get the key name from the current region, if any available_keys = _get_keys() default_key = cluster_section.get_param_value("key_name") key_name = prompt_iterable( "EC2 Key Pair Name", available_keys, default_value=default_key if default_key in available_keys else None) scheduler = prompt_iterable( "Scheduler", get_supported_schedulers(), default_value=cluster_section.get_param_value("scheduler")) scheduler_handler = SchedulerHandler(cluster_section, scheduler) scheduler_handler.prompt_os() scheduler_handler.prompt_cluster_size() master_instance_type = prompt( "Master instance type", lambda x: x in get_supported_instance_types(), default_value=cluster_section.get_param_value("master_instance_type"), ) scheduler_handler.prompt_compute_instance_type() automate_vpc = prompt("Automate VPC creation? (y/n)", lambda x: x in ("y", "n"), default_value="n") == "y" vpc_parameters = _create_vpc_parameters(vpc_section, scheduler, scheduler_handler.max_cluster_size, automate_vpc_creation=automate_vpc) cluster_parameters = { "key_name": key_name, "scheduler": scheduler, "master_instance_type": master_instance_type } cluster_parameters.update(scheduler_handler.get_scheduler_parameters()) # Remove parameters from the past configuration that can conflict with the user's choices. _reset_config_params(cluster_section, scheduler_handler.get_parameters_to_reset()) _reset_config_params( vpc_section, ("compute_subnet_id", "use_public_ips", "compute_subnet_cidr")) # Update configuration values according to user's choices pcluster_config.region = aws_region_name cluster_section.label = cluster_label for param_key, param_value in cluster_parameters.items(): param = cluster_section.get_param(param_key) param.value = param.get_value_from_string(param_value) vpc_section.label = vpc_label for param_key, param_value in vpc_parameters.items(): param = vpc_section.get_param(param_key) param.value = param.get_value_from_string(param_value) # Update config file by overriding changed settings pcluster_config.to_file() print("Configuration file written to {0}".format( pcluster_config.config_file)) print( "You can edit your configuration file or simply run 'pcluster create -c {0} cluster-name' " "to create your cluster".format(pcluster_config.config_file))