Path: blob/develop/awscli/customizations/emr/listclusters.py
1567 views
# Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.1#2# Licensed under the Apache License, Version 2.0 (the "License"). You3# may not use this file except in compliance with the License. A copy of4# the License is located at5#6# http://aws.amazon.com/apache2.0/7#8# or in the "license" file accompanying this file. This file is9# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF10# ANY KIND, either express or implied. See the License for the specific11# language governing permissions and limitations under the License.121314from awscli.arguments import CustomArgument15from awscli.customizations.emr import helptext16from awscli.customizations.emr import exceptions17from awscli.customizations.emr import constants181920def modify_list_clusters_argument(argument_table, **kwargs):21argument_table['cluster-states'] = \22ClusterStatesArgument(23name='cluster-states',24help_text=helptext.LIST_CLUSTERS_CLUSTER_STATES,25nargs='+')26argument_table['active'] = \27ActiveStateArgument(28name='active', help_text=helptext.LIST_CLUSTERS_STATE_FILTERS,29action='store_true', group_name='states_filter')30argument_table['terminated'] = \31TerminatedStateArgument(32name='terminated',33action='store_true', group_name='states_filter')34argument_table['failed'] = \35FailedStateArgument(36name='failed', action='store_true', group_name='states_filter')37argument_table['created-before'] = CreatedBefore(38name='created-before', help_text=helptext.LIST_CLUSTERS_CREATED_BEFORE,39cli_type_name='timestamp')40argument_table['created-after'] = CreatedAfter(41name='created-after', help_text=helptext.LIST_CLUSTERS_CREATED_AFTER,42cli_type_name='timestamp')434445class ClusterStatesArgument(CustomArgument):46def add_to_params(self, parameters, value):47if value is not None:48if (parameters.get('ClusterStates') is not None and49len(parameters.get('ClusterStates')) > 0):50raise exceptions.ClusterStatesFilterValidationError()51parameters['ClusterStates'] = value525354class ActiveStateArgument(CustomArgument):55def add_to_params(self, parameters, value):56if value is True:57if (parameters.get('ClusterStates') is not None and58len(parameters.get('ClusterStates')) > 0):59raise exceptions.ClusterStatesFilterValidationError()60parameters['ClusterStates'] = constants.LIST_CLUSTERS_ACTIVE_STATES616263class TerminatedStateArgument(CustomArgument):64def add_to_params(self, parameters, value):65if value is True:66if (parameters.get('ClusterStates') is not None and67len(parameters.get('ClusterStates')) > 0):68raise exceptions.ClusterStatesFilterValidationError()69parameters['ClusterStates'] = \70constants.LIST_CLUSTERS_TERMINATED_STATES717273class FailedStateArgument(CustomArgument):74def add_to_params(self, parameters, value):75if value is True:76if (parameters.get('ClusterStates') is not None and77len(parameters.get('ClusterStates')) > 0):78raise exceptions.ClusterStatesFilterValidationError()79parameters['ClusterStates'] = constants.LIST_CLUSTERS_FAILED_STATES808182class CreatedBefore(CustomArgument):83def add_to_params(self, parameters, value):84if value is None:85return86parameters['CreatedBefore'] = value878889class CreatedAfter(CustomArgument):90def add_to_params(self, parameters, value):91if value is None:92return93parameters['CreatedAfter'] = value949596