Azure HDInsight Management Client Library

9.0.0 · active · verified Thu Apr 09

The Microsoft Azure HDInsight Management Client Library for Python provides tools to manage Azure HDInsight clusters, including creation, deletion, scaling, and configuration. It is part of the Azure SDK for Python, currently at version 9.0.0, and typically receives updates aligning with Azure REST API changes and general SDK improvements.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with Azure, initialize the `HDInsightManagementClient`, and then list all HDInsight clusters within your subscription, as well as fetch capabilities for a specific location. It uses `DefaultAzureCredential` for flexible authentication.

import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.hdinsight import HDInsightManagementClient

# Set your Azure Subscription ID as an environment variable
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "<your-subscription-id>")
if subscription_id == "<your-subscription-id>":
    print("Please set the AZURE_SUBSCRIPTION_ID environment variable or replace the placeholder.")
    exit(1)

# Authenticate using DefaultAzureCredential, which tries multiple credential types
# (environment variables, managed identity, VS Code, Azure CLI, etc.)
credential = DefaultAzureCredential()

# Create the HDInsight Management Client
client = HDInsightManagementClient(credential, subscription_id)

print(f"Listing all HDInsight clusters in subscription: {subscription_id}")

try:
    # List all clusters in the subscription
    clusters = client.clusters.list()
    found_clusters = False
    for cluster in clusters:
        found_clusters = True
        print(f"- Cluster Name: {cluster.name}, Location: {cluster.location}, State: {cluster.properties.cluster_state}")
    if not found_clusters:
        print("No HDInsight clusters found in this subscription.")

except Exception as e:
    print(f"An error occurred: {e}")
    print("Make sure your AZURE_SUBSCRIPTION_ID is correct and you have appropriate permissions.")

print("\nListing available locations (capabilities) for HDInsight:")
# Note: list_capabilities often requires a specific location as input for context
# We'll use 'eastus' as an example.
# This might list an empty set if the subscription has no capabilities in 'eastus' or permission issues.
locations = client.locations.list_capabilities("eastus")
found_locations = False
for location in locations:
    found_locations = True
    print(f"- Location: {location.location}, VM Families: {len(location.regions_with_ FVM_families)}, Max Clusters: {location.max_cluster_count}")
    if found_locations: # Print only the first one for brevity
        break
if not found_locations:
    print("No capabilities listed for 'eastus' or an error occurred.")

view raw JSON →