Path: blob/develop/awscli/customizations/emr/modifyclusterattributes.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.1213from awscli.customizations.emr import emrutils14from awscli.customizations.emr import exceptions15from awscli.customizations.emr import helptext16from awscli.customizations.emr.command import Command171819class ModifyClusterAttr(Command):20NAME = 'modify-cluster-attributes'21DESCRIPTION = ("Modifies the cluster attributes 'visible-to-all-users', "22" 'termination-protected' and 'unhealthy-node-replacement'.")23ARG_TABLE = [24{'name': 'cluster-id', 'required': True,25'help_text': helptext.CLUSTER_ID},26{'name': 'visible-to-all-users', 'required': False, 'action':27'store_true', 'group_name': 'visible',28'help_text': helptext.VISIBILITY},29{'name': 'no-visible-to-all-users', 'required': False, 'action':30'store_true', 'group_name': 'visible',31'help_text': helptext.VISIBILITY},32{'name': 'termination-protected', 'required': False, 'action':33'store_true', 'group_name': 'terminate',34'help_text': 'Set termination protection on or off'},35{'name': 'no-termination-protected', 'required': False, 'action':36'store_true', 'group_name': 'terminate',37'help_text': 'Set termination protection on or off'},38{'name': 'auto-terminate', 'required': False, 'action':39'store_true', 'group_name': 'auto_terminate',40'help_text': 'Set cluster auto terminate after completing all the steps on or off'},41{'name': 'no-auto-terminate', 'required': False, 'action':42'store_true', 'group_name': 'auto_terminate',43'help_text': 'Set cluster auto terminate after completing all the steps on or off'},44{'name': 'unhealthy-node-replacement', 'required': False, 'action':45'store_true', 'group_name': 'UnhealthyReplacement',46'help_text': 'Set Unhealthy Node Replacement on or off'},47{'name': 'no-unhealthy-node-replacement', 'required': False, 'action':48'store_true', 'group_name': 'UnhealthyReplacement',49'help_text': 'Set Unhealthy Node Replacement on or off'},50]5152def _run_main_command(self, args, parsed_globals):5354if (args.visible_to_all_users and args.no_visible_to_all_users):55raise exceptions.MutualExclusiveOptionError(56option1='--visible-to-all-users',57option2='--no-visible-to-all-users')58if (args.termination_protected and args.no_termination_protected):59raise exceptions.MutualExclusiveOptionError(60option1='--termination-protected',61option2='--no-termination-protected')62if (args.auto_terminate and args.no_auto_terminate):63raise exceptions.MutualExclusiveOptionError(64option1='--auto-terminate',65option2='--no-auto-terminate')66if (args.unhealthy_node_replacement and args.no_unhealthy_node_replacement):67raise exceptions.MutualExclusiveOptionError(68option1='--unhealthy-node-replacement',69option2='--no-unhealthy-node-replacement')70if not(args.termination_protected or args.no_termination_protected or71args.visible_to_all_users or args.no_visible_to_all_users or72args.auto_terminate or args.no_auto_terminate or73args.unhealthy_node_replacement or args.no_unhealthy_node_replacement):74raise exceptions.MissingClusterAttributesError()7576if (args.visible_to_all_users or args.no_visible_to_all_users):77visible = (args.visible_to_all_users and78not args.no_visible_to_all_users)79parameters = {'JobFlowIds': [args.cluster_id],80'VisibleToAllUsers': visible}81emrutils.call_and_display_response(self._session,82'SetVisibleToAllUsers',83parameters, parsed_globals)8485if (args.termination_protected or args.no_termination_protected):86protected = (args.termination_protected and87not args.no_termination_protected)88parameters = {'JobFlowIds': [args.cluster_id],89'TerminationProtected': protected}90emrutils.call_and_display_response(self._session,91'SetTerminationProtection',92parameters, parsed_globals)9394if (args.auto_terminate or args.no_auto_terminate):95auto_terminate = (args.auto_terminate and96not args.no_auto_terminate)97parameters = {'JobFlowIds': [args.cluster_id],98'KeepJobFlowAliveWhenNoSteps': not auto_terminate}99emrutils.call_and_display_response(self._session,100'SetKeepJobFlowAliveWhenNoSteps',101parameters, parsed_globals)102103if (args.unhealthy_node_replacement or args.no_unhealthy_node_replacement):104protected = (args.unhealthy_node_replacement and105not args.no_unhealthy_node_replacement)106parameters = {'JobFlowIds': [args.cluster_id],107'UnhealthyNodeReplacement': protected}108emrutils.call_and_display_response(self._session,109'SetUnhealthyNodeReplacement',110parameters, parsed_globals)111112return 0113114115