Azure Extended Location Management

2.0.0 · active · verified Thu Apr 09

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

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate the `ExtendedLocationMgmtClient` using `DefaultAzureCredential` and list custom locations within your Azure subscription. Ensure `AZURE_SUBSCRIPTION_ID` is set as an environment variable and you have appropriate permissions.

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.")

view raw JSON →