Azure Management Private DNS Client Library
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
- breaking The credential system was completely revamped. Old `azure.common.credentials` or `msrestazure.azure_active_directory` instances are no longer supported.
- breaking Long-Running Operations (LRO) pollers and exception handling changed. Operations returning `msrest.polling.LROPoller` now return `azure.core.polling.LROPoller` and are prefixed with `begin_`. Most exceptions are now `azure.core.exceptions.HttpResponseError` instead of `CloudError`.
- gotcha Deleting a Private DNS zone also deletes all DNS records within it, and this operation cannot be undone. Furthermore, a Private DNS zone cannot be deleted unless all virtual network links to it are first removed.
- gotcha The `PrivateDnsManagementClient` constructor accepts an `api_version` parameter. While it has a default, explicitly overriding it with an unsupported or outdated value can lead to unexpected API behavior or errors.
Install
-
pip install azure-mgmt-privatedns azure-identity
Imports
- PrivateDnsManagementClient
from azure.mgmt.privatedns import PrivateDnsManagementClient
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
Quickstart
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.