def get_cluster_nodes(cluster_id, role=None): emr_client = connect_emr(role=role) result = run_func(emr_client.list_instances, ClusterId=cluster_id, InstanceStates=['AWAITING_FULFILLMENT', 'PROVISIONING', 'BOOTSTRAPPING', 'RUNNING'], cache_duration_secs=QUERY_CACHE_TIMEOUT) result = json.loads(result) result = result['Instances'] # read domain name config custom_dn = config.get_value(constants.KEY_CUSTOM_DOMAIN_NAME, section=SECTION_EMR, resource=cluster_id) i = 0 while i < len(result): inst = result[i] if inst['Status']['State'] == INSTANCE_STATE_TERMINATED: del result[i] i -= 1 else: inst['cid'] = inst['Id'] if 'Id' in inst else 'n/a' inst['iid'] = inst['Ec2InstanceId'] if 'Ec2InstanceId' in inst else 'n/a' inst['gid'] = inst['InstanceGroupId'] if 'InstanceGroupId' in inst else 'n/a' inst['ip'] = inst['PrivateIpAddress'] if 'PrivateIpAddress' in inst else 'n/a' inst['host'] = inst['PrivateDnsName'] if 'PrivateDnsName' in inst else 'n/a' if custom_dn: inst['host'] = ip_to_hostname(hostname_to_ip(inst['host']), custom_dn) inst['type'] = get_instance_group_type(cluster_id, inst['InstanceGroupId'], role=role) inst['state'] = inst['Status']['State'] inst['market'] = get_instance_group_details(cluster_id, inst['InstanceGroupId'], role=role)['Market'] i += 1 return result
def get_instance_by_ip(ip, role=None): ec2_client = connect_ec2(role=role) result = run_func(ec2_client.describe_instances, Filters=[{'Name': 'private-ip-address', 'Values': [ip]}], cache_duration_secs=STATIC_INFO_CACHE_TIMEOUT) result = json.loads(result) return result['Reservations'][0]['Instances'][0]
def get_instance_groups(cluster_id, role=None): emr_client = connect_emr(role=role) result = run_func(emr_client.list_instance_groups, ClusterId=cluster_id, cache_duration_secs=QUERY_CACHE_TIMEOUT) result = json.loads(result) result_map = {} for group in result['InstanceGroups']: group_type = group['InstanceGroupType'] if group_type not in result_map: result_map[group_type] = [] group['id'] = group['Id'] group['type'] = group_type result_map[group_type].append(group) return result_map