Microsoft Azure Data Migration Client Library for Python
The `azure-mgmt-datamigration` library provides client-side functionality for interacting with the Azure Data Migration Service, allowing programmatic management of data migration tasks to Azure data platforms. It is part of the Azure SDK for Python, currently at version 10.1.0, and follows the modern Azure SDK guidelines, with regular updates and releases.
Warnings
- breaking Version 9.0.0b1 introduced significant breaking changes, revamping the authentication system. Old `azure.common.credentials` or `msrestazure.azure_active_directory` are no longer supported; use `azure-identity` classes instead. The `credentials` parameter was also renamed to `credential`.
- breaking Older versions (e.g., 3.0.0) introduced breaking changes related to module visibility and renaming. Direct imports from sub-modules like `data_migration_service_client` for `DataMigrationServiceManagementClient`, or `models.my_class`, `operations.my_class_operations` are no longer supported. Operation methods returning `msrest.polling.LROPoller` were changed to `azure.core.polling.LROPoller` and prefixed with `begin_`.
- gotcha `DefaultAzureCredential` relies on specific environment variables (e.g., `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`, `AZURE_SUBSCRIPTION_ID`) or other configured authentication methods (Azure CLI, Managed Identity). Misconfiguration is a common source of `ClientAuthenticationError`.
- gotcha The Azure Database Migration Service has operational limits, such as a maximum of four databases per migration activity. Attempting to migrate more than this limit in a single activity will result in a validation error.
- gotcha Network and DNS misconfigurations, including dynamic ports for SQL Server instances, incorrect ExpressRoute setup, or firewall rules, are frequent causes of connection failures during migration setup within the Data Migration Service.
Install
-
pip install azure-mgmt-datamigration azure-identity
Imports
- DataMigrationManagementClient
from azure.mgmt.datamigration import DataMigrationManagementClient
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
Quickstart
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.datamigration import DataMigrationManagementClient
# Set your Azure Subscription ID as an environment variable or replace directly
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "<your-subscription-id>")
# Acquire a credential using DefaultAzureCredential. This will try various methods
# like environment variables (AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET),
# Azure CLI, Managed Identity, etc.
credential = DefaultAzureCredential()
# Create a DataMigrationManagementClient
client = DataMigrationManagementClient(credential, subscription_id)
# Example: List all Data Migration Services in a resource group
resource_group_name = os.environ.get("AZURE_RESOURCE_GROUP", "<your-resource-group>")
print(f"Listing Data Migration Services in resource group: {resource_group_name}")
try:
for service in client.services.list_by_resource_group(resource_group_name):
print(f" Service Name: {service.name}, Location: {service.location}")
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure AZURE_SUBSCRIPTION_ID and AZURE_RESOURCE_GROUP are set,")
print("and that your principal has 'Reader' permissions on the resource group.")