Path: blob/develop/awscli/customizations/emr/describecluster.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.commands import BasicCommand14from awscli.customizations.emr import constants15from awscli.customizations.emr import emrutils16from awscli.customizations.emr import helptext17from awscli.customizations.emr.command import Command18from botocore.exceptions import NoCredentialsError192021class DescribeCluster(Command):22NAME = 'describe-cluster'23DESCRIPTION = helptext.DESCRIBE_CLUSTER_DESCRIPTION24ARG_TABLE = [25{'name': 'cluster-id', 'required': True,26'help_text': helptext.CLUSTER_ID}27]2829def _run_main_command(self, parsed_args, parsed_globals):30parameters = {'ClusterId': parsed_args.cluster_id}31list_instance_fleets_result = None32list_instance_groups_result = None33is_fleet_based_cluster = False3435describe_cluster_result = self._call(36self._session, 'describe_cluster', parameters, parsed_globals)373839if 'Cluster' in describe_cluster_result:40describe_cluster = describe_cluster_result['Cluster']41if describe_cluster.get('InstanceCollectionType') == constants.INSTANCE_FLEET_TYPE:42is_fleet_based_cluster = True4344if is_fleet_based_cluster:45list_instance_fleets_result = self._call(46self._session, 'list_instance_fleets', parameters,47parsed_globals)48else:49list_instance_groups_result = self._call(50self._session, 'list_instance_groups', parameters,51parsed_globals)5253list_bootstrap_actions_result = self._call(54self._session, 'list_bootstrap_actions',55parameters, parsed_globals)5657constructed_result = self._construct_result(58describe_cluster_result,59list_instance_fleets_result,60list_instance_groups_result,61list_bootstrap_actions_result)6263emrutils.display_response(self._session, 'describe_cluster',64constructed_result, parsed_globals)6566return 06768def _call(self, session, operation_name, parameters, parsed_globals):69return emrutils.call(70session, operation_name, parameters,71region_name=self.region,72endpoint_url=parsed_globals.endpoint_url,73verify=parsed_globals.verify_ssl)7475def _get_key_of_result(self, keys):76# Return the first key that is not "Marker"77for key in keys:78if key != "Marker":79return key8081def _construct_result(82self, describe_cluster_result, list_instance_fleets_result,83list_instance_groups_result, list_bootstrap_actions_result):84result = describe_cluster_result85result['Cluster']['BootstrapActions'] = []8687if (list_instance_fleets_result is not None and88list_instance_fleets_result.get('InstanceFleets') is not None):89result['Cluster']['InstanceFleets'] = \90list_instance_fleets_result.get('InstanceFleets')91if (list_instance_groups_result is not None and92list_instance_groups_result.get('InstanceGroups') is not None):93result['Cluster']['InstanceGroups'] = \94list_instance_groups_result.get('InstanceGroups')95if (list_bootstrap_actions_result is not None and96list_bootstrap_actions_result.get('BootstrapActions')97is not None):98result['Cluster']['BootstrapActions'] = \99list_bootstrap_actions_result['BootstrapActions']100101return result102103104