Azure Management Private DNS Client Library

1.2.0 · active · verified Thu Apr 09

The Microsoft Azure DNS Private Zones Client Library for Python allows you to create, configure, and manage private DNS zones within your Azure virtual networks. It provides programmatic access to manage private DNS zones, virtual network links, and DNS record sets. The current version is 1.2.0, released on September 23, 2024, and it is part of the Azure SDK for Python, which follows a regular release cadence with frequent updates across its libraries.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and then list all Private DNS zones available in your subscription using `PrivateDnsManagementClient`. Ensure your `AZURE_SUBSCRIPTION_ID` environment variable is set for this example to run correctly, along with other necessary Azure Identity environment variables for authentication.

import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.privatedns import PrivateDnsManagementClient

# Set your Azure Subscription ID as an environment variable or replace with your ID
# os.environ["AZURE_SUBSCRIPTION_ID"] = "<your-subscription-id>"

# Authenticate using DefaultAzureCredential. It will try various methods like environment variables,
# managed identity, Azure CLI, etc. For development, ensure AZURE_CLIENT_ID, AZURE_TENANT_ID,
# and AZURE_CLIENT_SECRET (or AZURE_CLI_AUTH_TOKEN for CLI login) are set.
credential = DefaultAzureCredential()
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "")

if not subscription_id:
    raise ValueError("AZURE_SUBSCRIPTION_ID environment variable not set.")

client = PrivateDnsManagementClient(credential=credential, subscription_id=subscription_id)

# Example: List all private DNS zones in the subscription
print("Listing Private DNS Zones:")
for zone in client.private_zones.list():
    print(f"  - Zone Name: {zone.name}, Resource Group: {zone.id.split('/')[4]}")

# In a real application, ensure proper error handling and resource management (e.g., closing the client if needed).
# client.close() # if using an older client or specific scenarios, typically not needed for management clients.

view raw JSON →