Azure Hybrid Compute Management Client Library

9.0.0 · active · verified Thu Apr 16

The `azure-mgmt-hybridcompute` library is the Microsoft Azure Hybrid Compute Management Client Library for Python. It provides classes and methods to programmatically manage Azure Arc-enabled servers and related resources. The current stable version is 9.0.0, and like other Azure SDKs, it follows an active release cadence with regular updates for new features and bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and then list all Azure Arc-enabled machines within a specified subscription. Ensure `AZURE_SUBSCRIPTION_ID` and other necessary Azure authentication environment variables (like `AZURE_CLIENT_ID`, `AZURE_CLIENT_SECRET`, `AZURE_TENANT_ID` if using a service principal) are set, or that you are logged in via `az login`.

import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.hybridcompute import HybridComputeManagementClient

# Set environment variables for authentication and subscription
# AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_TENANT_ID for service principal or Azure CLI login
# AZURE_SUBSCRIPTION_ID for your Azure subscription

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.")
    exit(1)

try:
    # Acquire a credential object using DefaultAzureCredential
    # This credential will attempt to authenticate via multiple mechanisms:
    # Environment variables, Managed Identity, Azure CLI, Visual Studio Code, etc.
    credential = DefaultAzureCredential()

    # Create a Hybrid Compute Management client
    client = HybridComputeManagementClient(credential=credential, subscription_id=subscription_id)

    print(f"Listing all machines in subscription {subscription_id}:")
    # Iterate over machines in the subscription
    for machine in client.machines.list_by_subscription():
        print(f"  - Machine Name: {machine.name}, Location: {machine.location}, Status: {machine.status}")

except Exception as e:
    print(f"An error occurred: {e}")
    print("Ensure you are authenticated to Azure (e.g., via `az login` or environment variables).")

view raw JSON →