CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-azure-mgmt-dns

Microsoft Azure DNS Management Client Library for Python

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

dns-zones.mddocs/

DNS Zone Management

Comprehensive management of Azure DNS zones including creation, deletion, updating, and listing operations. Supports both public and private zones with virtual network associations for Azure-internal name resolution.

Zone Operations

Create or Update Zone

Creates a new DNS zone or updates an existing one with the specified configuration.

def create_or_update(
    self,
    resource_group_name: str,
    zone_name: str,
    parameters: Union[Zone, IO[bytes]],
    if_match: Optional[str] = None,
    if_none_match: Optional[str] = None,
    **kwargs: Any
) -> Zone:
    """
    Create or update a DNS zone.
    
    Args:
        resource_group_name: Name of the resource group containing the zone
        zone_name: Name of the DNS zone (e.g., "example.com")
        parameters: Zone configuration parameters
        if_match: ETag value for conditional updates (optimistic concurrency)
        if_none_match: Set to "*" to prevent overwriting existing zones
        
    Returns:
        Zone: The created or updated DNS zone
        
    Raises:
        HttpResponseError: If the operation fails
    """

Usage Example:

from azure.mgmt.dns.models import Zone

# Create a public DNS zone
zone_params = Zone(
    location="global",  # DNS zones are always global
    zone_type="Public",
    tags={"environment": "production", "team": "networking"}
)

zone = dns_client.zones.create_or_update(
    resource_group_name="my-resource-group",
    zone_name="example.com",
    parameters=zone_params
)

print(f"Created zone: {zone.name}")
print(f"Name servers: {zone.name_servers}")

Delete Zone

Permanently deletes a DNS zone and all its record sets. This is a long-running operation.

def begin_delete(
    self,
    resource_group_name: str,
    zone_name: str,
    if_match: Optional[str] = None,
    **kwargs: Any
) -> LROPoller[None]:
    """
    Delete a DNS zone and all its record sets.
    
    Args:
        resource_group_name: Name of the resource group containing the zone
        zone_name: Name of the DNS zone to delete
        if_match: ETag value for conditional deletion
        
    Returns:
        LROPoller[None]: Long-running operation poller
        
    Raises:
        HttpResponseError: If the operation fails
    """

Usage Example:

# Delete a DNS zone (this will also delete all record sets)
delete_operation = dns_client.zones.begin_delete(
    resource_group_name="my-resource-group",
    zone_name="example.com"
)

# Wait for deletion to complete
delete_operation.wait()
print("Zone deleted successfully")

Get Zone

Retrieves the properties of a specific DNS zone.

def get(
    self,
    resource_group_name: str,
    zone_name: str,
    **kwargs: Any
) -> Zone:
    """
    Get properties of a DNS zone.
    
    Args:
        resource_group_name: Name of the resource group containing the zone
        zone_name: Name of the DNS zone
        
    Returns:
        Zone: The DNS zone properties
        
    Raises:
        HttpResponseError: If the zone is not found
    """

Usage Example:

zone = dns_client.zones.get(
    resource_group_name="my-resource-group",
    zone_name="example.com"
)

print(f"Zone: {zone.name}")
print(f"Record sets: {zone.number_of_record_sets}/{zone.max_number_of_record_sets}")
print(f"Name servers: {zone.name_servers}")

Update Zone

Updates mutable properties of an existing DNS zone.

def update(
    self,
    resource_group_name: str,
    zone_name: str,
    parameters: Union[ZoneUpdate, IO[bytes]],
    if_match: Optional[str] = None,
    **kwargs: Any
) -> Zone:
    """
    Update properties of a DNS zone.
    
    Args:
        resource_group_name: Name of the resource group containing the zone
        zone_name: Name of the DNS zone
        parameters: Zone update parameters (typically just tags)
        if_match: ETag value for conditional updates
        
    Returns:
        Zone: The updated DNS zone
        
    Raises:
        HttpResponseError: If the operation fails
    """

Usage Example:

from azure.mgmt.dns.models import ZoneUpdate

# Update zone tags
zone_update = ZoneUpdate(
    tags={"environment": "staging", "team": "networking", "cost-center": "IT"}
)

updated_zone = dns_client.zones.update(
    resource_group_name="my-resource-group",
    zone_name="example.com",
    parameters=zone_update
)

