def delete_cluster(cluster_name: str, region: str, keep_logs: bool = True): """Delete cluster.""" cluster = None try: if region: os.environ["AWS_DEFAULT_REGION"] = region # retrieve cluster config and generate model cluster = Cluster(cluster_name) cluster.delete(keep_logs) return ClusterInfo(cluster.stack) except Exception as e: if cluster: cluster.terminate_nodes() return ApiFailure(str(e))
def delete_cluster(cluster_name, region=None): """ Initiate the deletion of a cluster. :param cluster_name: Name of the cluster :type cluster_name: str :param region: AWS Region that the operation corresponds to. :type region: str :rtype: DeleteClusterResponseContent """ try: cluster = Cluster(cluster_name) if not check_cluster_version(cluster): raise BadRequestException( f"Cluster '{cluster_name}' belongs to an incompatible ParallelCluster major version." ) if not cluster.status == CloudFormationStackStatus.DELETE_IN_PROGRESS: # TODO: remove keep_logs logic from delete cluster.delete(keep_logs=False) return DeleteClusterResponseContent( cluster=ClusterInfoSummary( cluster_name=cluster_name, cloudformation_stack_status=CloudFormationStackStatus.DELETE_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.DELETE_IN_PROGRESS), ) ) except StackNotFoundError: raise NotFoundException( f"Cluster '{cluster_name}' does not exist or belongs to an incompatible ParallelCluster major version. " "In case you have running instances belonging to a deleted cluster please use the DeleteClusterInstances " "API." )