Microsoft Azure Container Registry Client Library for managing container registries, replications, webhooks, and access control through Azure Resource Manager APIs.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Geographic replication management for Premium registries, enabling registry content distribution across multiple Azure regions for performance optimization, disaster recovery, and global content delivery. Replications synchronize registry content automatically and provide regional endpoints for faster access.
Create, update, and delete replications to distribute registry content across Azure regions with configurable settings for zone redundancy and regional optimization.
def begin_create(resource_group_name: str, registry_name: str, replication_name: str, replication: Replication, **kwargs) -> LROPoller[Replication]:
"""
Create a replication for a container registry.
Parameters:
- resource_group_name: str - Name of the resource group
- registry_name: str - Name of the registry
- replication_name: str - Name of the replication (typically the region name)
- replication: Replication - Replication configuration parameters
Returns:
LROPoller[Replication] - Long-running operation poller for the replication
"""
def begin_delete(resource_group_name: str, registry_name: str, replication_name: str, **kwargs) -> LROPoller[None]:
"""
Delete a replication from a container registry.
Parameters:
- resource_group_name: str - Name of the resource group
- registry_name: str - Name of the registry
- replication_name: str - Name of the replication to delete
Returns:
LROPoller[None] - Long-running operation poller
"""
def begin_update(resource_group_name: str, registry_name: str, replication_name: str, replication_update_parameters: ReplicationUpdateParameters, **kwargs) -> LROPoller[Replication]:
"""
Update a replication for a container registry.
Parameters:
- resource_group_name: str - Name of the resource group
- registry_name: str - Name of the registry
- replication_name: str - Name of the replication to update
- replication_update_parameters: ReplicationUpdateParameters - Update parameters
Returns:
LROPoller[Replication] - Long-running operation poller for the updated replication
"""Retrieve replication details, list all replications for a registry, and monitor replication status and synchronization state.
def get(resource_group_name: str, registry_name: str, replication_name: str, **kwargs) -> Replication:
"""
Get properties of a replication.
Parameters:
- resource_group_name: str - Name of the resource group
- registry_name: str - Name of the registry
- replication_name: str - Name of the replication
Returns:
Replication - Replication resource with complete configuration and status
"""
def list(resource_group_name: str, registry_name: str, **kwargs) -> ItemPaged[Replication]:
"""
List all replications for a container registry.
Parameters:
- resource_group_name: str - Name of the resource group
- registry_name: str - Name of the registry
Returns:
ItemPaged[Replication] - Paginated list of all replications for the registry
"""class Replication:
"""
An object that represents a replication for a container registry.
Attributes:
- id: str - Resource ID
- name: str - Resource name (typically region name)
- type: str - Resource type
- location: str - Azure region location for the replication
- tags: Dict[str, str] - Resource tags
- provisioning_state: ProvisioningState - Current provisioning state
- status: Status - Replication status information
- region_endpoint_enabled: bool - Enable regional endpoint
- zone_redundancy: ZoneRedundancy - Zone redundancy setting for the replication
"""class ReplicationUpdateParameters:
"""
Parameters for updating a replication.
Attributes:
- tags: Dict[str, str] - Resource tags to update
- region_endpoint_enabled: bool - Enable or disable regional endpoint
- zone_redundancy: ZoneRedundancy - Zone redundancy setting
"""class Status:
"""
Current status of a resource.
Attributes:
- display_status: str - Display status description
- message: str - Status message with additional details
- timestamp: datetime - Status timestamp
"""class ZoneRedundancy(str, Enum):
"""Zone redundancy setting for replications."""
ENABLED = "Enabled"
DISABLED = "Disabled"class ProvisioningState(str, Enum):
"""Provisioning state of a resource."""
CREATING = "Creating"
UPDATING = "Updating"
DELETING = "Deleting"
SUCCEEDED = "Succeeded"
FAILED = "Failed"
CANCELED = "Canceled"from azure.mgmt.containerregistry import ContainerRegistryManagementClient
from azure.mgmt.containerregistry.models import Replication, ZoneRedundancy
from azure.identity import DefaultAzureCredential
client = ContainerRegistryManagementClient(
DefaultAzureCredential(),
"subscription-id"
)
# Create replications in multiple regions for global distribution
regions = [
{"name": "westus2", "location": "West US 2", "zone_redundancy": ZoneRedundancy.ENABLED},
{"name": "eastus", "location": "East US", "zone_redundancy": ZoneRedundancy.ENABLED},
{"name": "westeurope", "location": "West Europe", "zone_redundancy": ZoneRedundancy.DISABLED},
{"name": "southeastasia", "location": "Southeast Asia", "zone_redundancy": ZoneRedundancy.DISABLED}
]
for region in regions:
replication_params = Replication(
location=region["location"],
zone_redundancy=region["zone_redundancy"],
region_endpoint_enabled=True,
tags={
"purpose": "global-distribution",
"region-tier": "primary" if region["zone_redundancy"] == ZoneRedundancy.ENABLED else "secondary"
}
)
print(f"Creating replication in {region['location']}...")
creation_poller = client.replications.begin_create(
"my-resource-group",
"my-premium-registry",
region["name"],
replication_params
)
# Wait for completion
replication = creation_poller.result()
print(f"Replication created in {replication.location} with status: {replication.provisioning_state}")# List all replications and check their status
replications = client.replications.list("my-resource-group", "my-premium-registry")
print("Registry Replications Status:")
print("-" * 50)
for replication in replications:
print(f"Region: {replication.location}")
print(f" Status: {replication.provisioning_state}")
print(f" Zone Redundancy: {replication.zone_redundancy}")
print(f" Regional Endpoint: {replication.region_endpoint_enabled}")
if replication.status:
print(f" Display Status: {replication.status.display_status}")
print(f" Message: {replication.status.message}")
print()from azure.mgmt.containerregistry.models import ReplicationUpdateParameters
# Enable zone redundancy for an existing replication
update_params = ReplicationUpdateParameters(
zone_redundancy=ZoneRedundancy.ENABLED,
region_endpoint_enabled=True,
tags={
"updated": "2024-01-15",
"zone-redundancy": "enabled"
}
)
update_poller = client.replications.begin_update(
"my-resource-group",
"my-premium-registry",
"westeurope",
update_params
)
updated_replication = update_poller.result()
print(f"Updated replication zone redundancy: {updated_replication.zone_redundancy}")# Create a disaster recovery replication setup
primary_regions = ["eastus", "westus2"] # Primary regions with zone redundancy
dr_regions = ["southcentralus", "northcentralus"] # DR regions
# Create primary replications with zone redundancy
for region in primary_regions:
replication_params = Replication(
location=region.replace("us", " US").replace("west", "West ").replace("east", "East ").title(),
zone_redundancy=ZoneRedundancy.ENABLED,
region_endpoint_enabled=True,
tags={
"tier": "primary",
"disaster-recovery": "true"
}
)
client.replications.begin_create(
"my-resource-group",
"my-registry",
region,
replication_params
).result()
# Create DR replications without zone redundancy for cost optimization
for region in dr_regions:
replication_params = Replication(
location=region.replace("us", " US").replace("central", " Central").replace("north", "North").replace("south", "South").title(),
zone_redundancy=ZoneRedundancy.DISABLED,
region_endpoint_enabled=False, # Disable for cost savings
tags={
"tier": "disaster-recovery",
"primary-backup": "true"
}
)
client.replications.begin_create(
"my-resource-group",
"my-registry",
region,
replication_params
).result()
print("Disaster recovery replication setup completed")# Remove replications that are no longer needed
replications_to_remove = ["southeastasia", "japaneast"]
for replication_name in replications_to_remove:
try:
print(f"Removing replication: {replication_name}")
deletion_poller = client.replications.begin_delete(
"my-resource-group",
"my-registry",
replication_name
)
deletion_poller.result()
print(f"Successfully removed replication: {replication_name}")
except Exception as e:
print(f"Failed to remove replication {replication_name}: {e}")Install with Tessl CLI
npx tessl i tessl/pypi-azure-mgmt-containerregistry