print(f"Updated tags: {updated_zone.tags}")

List Zones

List DNS zones within a resource group or subscription.

def list_by_resource_group(
    self,
    resource_group_name: str,
    top: Optional[int] = None,
    **kwargs: Any
) -> ItemPaged[Zone]:
    """
    List DNS zones in a resource group.
    
    Args:
        resource_group_name: Name of the resource group
        top: Maximum number of zones to return
        
    Returns:
        ItemPaged[Zone]: Paginated list of DNS zones
    """

def list(
    self,
    top: Optional[int] = None,
    **kwargs: Any
) -> ItemPaged[Zone]:
    """
    List all DNS zones in the subscription.
    
    Args:
        top: Maximum number of zones to return
        
    Returns:
        ItemPaged[Zone]: Paginated list of DNS zones
    """

Usage Examples:

# List zones in a specific resource group
zones = dns_client.zones.list_by_resource_group("my-resource-group")
for zone in zones:
    print(f"Zone: {zone.name}, Records: {zone.number_of_record_sets}")

# List all zones in subscription
all_zones = dns_client.zones.list(top=50)  # Limit to first 50 zones
for zone in all_zones:
    print(f"Zone: {zone.name}, Resource Group: {zone.id.split('/')[4]}")

Zone Data Model

Zone Class

class Zone:
    """
    Represents a DNS zone resource in Azure.
    
    A DNS zone contains DNS records and provides name resolution for a domain.
    Zones can be public (internet-accessible) or private (Azure-internal only).
    """
    
    # Read-only properties
    id: str                                    # Azure resource ID
    name: str                                  # Zone name (e.g., "example.com")
    type: str                                  # Resource type ("Microsoft.Network/dnszones")
    etag: str                                  # ETag for concurrency control
    max_number_of_record_sets: int             # Maximum allowed record sets
    number_of_record_sets: int                 # Current number of record sets
    name_servers: List[str]                    # Authoritative name servers
    
    # Configurable properties
    location: str                              # Always "global" for DNS zones
    tags: Dict[str, str]                       # Resource tags for organization
    zone_type: ZoneType                        # Public or Private
    
    # Private zone properties (only for private zones)
    registration_virtual_networks: List[SubResource]  # VNets for auto-registration
    resolution_virtual_networks: List[SubResource]    # VNets for name resolution

Zone Types

class ZoneType(str, Enum):
    """DNS zone visibility and resolution scope."""
    PUBLIC = "Public"    # Internet-accessible zone
    PRIVATE = "Private"  # Azure-internal zone linked to VNets

Private DNS Zones

Private zones provide DNS resolution within Azure virtual networks without exposing records to the internet.

Usage Example:

from azure.mgmt.dns.models import Zone, ZoneType, SubResource

# Create a private DNS zone
private_zone = Zone(
    location="global",
    zone_type=ZoneType.PRIVATE,
    resolution_virtual_networks=[
        SubResource(id="/subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Network/virtualNetworks/vnet1"),
        SubResource(id="/subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Network/virtualNetworks/vnet2")
    ],
    tags={"purpose": "internal-services"}
)

zone = dns_client.zones.create_or_update(
    resource_group_name="my-resource-group",
    zone_name="internal.company.com",
    parameters=private_zone
)

print(f"Created private zone: {zone.name}")

Error Handling

DNS zone operations can fail for various reasons:

from azure.core.exceptions import HttpResponseError

try:
    zone = dns_client.zones.get("my-rg", "nonexistent.com")
except HttpResponseError as e:
    if e.status_code == 404:
        print("Zone not found")
    elif e.status_code == 403:
        print("Access denied - check permissions")
    else:
        print(f"Unexpected error: {e.status_code} - {e.message}")

Common error scenarios:

  • 404 Not Found: Zone doesn't exist
  • 403 Forbidden: Insufficient permissions
  • 409 Conflict: Zone name already exists (when using if_none_match)
  • 412 Precondition Failed: ETag mismatch (when using if_match)

Install with Tessl CLI

npx tessl i tessl/pypi-azure-mgmt-dns

docs

dns-record-sets.md

dns-resource-references.md

dns-zones.md

index.md

tile.json