Path: blob/develop/awscli/customizations/emr/addinstancegroups.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.customizations.emr import argumentschema15from awscli.customizations.emr import emrutils16from awscli.customizations.emr import helptext17from awscli.customizations.emr import instancegroupsutils18from awscli.customizations.emr.command import Command192021class AddInstanceGroups(Command):22NAME = 'add-instance-groups'23DESCRIPTION = 'Adds an instance group to a running cluster.'24ARG_TABLE = [25{'name': 'cluster-id', 'required': True,26'help_text': helptext.CLUSTER_ID},27{'name': 'instance-groups', 'required': True,28'help_text': helptext.INSTANCE_GROUPS,29'schema': argumentschema.INSTANCE_GROUPS_SCHEMA}30]3132def _run_main_command(self, parsed_args, parsed_globals):33parameters = {'JobFlowId': parsed_args.cluster_id}34parameters['InstanceGroups'] = \35instancegroupsutils.build_instance_groups(36parsed_args.instance_groups)3738add_instance_groups_response = emrutils.call(39self._session, 'add_instance_groups', parameters,40self.region, parsed_globals.endpoint_url,41parsed_globals.verify_ssl)4243constructed_result = self._construct_result(44add_instance_groups_response)4546emrutils.display_response(self._session, 'add_instance_groups',47constructed_result, parsed_globals)48return 04950def _construct_result(self, add_instance_groups_result):51jobFlowId = None52instanceGroupIds = None53clusterArn = None54if add_instance_groups_result is not None:55jobFlowId = add_instance_groups_result.get('JobFlowId')56instanceGroupIds = add_instance_groups_result.get(57'InstanceGroupIds')58clusterArn = add_instance_groups_result.get('ClusterArn')5960if jobFlowId is not None and instanceGroupIds is not None:61return {'ClusterId': jobFlowId,62'InstanceGroupIds': instanceGroupIds,63'ClusterArn': clusterArn}64else:65return {}666768