Microsoft Azure Image Builder Client Library for Python

1.4.0 · active · verified Thu Apr 09

This is the Microsoft Azure Image Builder Client Library for Python. It provides the necessary tools to interact with the Azure VM Image Builder service to define, build, and distribute custom virtual machine images. The current version is 1.4.0, and it follows the Azure SDK release cadence, with frequent updates for features and bug fixes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and create an `ImageBuilderClient`. It then shows how to list virtual machine image templates within a specified resource group. Ensure `AZURE_SUBSCRIPTION_ID`, `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, and `AZURE_CLIENT_SECRET` environment variables are set for successful authentication.

import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.imagebuilder import ImageBuilderClient

# Set environment variables for authentication and subscription
# AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
# AZURE_SUBSCRIPTION_ID

subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "YOUR_SUBSCRIPTION_ID")
resource_group_name = "myResourceGroup"

# Authenticate and create client
try:
    credential = DefaultAzureCredential()
    client = ImageBuilderClient(credential=credential, subscription_id=subscription_id)
    print(f"ImageBuilderClient created for subscription: {subscription_id}")

    # Example: List all image templates in a resource group
    print(f"\nListing image templates in resource group '{resource_group_name}':")
    templates = client.virtual_machine_image_templates.list_by_resource_group(resource_group_name=resource_group_name)
    for template in templates:
        print(f"  - {template.name} ({template.id})")

except Exception as e:
    print(f"An error occurred: {e}")
    print("Please ensure environment variables (AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET, AZURE_SUBSCRIPTION_ID) are set correctly and the resource group exists.")

view raw JSON →