CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/pypi-azure-mgmt-datamigration

Microsoft Azure Data Migration Client Library for Python providing comprehensive database migration management capabilities

Overview
Eval results
Files

files.mddocs/

File Management

Project file upload, management, and access for migration artifacts like scripts, configurations, and backup files. This capability enables storing and retrieving files associated with migration projects.

Capabilities

File Lifecycle Management

Create, update, delete, and retrieve project files with comprehensive metadata and access control.

def create_or_update(
    group_name: str,
    service_name: str,
    project_name: str,
    file_name: str,
    parameters: ProjectFile,
    **kwargs
) -> ProjectFile:
    """
    Create or update a project file.
    
    Parameters:
    - group_name: Name of the resource group
    - service_name: Name of the Data Migration Service
    - project_name: Name of the project
    - file_name: Name of the file
    - parameters: File configuration parameters
    
    Returns:
    ProjectFile instance details
    """

def get(
    group_name: str,
    service_name: str,
    project_name: str,
    file_name: str,
    **kwargs
) -> ProjectFile:
    """
    Get details of a project file.
    
    Parameters:
    - group_name: Name of the resource group
    - service_name: Name of the Data Migration Service
    - project_name: Name of the project
    - file_name: Name of the file
    
    Returns:
    ProjectFile instance details
    """

def delete(
    group_name: str,
    service_name: str,
    project_name: str,
    file_name: str,
    **kwargs
) -> None:
    """
    Delete a project file.
    
    Parameters:
    - group_name: Name of the resource group
    - service_name: Name of the Data Migration Service
    - project_name: Name of the project
    - file_name: Name of the file
    """

def update(
    group_name: str,
    service_name: str,
    project_name: str,
    file_name: str,
    parameters: ProjectFile,
    **kwargs
) -> ProjectFile:
    """
    Update an existing project file.
    
    Parameters:
    - group_name: Name of the resource group
    - service_name: Name of the Data Migration Service
    - project_name: Name of the project
    - file_name: Name of the file
    - parameters: Updated file parameters
    
    Returns:
    Updated file details
    """

File Access Operations

Read file content and manage file access permissions for project files.

def read(
    group_name: str,
    service_name: str,
    project_name: str,
    file_name: str,
    **kwargs
) -> FileStorageInfo:
    """
    Get file content for reading.
    
    Parameters:
    - group_name: Name of the resource group
    - service_name: Name of the Data Migration Service
    - project_name: Name of the project
    - file_name: Name of the file
    
    Returns:
    File storage information with read URI
    """

def read_write(
    group_name: str,
    service_name: str,
    project_name: str,
    file_name: str,
    **kwargs
) -> FileStorageInfo:
    """
    Get file access for reading and writing.
    
    Parameters:
    - group_name: Name of the resource group
    - service_name: Name of the Data Migration Service
    - project_name: Name of the project
    - file_name: Name of the file
    
    Returns:
    File storage information with read/write URI
    """

File Discovery

List project files for inventory and management purposes.

def list(
    group_name: str,
    service_name: str,
    project_name: str,
    **kwargs
) -> ItemPaged[ProjectFile]:
    """
    List files in a migration project.
    
    Parameters:
    - group_name: Name of the resource group
    - service_name: Name of the Data Migration Service
    - project_name: Name of the project
    
    Returns:
    Paginated list of project files
    """

Usage Examples

Uploading a Migration Script

from azure.mgmt.datamigration import DataMigrationManagementClient
from azure.mgmt.datamigration.models import ProjectFile, ProjectFileProperties
from azure.identity import DefaultAzureCredential
import requests

credential = DefaultAzureCredential()
client = DataMigrationManagementClient(credential, "subscription-id")

# Create file metadata
file_properties = ProjectFileProperties(
    file_type="Script",
    media_type="application/sql"
)

project_file = ProjectFile(
    properties=file_properties
)

# Create the file entry
created_file = client.files.create_or_update(
    group_name="my-rg",
    service_name="my-migration-service",
    project_name="my-project",
    file_name="migration-script.sql",
    parameters=project_file
)

print(f"File created: {created_file.name}")

