Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/awscli/customizations/emr/listclusters.py
1567 views
1
# Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
14
15
from awscli.arguments import CustomArgument
16
from awscli.customizations.emr import helptext
17
from awscli.customizations.emr import exceptions
18
from awscli.customizations.emr import constants
19
20
21
def modify_list_clusters_argument(argument_table, **kwargs):
22
argument_table['cluster-states'] = \
23
ClusterStatesArgument(
24
name='cluster-states',
25
help_text=helptext.LIST_CLUSTERS_CLUSTER_STATES,
26
nargs='+')
27
argument_table['active'] = \
28
ActiveStateArgument(
29
name='active', help_text=helptext.LIST_CLUSTERS_STATE_FILTERS,
30
action='store_true', group_name='states_filter')
31
argument_table['terminated'] = \
32
TerminatedStateArgument(
33
name='terminated',
34
action='store_true', group_name='states_filter')
35
argument_table['failed'] = \
36
FailedStateArgument(
37
name='failed', action='store_true', group_name='states_filter')
38
argument_table['created-before'] = CreatedBefore(
39
name='created-before', help_text=helptext.LIST_CLUSTERS_CREATED_BEFORE,
40
cli_type_name='timestamp')
41
argument_table['created-after'] = CreatedAfter(
42
name='created-after', help_text=helptext.LIST_CLUSTERS_CREATED_AFTER,
43
cli_type_name='timestamp')
44
45
46
class ClusterStatesArgument(CustomArgument):
47
def add_to_params(self, parameters, value):
48
if value is not None:
49
if (parameters.get('ClusterStates') is not None and
50
len(parameters.get('ClusterStates')) > 0):
51
raise exceptions.ClusterStatesFilterValidationError()
52
parameters['ClusterStates'] = value
53
54
55
class ActiveStateArgument(CustomArgument):
56
def add_to_params(self, parameters, value):
57
if value is True:
58
if (parameters.get('ClusterStates') is not None and
59
len(parameters.get('ClusterStates')) > 0):
60
raise exceptions.ClusterStatesFilterValidationError()
61
parameters['ClusterStates'] = constants.LIST_CLUSTERS_ACTIVE_STATES
62
63
64
class TerminatedStateArgument(CustomArgument):
65
def add_to_params(self, parameters, value):
66
if value is True:
67
if (parameters.get('ClusterStates') is not None and
68
len(parameters.get('ClusterStates')) > 0):
69
raise exceptions.ClusterStatesFilterValidationError()
70
parameters['ClusterStates'] = \
71
constants.LIST_CLUSTERS_TERMINATED_STATES
72
73
74
class FailedStateArgument(CustomArgument):
75
def add_to_params(self, parameters, value):
76
if value is True:
77
if (parameters.get('ClusterStates') is not None and
78
len(parameters.get('ClusterStates')) > 0):
79
raise exceptions.ClusterStatesFilterValidationError()
80
parameters['ClusterStates'] = constants.LIST_CLUSTERS_FAILED_STATES
81
82
83
class CreatedBefore(CustomArgument):
84
def add_to_params(self, parameters, value):
85
if value is None:
86
return
87
parameters['CreatedBefore'] = value
88
89
90
class CreatedAfter(CustomArgument):
91
def add_to_params(self, parameters, value):
92
if value is None:
93
return
94
parameters['CreatedAfter'] = value
95
96