Azure Extended Location Management
The Microsoft Azure Extended Location Management Client Library for Python provides functionality to manage Custom Locations and Resource Sync Rules within Azure. These extended locations allow Azure services to run in environments outside of Azure datacenters. The current version is 2.0.0, and new versions are released regularly to keep pace with Azure service updates.
Warnings
- breaking Major breaking changes occurred in Azure SDK for Python Track 2 (version 2.x) compared to older Track 1 versions (0.x or 1.x). Client instantiation, authentication (now using `azure.identity`), and object models have been completely revised.
- gotcha Authentication with `DefaultAzureCredential` relies on specific environment variables (e.g., `AZURE_CLIENT_ID`, `AZURE_CLIENT_SECRET`, `AZURE_TENANT_ID` for service principals, or `AZURE_SUBSCRIPTION_ID` for the management client) or other configured authentication mechanisms (Azure CLI, VS Code, etc.). Misconfiguration will lead to `CredentialUnavailableError`.
- gotcha Many resource creation or update operations in Azure management libraries are Long Running Operations (LROs). These methods return a poller object (e.g., `LROPoller`) immediately. You must call `.result()` on the poller to wait for the operation to complete and retrieve the final resource object.
Install
-
pip install azure-mgmt-extendedlocation
Imports
- ExtendedLocationMgmtClient
from azure.mgmt.extendedlocation import ExtendedLocationMgmtClient
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
Quickstart
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.extendedlocation import ExtendedLocationMgmtClient
# Set your Azure Subscription ID as an environment variable (e.g., AZURE_SUBSCRIPTION_ID)
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "")
if not subscription_id:
raise ValueError("AZURE_SUBSCRIPTION_ID environment variable must be set.")
# Authenticate using DefaultAzureCredential
# This will attempt to authenticate via environment variables, managed identity,
# Azure CLI, Azure Developer CLI, Visual Studio Code, etc.
credential = DefaultAzureCredential()
# Create the ExtendedLocation Management client
client = ExtendedLocationMgmtClient(credential, subscription_id)
print(f"Listing custom locations for subscription: {subscription_id}")
# Iterate through custom locations in the subscription
try:
custom_locations = client.custom_locations.list_by_subscription()
for cl in custom_locations:
print(f" - Custom Location Name: {cl.name}, Location: {cl.location}, ID: {cl.id}")
except Exception as e:
print(f"An error occurred: {e}")
print("Make sure your account has permissions and AZURE_SUBSCRIPTION_ID is correct.")