Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/awscli/customizations/emr/modifyclusterattributes.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
from awscli.customizations.emr import emrutils
15
from awscli.customizations.emr import exceptions
16
from awscli.customizations.emr import helptext
17
from awscli.customizations.emr.command import Command
18
19
20
class ModifyClusterAttr(Command):
21
NAME = 'modify-cluster-attributes'
22
DESCRIPTION = ("Modifies the cluster attributes 'visible-to-all-users', "
23
" 'termination-protected' and 'unhealthy-node-replacement'.")
24
ARG_TABLE = [
25
{'name': 'cluster-id', 'required': True,
26
'help_text': helptext.CLUSTER_ID},
27
{'name': 'visible-to-all-users', 'required': False, 'action':
28
'store_true', 'group_name': 'visible',
29
'help_text': helptext.VISIBILITY},
30
{'name': 'no-visible-to-all-users', 'required': False, 'action':
31
'store_true', 'group_name': 'visible',
32
'help_text': helptext.VISIBILITY},
33
{'name': 'termination-protected', 'required': False, 'action':
34
'store_true', 'group_name': 'terminate',
35
'help_text': 'Set termination protection on or off'},
36
{'name': 'no-termination-protected', 'required': False, 'action':
37
'store_true', 'group_name': 'terminate',
38
'help_text': 'Set termination protection on or off'},
39
{'name': 'auto-terminate', 'required': False, 'action':
40
'store_true', 'group_name': 'auto_terminate',
41
'help_text': 'Set cluster auto terminate after completing all the steps on or off'},
42
{'name': 'no-auto-terminate', 'required': False, 'action':
43
'store_true', 'group_name': 'auto_terminate',
44
'help_text': 'Set cluster auto terminate after completing all the steps on or off'},
45
{'name': 'unhealthy-node-replacement', 'required': False, 'action':
46
'store_true', 'group_name': 'UnhealthyReplacement',
47
'help_text': 'Set Unhealthy Node Replacement on or off'},
48
{'name': 'no-unhealthy-node-replacement', 'required': False, 'action':
49
'store_true', 'group_name': 'UnhealthyReplacement',
50
'help_text': 'Set Unhealthy Node Replacement on or off'},
51
]
52
53
def _run_main_command(self, args, parsed_globals):
54
55
if (args.visible_to_all_users and args.no_visible_to_all_users):
56
raise exceptions.MutualExclusiveOptionError(
57
option1='--visible-to-all-users',
58
option2='--no-visible-to-all-users')
59
if (args.termination_protected and args.no_termination_protected):
60
raise exceptions.MutualExclusiveOptionError(
61
option1='--termination-protected',
62
option2='--no-termination-protected')
63
if (args.auto_terminate and args.no_auto_terminate):
64
raise exceptions.MutualExclusiveOptionError(
65
option1='--auto-terminate',
66
option2='--no-auto-terminate')
67
if (args.unhealthy_node_replacement and args.no_unhealthy_node_replacement):
68
raise exceptions.MutualExclusiveOptionError(
69
option1='--unhealthy-node-replacement',
70
option2='--no-unhealthy-node-replacement')
71
if not(args.termination_protected or args.no_termination_protected or
72
args.visible_to_all_users or args.no_visible_to_all_users or
73
args.auto_terminate or args.no_auto_terminate or
74
args.unhealthy_node_replacement or args.no_unhealthy_node_replacement):
75
raise exceptions.MissingClusterAttributesError()
76
77
if (args.visible_to_all_users or args.no_visible_to_all_users):
78
visible = (args.visible_to_all_users and
79
not args.no_visible_to_all_users)
80
parameters = {'JobFlowIds': [args.cluster_id],
81
'VisibleToAllUsers': visible}
82
emrutils.call_and_display_response(self._session,
83
'SetVisibleToAllUsers',
84
parameters, parsed_globals)
85
86
if (args.termination_protected or args.no_termination_protected):
87
protected = (args.termination_protected and
88
not args.no_termination_protected)
89
parameters = {'JobFlowIds': [args.cluster_id],
90
'TerminationProtected': protected}
91
emrutils.call_and_display_response(self._session,
92
'SetTerminationProtection',
93
parameters, parsed_globals)
94
95
if (args.auto_terminate or args.no_auto_terminate):
96
auto_terminate = (args.auto_terminate and
97
not args.no_auto_terminate)
98
parameters = {'JobFlowIds': [args.cluster_id],
99
'KeepJobFlowAliveWhenNoSteps': not auto_terminate}
100
emrutils.call_and_display_response(self._session,
101
'SetKeepJobFlowAliveWhenNoSteps',
102
parameters, parsed_globals)
103
104
if (args.unhealthy_node_replacement or args.no_unhealthy_node_replacement):
105
protected = (args.unhealthy_node_replacement and
106
not args.no_unhealthy_node_replacement)
107
parameters = {'JobFlowIds': [args.cluster_id],
108
'UnhealthyNodeReplacement': protected}
109
emrutils.call_and_display_response(self._session,
110
'SetUnhealthyNodeReplacement',
111
parameters, parsed_globals)
112
113
return 0
114
115