Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/awscli/customizations/emr/describecluster.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.commands import BasicCommand
15
from awscli.customizations.emr import constants
16
from awscli.customizations.emr import emrutils
17
from awscli.customizations.emr import helptext
18
from awscli.customizations.emr.command import Command
19
from botocore.exceptions import NoCredentialsError
20
21
22
class DescribeCluster(Command):
23
NAME = 'describe-cluster'
24
DESCRIPTION = helptext.DESCRIBE_CLUSTER_DESCRIPTION
25
ARG_TABLE = [
26
{'name': 'cluster-id', 'required': True,
27
'help_text': helptext.CLUSTER_ID}
28
]
29
30
def _run_main_command(self, parsed_args, parsed_globals):
31
parameters = {'ClusterId': parsed_args.cluster_id}
32
list_instance_fleets_result = None
33
list_instance_groups_result = None
34
is_fleet_based_cluster = False
35
36
describe_cluster_result = self._call(
37
self._session, 'describe_cluster', parameters, parsed_globals)
38
39
40
if 'Cluster' in describe_cluster_result:
41
describe_cluster = describe_cluster_result['Cluster']
42
if describe_cluster.get('InstanceCollectionType') == constants.INSTANCE_FLEET_TYPE:
43
is_fleet_based_cluster = True
44
45
if is_fleet_based_cluster:
46
list_instance_fleets_result = self._call(
47
self._session, 'list_instance_fleets', parameters,
48
parsed_globals)
49
else:
50
list_instance_groups_result = self._call(
51
self._session, 'list_instance_groups', parameters,
52
parsed_globals)
53
54
list_bootstrap_actions_result = self._call(
55
self._session, 'list_bootstrap_actions',
56
parameters, parsed_globals)
57
58
constructed_result = self._construct_result(
59
describe_cluster_result,
60
list_instance_fleets_result,
61
list_instance_groups_result,
62
list_bootstrap_actions_result)
63
64
emrutils.display_response(self._session, 'describe_cluster',
65
constructed_result, parsed_globals)
66
67
return 0
68
69
def _call(self, session, operation_name, parameters, parsed_globals):
70
return emrutils.call(
71
session, operation_name, parameters,
72
region_name=self.region,
73
endpoint_url=parsed_globals.endpoint_url,
74
verify=parsed_globals.verify_ssl)
75
76
def _get_key_of_result(self, keys):
77
# Return the first key that is not "Marker"
78
for key in keys:
79
if key != "Marker":
80
return key
81
82
def _construct_result(
83
self, describe_cluster_result, list_instance_fleets_result,
84
list_instance_groups_result, list_bootstrap_actions_result):
85
result = describe_cluster_result
86
result['Cluster']['BootstrapActions'] = []
87
88
if (list_instance_fleets_result is not None and
89
list_instance_fleets_result.get('InstanceFleets') is not None):
90
result['Cluster']['InstanceFleets'] = \
91
list_instance_fleets_result.get('InstanceFleets')
92
if (list_instance_groups_result is not None and
93
list_instance_groups_result.get('InstanceGroups') is not None):
94
result['Cluster']['InstanceGroups'] = \
95
list_instance_groups_result.get('InstanceGroups')
96
if (list_bootstrap_actions_result is not None and
97
list_bootstrap_actions_result.get('BootstrapActions')
98
is not None):
99
result['Cluster']['BootstrapActions'] = \
100
list_bootstrap_actions_result['BootstrapActions']
101
102
return result
103
104