# Get write access to upload content
write_access = client.files.read_write(
    group_name="my-rg", 
    service_name="my-migration-service",
    project_name="my-project",
    file_name="migration-script.sql"
)

# Upload file content using the provided URI
script_content = """
-- Migration script
USE TargetDB;
CREATE TABLE IF NOT EXISTS MigrationLog (
    Id INT PRIMARY KEY,
    Timestamp DATETIME,
    Message NVARCHAR(500)
);
"""

if write_access.uri:
    # Upload the content (example using requests)
    response = requests.put(
        write_access.uri,
        data=script_content.encode('utf-8'),
        headers={'Content-Type': 'application/sql'}
    )
    
    if response.status_code == 200:
        print("File content uploaded successfully")
    else:
        print(f"Upload failed: {response.status_code}")

Managing Project Files

# List all files in a project
files = client.files.list(
    group_name="my-rg",
    service_name="my-migration-service", 
    project_name="my-project"
)

print("Project files:")
for file in files:
    print(f"  {file.name}")
    if file.properties:
        print(f"    Type: {file.properties.file_type}")
        print(f"    Media Type: {file.properties.media_type}")
        print(f"    Size: {file.properties.size} bytes")
        print(f"    Last Modified: {file.properties.last_modified}")

# Get specific file details
file_details = client.files.get(
    group_name="my-rg",
    service_name="my-migration-service",
    project_name="my-project", 
    file_name="migration-script.sql"
)

print(f"\nFile details for {file_details.name}:")
print(f"  File Type: {file_details.properties.file_type}")
print(f"  Extension: {file_details.properties.extension}")
print(f"  Size: {file_details.properties.size} bytes")

Reading File Content

# Get read access to a file
read_access = client.files.read(
    group_name="my-rg",
    service_name="my-migration-service", 
    project_name="my-project",
    file_name="migration-script.sql"
)

# Download and read file content
if read_access.uri:
    response = requests.get(read_access.uri)
    
    if response.status_code == 200:
        file_content = response.text
        print("File content:")
        print(file_content)
    else:
        print(f"Failed to read file: {response.status_code}")

# File access has expiration
print(f"Read access expires: {read_access.access_end_time}")

Working with Different File Types

from azure.mgmt.datamigration.models import ProjectFileProperties

# Upload a configuration file
config_properties = ProjectFileProperties(
    file_type="Configuration",
    media_type="application/json"
)

config_file = ProjectFile(properties=config_properties)

config_created = client.files.create_or_update(
    group_name="my-rg",
    service_name="my-migration-service",
    project_name="my-project", 
    file_name="migration-config.json",
    parameters=config_file
)

# Upload a backup file reference
backup_properties = ProjectFileProperties(
    file_type="Backup",
    media_type="application/octet-stream"
)

backup_file = ProjectFile(properties=backup_properties)

backup_created = client.files.create_or_update(
    group_name="my-rg", 
    service_name="my-migration-service",
    project_name="my-project",
    file_name="database-backup.bak",
    parameters=backup_file
)

# Clean up files when no longer needed
client.files.delete(
    group_name="my-rg",
    service_name="my-migration-service", 
    project_name="my-project",
    file_name="old-script.sql"
)

print("File cleanup completed")

Types

class ProjectFile:
    """Project file configuration and metadata."""
    name: str
    type: str
    etag: str
    properties: ProjectFileProperties

class ProjectFileProperties:
    """Project file properties."""
    file_type: str  # File type classification
    media_type: str  # MIME type of the file
    size: int  # File size in bytes
    extension: str  # File extension
    last_modified: datetime  # Last modification timestamp

class FileStorageInfo:
    """File storage access information."""
    uri: str  # Access URI for the file
    access_end_time: datetime  # When access expires

class FileList:
    """List of project files."""
    value: list[ProjectFile]
    next_link: str

class FileShare:
    """File share configuration."""
    path: str  # File share path
    user_name: str  # Username for access
    password: str  # Password for access

class BlobShare:
    """Blob storage share configuration."""
    sas_uri: str  # SAS URI for blob access
tessl i tessl/pypi-azure-mgmt-datamigration@9.0.0

docs

connection-validation.md

files.md

index.md

operations.md

projects.md

resources.md

service-tasks.md

services.md

tasks.md

tile.json