Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/awscli/customizations/emr/addinstancegroups.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.customizations.emr import argumentschema
16
from awscli.customizations.emr import emrutils
17
from awscli.customizations.emr import helptext
18
from awscli.customizations.emr import instancegroupsutils
19
from awscli.customizations.emr.command import Command
20
21
22
class AddInstanceGroups(Command):
23
NAME = 'add-instance-groups'
24
DESCRIPTION = 'Adds an instance group to a running cluster.'
25
ARG_TABLE = [
26
{'name': 'cluster-id', 'required': True,
27
'help_text': helptext.CLUSTER_ID},
28
{'name': 'instance-groups', 'required': True,
29
'help_text': helptext.INSTANCE_GROUPS,
30
'schema': argumentschema.INSTANCE_GROUPS_SCHEMA}
31
]
32
33
def _run_main_command(self, parsed_args, parsed_globals):
34
parameters = {'JobFlowId': parsed_args.cluster_id}
35
parameters['InstanceGroups'] = \
36
instancegroupsutils.build_instance_groups(
37
parsed_args.instance_groups)
38
39
add_instance_groups_response = emrutils.call(
40
self._session, 'add_instance_groups', parameters,
41
self.region, parsed_globals.endpoint_url,
42
parsed_globals.verify_ssl)
43
44
constructed_result = self._construct_result(
45
add_instance_groups_response)
46
47
emrutils.display_response(self._session, 'add_instance_groups',
48
constructed_result, parsed_globals)
49
return 0
50
51
def _construct_result(self, add_instance_groups_result):
52
jobFlowId = None
53
instanceGroupIds = None
54
clusterArn = None
55
if add_instance_groups_result is not None:
56
jobFlowId = add_instance_groups_result.get('JobFlowId')
57
instanceGroupIds = add_instance_groups_result.get(
58
'InstanceGroupIds')
59
clusterArn = add_instance_groups_result.get('ClusterArn')
60
61
if jobFlowId is not None and instanceGroupIds is not None:
62
return {'ClusterId': jobFlowId,
63
'InstanceGroupIds': instanceGroupIds,
64
'ClusterArn': clusterArn}
65
else:
66
return {}
67
68