Azure HDInsight Management Client Library
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
- breaking Major version releases (e.g., 9.0.0) typically introduce breaking changes in API models, client constructors, or method signatures. Always review the migration guide in the official Azure SDK documentation when upgrading between major versions.
- gotcha Many Azure management operations, such as creating or deleting clusters, are long-running operations (LROs). The SDK returns a poller object (e.g., `LROPoller`). You must call `.result()` on this poller to wait for the operation to complete and get its final outcome.
- deprecated Older authentication methods like directly using `ServicePrincipalCredentials` or `TokenCredentials` are being deprecated. The `azure-identity` library with `DefaultAzureCredential` is the recommended and most flexible approach for authentication across Azure SDKs.
- gotcha Azure HDInsight management operations are tied to a specific Azure subscription and often a resource group. Ensure you provide the correct `subscription_id` and `resource_group_name` to the client and methods, respectively. Incorrect context will lead to 'ResourceNotFound' or 'PermissionDenied' errors.
Install
-
pip install azure-mgmt-hdinsight azure-identity
Imports
- HDInsightManagementClient
from azure.mgmt.hdinsight import HDInsightManagementClient
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
- models
from azure.mgmt.hdinsight.models import Cluster
Quickstart
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.")