Azure Hybrid Compute Management Client Library
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
-
ModuleNotFoundError: No module named 'azure.profiles' OR ModuleNotFoundError: No module named 'azure.common.credentials'
cause Attempting to import old, deprecated authentication modules (e.g., `azure.common.credentials` or `azure.profiles`) which are no longer part of the Azure SDK structure.fixUpdate your imports to use `azure-identity` for authentication, for example: `from azure.identity import DefaultAzureCredential`. -
azure.core.exceptions.HttpResponseError: (AuthorizationFailed) The client '...' with object id '...' does not have authorization to perform action 'Microsoft.HybridCompute/machines/read' over scope '/subscriptions/...' or the scope is invalid.
cause The authenticated identity (user, service principal, or managed identity) lacks the necessary Azure RBAC permissions to perform the requested operation on the specified scope.fixAssign the appropriate RBAC role (e.g., 'Azure Connected Machine Reader' or a custom role with required permissions) to the identity used for authentication on the subscription, resource group, or specific resource scope. -
AttributeError: 'HybridComputeManagementClient' object has no attribute 'agent_version_operations'
cause Attempting to access an operation group (e.g., `agent_version_operations`, `license_profiles_operations`) that was removed in version 9.0.0.fixReview the official documentation for version 9.0.0 to identify the correct way to perform the desired operation, as these specific operation groups are no longer available directly.
Warnings
- breaking The credential system has been completely revamped in versions 7.0.0b1 and later. Old authentication classes like `azure.common.credentials` or `msrestazure.azure_active_directory` are no longer supported. The `credentials` parameter for client constructors has been renamed to `credential`.
- breaking Long-running operations (LROs) that previously returned `msrest.polling.LROPoller` now return `azure.core.polling.LROPoller` and are prefixed with `begin_` (e.g., `create_or_update` becomes `begin_create_or_update`). The `CloudError` exception has been removed, replaced by `azure.core.exceptions.HttpResponseError`.
- breaking Version 9.0.0 removed the `AgentVersionOperations`, `HybridIdentityMetadataOperations`, `LicenseProfilesOperations`, and `LicensesOperations` operation groups. If your code uses these, it will break.
- gotcha Support for Python 2.7 has officially ended on January 1, 2022. This library, like all new Azure SDK for Python packages, requires Python 3.8 or later.
- gotcha Some users have reported discrepancies where certain Hybrid Compute API operations documented in the REST API were initially missing or delayed in the Python SDK. While efforts are made to keep SDKs up-to-date, occasional gaps or delays in API parity can occur.
Install
-
pip install azure-mgmt-hybridcompute azure-identity
Imports
- HybridComputeManagementClient
from azure.mgmt.hybridcompute import HybridComputeManagementClient
- DefaultAzureCredential
from azure.common.credentials import ServicePrincipalCredentials
from azure.identity import DefaultAzureCredential
Quickstart
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).")