Azure DevTest Labs Management
Microsoft Azure DevTestLabs Management Client Library for Python, currently at version 9.0.0. This library provides programmatic access to manage Azure DevTest Labs resources, including labs, virtual machines, custom images, and schedules. Azure SDK libraries typically follow a regular release schedule, with updates for new features and bug fixes.
Warnings
- breaking The primary client class name changed from `DevTestLabsManagementClient` to `DevTestLabsClient` in the V2 SDK. Code written for older versions will need to update the import and instantiation.
- breaking Resource models and API methods may have changed significantly between major versions (e.g., V1 to V2 SDK). Property names, argument order, and response structures might differ, leading to `AttributeError` or `TypeError`.
- gotcha The library provides both synchronous (`DevTestLabsClient`) and asynchronous (`DevTestLabsClientAsync`) clients. Ensure you are using the correct client type for your application's concurrency model (e.g., `async/await` for asynchronous operations).
- gotcha Many list operations (e.g., `client.labs.list_by_subscription()`) return an iterable object that performs pagination under the hood. Not all items might be immediately available, and the iterator must be fully consumed to retrieve all results.
Install
-
pip install azure-mgmt-devtestlabs
Imports
- DevTestLabsClient
from azure.mgmt.devtestlabs import DevTestLabsClient
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
Quickstart
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.devtestlabs import DevTestLabsClient
# Set your Azure Subscription ID as an environment variable
# E.g., export AZURE_SUBSCRIPTION_ID="<your-subscription-id>"
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "")
if not subscription_id:
raise ValueError("AZURE_SUBSCRIPTION_ID environment variable not set.")
# Authenticate using DefaultAzureCredential
# This will try various authentication methods, like environment variables,
# managed identity, Azure CLI, VS Code, etc.
credential = DefaultAzureCredential()
# Create a DevTestLabsClient
client = DevTestLabsClient(credential, subscription_id)
# Example: List all DevTest Labs in the subscription
print("Listing DevTest Labs:")
for lab in client.labs.list_by_subscription():
print(f" Lab Name: {lab.name}, Location: {lab.location}")