def update_cluster( cluster_config: str, cluster_name: str, region: str, suppress_validators: bool = False, validation_failure_level: FailureLevel = FailureLevel.ERROR, force: bool = False, ): """ Update existing cluster. :param cluster_config: cluster configuration (str) :param cluster_name: the name to assign to the cluster :param region: AWS region :param suppress_validators: bool = False, :param validation_failure_level: FailureLevel = FailureLevel.ERROR, :param force: set to True to force stack update """ try: if region: os.environ["AWS_DEFAULT_REGION"] = region # Check if stack version matches with running version. cluster = Cluster(cluster_name) installed_version = get_installed_version() if cluster.stack.version != installed_version: raise ClusterActionError( "The cluster was created with a different version of " f"ParallelCluster: {cluster.stack.version}. Installed version is {installed_version}. " "This operation may only be performed using the same ParallelCluster " "version used to create the cluster.") validator_suppressors = set() if suppress_validators: validator_suppressors.add(AllValidatorsSuppressor()) cluster.update(cluster_config, validator_suppressors, validation_failure_level, force) # TODO add dryrun return ClusterInfo(cluster.stack) except ConfigValidationError as e: return ApiFailure(str(e), validation_failures=e.validation_failures) except ClusterUpdateError as e: return ApiFailure(str(e), update_changes=e.update_changes) except Exception as e: return ApiFailure(str(e))
def update_cluster( update_cluster_request_content: Dict, cluster_name, suppress_validators=None, validation_failure_level=None, region=None, dryrun=None, force_update=None, ): """ Update a cluster managed in a given region. :param update_cluster_request_content: :param cluster_name: Name of the cluster :type cluster_name: str :param suppress_validators: Identifies one or more config validators to suppress. Format: (ALL|type:[A-Za-z0-9]+) :type suppress_validators: List[str] :param validation_failure_level: Min validation level that will cause the update to fail. (Defaults to 'error'.) :type validation_failure_level: dict | bytes :param region: AWS Region that the operation corresponds to. :type region: str :param dryrun: Only perform request validation without creating any resource. May be used to validate the cluster configuration and update requirements. Response code: 200 :type dryrun: bool :param force_update: Force update by ignoring the update validation errors. (Defaults to 'false'.) :type force_update: bool :rtype: UpdateClusterResponseContent """ # Set defaults validation_failure_level = validation_failure_level or ValidationLevel.ERROR dryrun = dryrun is True force_update = force_update is True update_cluster_request_content = UpdateClusterRequestContent.from_dict(update_cluster_request_content) cluster_config = update_cluster_request_content.cluster_configuration if not cluster_config: LOGGER.error("Failed: configuration is required and cannot be empty") raise BadRequestException("configuration is required and cannot be empty") try: cluster = Cluster(cluster_name) if not check_cluster_version(cluster, exact_match=True): raise BadRequestException( f"the update can be performed only with the same ParallelCluster version ({cluster.stack.version}) " "used to create the cluster." ) if dryrun: _, changes, ignored_validation_failures = cluster.validate_update_request( target_source_config=cluster_config, force=force_update, validator_suppressors=get_validator_suppressors(suppress_validators), validation_failure_level=FailureLevel[validation_failure_level], ) change_set, _ = _analyze_changes(changes) validation_messages = validation_results_to_config_validation_errors(ignored_validation_failures) raise DryrunOperationException(change_set=change_set, validation_messages=validation_messages or None) changes, ignored_validation_failures = cluster.update( target_source_config=cluster_config, validator_suppressors=get_validator_suppressors(suppress_validators), validation_failure_level=FailureLevel[validation_failure_level], force=force_update, ) change_set, _ = _analyze_changes(changes) return UpdateClusterResponseContent( cluster=ClusterInfoSummary( cluster_name=cluster_name, cloudformation_stack_status=CloudFormationStackStatus.UPDATE_IN_PROGRESS, cloudformation_stack_arn=cluster.stack.id, region=os.environ.get("AWS_DEFAULT_REGION"), version=cluster.stack.version, cluster_status=cloud_formation_status_to_cluster_status(CloudFormationStackStatus.UPDATE_IN_PROGRESS), ), validation_messages=validation_results_to_config_validation_errors(ignored_validation_failures) or None, change_set=change_set, ) except ConfigValidationError as e: config_validation_messages = validation_results_to_config_validation_errors(e.validation_failures) or None raise UpdateClusterBadRequestException( UpdateClusterBadRequestExceptionResponseContent( configuration_validation_errors=config_validation_messages, message=str(e) ) ) except ClusterUpdateError as e: raise _handle_cluster_update_error(e) except (NotFoundClusterActionError, StackNotFoundError): raise NotFoundException( f"Cluster '{cluster_name}' does not exist or belongs to an incompatible ParallelCluster major version." )