Microsoft Azure Compute Management Client Library for programmatic management of Azure compute resources including virtual machines, scale sets, disks, and related infrastructure.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Management of managed disks, snapshots, disk encryption, and disk access controls for persistent storage solutions. This includes operations for creating, configuring, and managing Azure managed disks, snapshots for backup and recovery, disk encryption sets for security, and disk access controls for private endpoints.
Core operations for managing Azure managed disks.
def begin_create_or_update(
resource_group_name: str,
disk_name: str,
disk: Disk
) -> LROPoller[Disk]:
"""
Create or update a managed disk.
Args:
resource_group_name: Name of the resource group
disk_name: Name of the disk
disk: Disk configuration parameters
Returns:
Long-running operation poller for Disk
"""
def begin_delete(resource_group_name: str, disk_name: str) -> LROPoller[None]:
"""
Delete a managed disk.
Args:
resource_group_name: Name of the resource group
disk_name: Name of the disk
Returns:
Long-running operation poller
"""
def get(resource_group_name: str, disk_name: str) -> Disk:
"""
Get managed disk details.
Args:
resource_group_name: Name of the resource group
disk_name: Name of the disk
Returns:
Disk details
"""
def list() -> Iterable[Disk]:
"""
List all managed disks in the subscription.
Returns:
Iterable of all disks in the subscription
"""
def list_by_resource_group(resource_group_name: str) -> Iterable[Disk]:
"""
List managed disks in a resource group.
Args:
resource_group_name: Name of the resource group
Returns:
Iterable of disks in the resource group
"""Operations for granting access to disks and exporting disk data.
def begin_grant_access(
resource_group_name: str,
disk_name: str,
grant_access_data: GrantAccessData
) -> LROPoller[AccessUri]:
"""
Grant access to a managed disk for export or backup.
Args:
resource_group_name: Name of the resource group
disk_name: Name of the disk
grant_access_data: Access grant parameters including duration and access level
Returns:
Long-running operation poller for AccessUri
"""
def begin_revoke_access(resource_group_name: str, disk_name: str) -> LROPoller[None]:
"""
Revoke access to a managed disk.
Args:
resource_group_name: Name of the resource group
disk_name: Name of the disk
Returns:
Long-running operation poller
"""Operations for managing disk snapshots.
class SnapshotsOperations:
def begin_create_or_update(
resource_group_name: str,
snapshot_name: str,
snapshot: Snapshot
) -> LROPoller[Snapshot]:
"""
Create or update a snapshot.
Args:
resource_group_name: Name of the resource group
snapshot_name: Name of the snapshot
snapshot: Snapshot configuration
Returns:
Long-running operation poller for Snapshot
"""
def begin_delete(resource_group_name: str, snapshot_name: str) -> LROPoller[None]:
"""
Delete a snapshot.
Args:
resource_group_name: Name of the resource group
snapshot_name: Name of the snapshot
Returns:
Long-running operation poller
"""
def get(resource_group_name: str, snapshot_name: str) -> Snapshot:
"""
Get snapshot details.
Args:
resource_group_name: Name of the resource group
snapshot_name: Name of the snapshot
Returns:
Snapshot details
"""
def list() -> Iterable[Snapshot]:
"""
List all snapshots in the subscription.
Returns:
Iterable of all snapshots
"""
def list_by_resource_group(resource_group_name: str) -> Iterable[Snapshot]:
"""
List snapshots in a resource group.
Args:
resource_group_name: Name of the resource group
Returns:
Iterable of snapshots in the resource group
"""Operations for managing disk encryption sets for enhanced security.
class DiskEncryptionSetsOperations:
def begin_create_or_update(
resource_group_name: str,
disk_encryption_set_name: str,
disk_encryption_set: DiskEncryptionSet
) -> LROPoller[DiskEncryptionSet]:
"""
Create or update a disk encryption set.
Args:
resource_group_name: Name of the resource group
disk_encryption_set_name: Name of the disk encryption set
disk_encryption_set: Encryption set configuration
Returns:
Long-running operation poller for DiskEncryptionSet
"""
def begin_delete(resource_group_name: str, disk_encryption_set_name: str) -> LROPoller[None]:
"""
Delete a disk encryption set.
Args:
resource_group_name: Name of the resource group
disk_encryption_set_name: Name of the disk encryption set
Returns:
Long-running operation poller
"""
def get(resource_group_name: str, disk_encryption_set_name: str) -> DiskEncryptionSet:
"""
Get disk encryption set details.
Args:
resource_group_name: Name of the resource group
disk_encryption_set_name: Name of the disk encryption set
Returns:
Disk encryption set details
"""
def list() -> Iterable[DiskEncryptionSet]:
"""
List all disk encryption sets in the subscription.
Returns:
Iterable of all disk encryption sets
"""
def list_by_resource_group(resource_group_name: str) -> Iterable[DiskEncryptionSet]:
"""
List disk encryption sets in a resource group.
Args:
resource_group_name: Name of the resource group
Returns:
Iterable of disk encryption sets in the resource group
"""Operations for managing private endpoints and network access to disks.
class DiskAccessesOperations:
def begin_create_or_update(
resource_group_name: str,
disk_access_name: str,
disk_access: DiskAccess
) -> LROPoller[DiskAccess]:
"""
Create or update a disk access resource for private endpoints.
Args:
resource_group_name: Name of the resource group
disk_access_name: Name of the disk access resource
disk_access: Disk access configuration
Returns:
Long-running operation poller for DiskAccess
"""
def begin_delete(resource_group_name: str, disk_access_name: str) -> LROPoller[None]:
"""
Delete a disk access resource.
Args:
resource_group_name: Name of the resource group
disk_access_name: Name of the disk access resource
Returns:
Long-running operation poller
"""
def get(resource_group_name: str, disk_access_name: str) -> DiskAccess:
"""
Get disk access resource details.
Args:
resource_group_name: Name of the resource group
disk_access_name: Name of the disk access resource
Returns:
Disk access resource details
"""
def list() -> Iterable[DiskAccess]:
"""
List all disk access resources in the subscription.
Returns:
Iterable of all disk access resources
"""class Disk:
"""Disk resource."""
id: Optional[str]
name: Optional[str]
type: Optional[str]
location: str
tags: Optional[Dict[str, str]]
managed_by: Optional[str]
managed_by_extended: Optional[List[str]]
sku: Optional[DiskSku]
zones: Optional[List[str]]
extended_location: Optional[ExtendedLocation]
time_created: Optional[datetime]
os_type: Optional[OperatingSystemTypes]
hyper_v_generation: Optional[HyperVGeneration]
purchase_plan: Optional[PurchasePlan]
creation_data: CreationData
disk_size_gb: Optional[int]
disk_size_bytes: Optional[int]
unique_id: Optional[str]
encryption_settings_collection: Optional[EncryptionSettingsCollection]
provisioning_state: Optional[str]
disk_iops_read_write: Optional[int]
disk_m_bps_read_write: Optional[int]
disk_iops_read_only: Optional[int]
disk_m_bps_read_only: Optional[int]
disk_state: Optional[DiskState]
encryption: Optional[Encryption]
max_shares: Optional[int]
share_info: Optional[List[ShareInfoElement]]
network_access_policy: Optional[NetworkAccessPolicy]
disk_access_id: Optional[str]
tier: Optional[str]
bursting_enabled: Optional[bool]
property_updates_in_progress: Optional[PropertyUpdatesInProgress]
supports_hibernation: Optional[bool]
security_profile: Optional[DiskSecurityProfile]
completion_percent: Optional[float]
public_network_access: Optional[PublicNetworkAccess]
data_access_auth_mode: Optional[DataAccessAuthMode]
optimized_for_frequent_attach: Optional[bool]
class DiskSku:
"""The disks sku name."""
name: Optional[DiskStorageAccountTypes]
tier: Optional[str]
class CreationData:
"""Data for creating a disk."""
create_option: DiskCreateOption
storage_account_id: Optional[str]
image_reference: Optional[ImageDiskReference]
gallery_image_reference: Optional[ImageDiskReference]
source_uri: Optional[str]
source_resource_id: Optional[str]
source_unique_id: Optional[str]
upload_size_bytes: Optional[int]
logical_sector_size: Optional[int]
security_data_uri: Optional[str]
perform_copy_completion: Optional[bool]
elastic_san_resource_id: Optional[str]
provisioned_bandwidth_copy_speed: Optional[ProvisionedBandwidthCopyOption]
class Snapshot:
"""Snapshot resource."""
id: Optional[str]
name: Optional[str]
type: Optional[str]
location: str
tags: Optional[Dict[str, str]]
managed_by: Optional[str]
sku: Optional[SnapshotSku]
extended_location: Optional[ExtendedLocation]
time_created: Optional[datetime]
os_type: Optional[OperatingSystemTypes]
hyper_v_generation: Optional[HyperVGeneration]
purchase_plan: Optional[PurchasePlan]
creation_data: CreationData
disk_size_gb: Optional[int]
disk_size_bytes: Optional[int]
disk_state: Optional[DiskState]
unique_id: Optional[str]
encryption_settings_collection: Optional[EncryptionSettingsCollection]
provisioning_state: Optional[str]
incremental: Optional[bool]
encryption: Optional[Encryption]
network_access_policy: Optional[NetworkAccessPolicy]
disk_access_id: Optional[str]
security_profile: Optional[DiskSecurityProfile]
supports_hibernation: Optional[bool]
public_network_access: Optional[PublicNetworkAccess]
completion_percent: Optional[float]
copy_completion_error: Optional[CopyCompletionError]
data_access_auth_mode: Optional[DataAccessAuthMode]
class DiskEncryptionSet:
"""Disk encryption set resource."""
id: Optional[str]
name: Optional[str]
type: Optional[str]
location: str
tags: Optional[Dict[str, str]]
identity: Optional[EncryptionSetIdentity]
encryption_type: Optional[DiskEncryptionSetType]
active_key: Optional[KeyForDiskEncryptionSet]
previous_keys: Optional[List[KeyForDiskEncryptionSet]]
provisioning_state: Optional[str]
rotation_to_latest_key_version_enabled: Optional[bool]
last_key_rotation_timestamp: Optional[datetime]
auto_key_rotation_error: Optional[ApiError]
federated_client_id: Optional[str]
class DiskAccess:
"""Disk access resource."""
id: Optional[str]
name: Optional[str]
type: Optional[str]
location: str
tags: Optional[Dict[str, str]]
extended_location: Optional[ExtendedLocation]
private_endpoint_connections: Optional[List[PrivateEndpointConnection]]
provisioning_state: Optional[str]
time_created: Optional[datetime]
disk_access_id: Optional[str]
class GrantAccessData:
"""Data for granting access to a disk."""
access: AccessLevel
duration_in_seconds: int
get_secure_vm_guest_state_sas: Optional[bool]
class AccessUri:
"""A disk access SAS uri."""
access_sas: Optional[str]
security_data_access_sas: Optional[str]from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
credential = DefaultAzureCredential()
compute_client = ComputeManagementClient(credential, "subscription-id")
disk_parameters = {
'location': 'East US',
'sku': {
'name': 'Premium_LRS'
},
'creation_data': {
'create_option': 'Empty'
},
'disk_size_gb': 128,
'tags': {
'environment': 'production',
'project': 'myapp'
}
}
operation = compute_client.disks.begin_create_or_update(
'myResourceGroup',
'myDataDisk',
disk_parameters
)
disk = operation.result()
print(f"Disk {disk.name} created with size {disk.disk_size_gb} GB")# First create a snapshot from an existing disk
snapshot_parameters = {
'location': 'East US',
'creation_data': {
'create_option': 'Copy',
'source_resource_id': '/subscriptions/.../disks/sourceDisk'
}
}
operation = compute_client.snapshots.begin_create_or_update(
'myResourceGroup',
'mySnapshot',
snapshot_parameters
)
snapshot = operation.result()
# Create a new disk from the snapshot
disk_from_snapshot = {
'location': 'East US',
'sku': {
'name': 'Standard_LRS'
},
'creation_data': {
'create_option': 'Copy',
'source_resource_id': snapshot.id
}
}
operation = compute_client.disks.begin_create_or_update(
'myResourceGroup',
'diskFromSnapshot',
disk_from_snapshot
)
new_disk = operation.result()
print(f"New disk created from snapshot: {new_disk.name}")# Create disk encryption set
encryption_set_parameters = {
'location': 'East US',
'identity': {
'type': 'SystemAssigned'
},
'encryption_type': 'EncryptionAtRestWithCustomerKey',
'active_key': {
'source_vault': {
'id': '/subscriptions/.../vaults/myKeyVault'
},
'key_url': 'https://mykeyvault.vault.azure.net/keys/mykey/version'
}
}
operation = compute_client.disk_encryption_sets.begin_create_or_update(
'myResourceGroup',
'myEncryptionSet',
encryption_set_parameters
)
encryption_set = operation.result()
# Create encrypted disk
encrypted_disk_parameters = {
'location': 'East US',
'sku': {
'name': 'Premium_LRS'
},
'creation_data': {
'create_option': 'Empty'
},
'disk_size_gb': 256,
'encryption': {
'disk_encryption_set_id': encryption_set.id,
'type': 'EncryptionAtRestWithCustomerKey'
}
}
operation = compute_client.disks.begin_create_or_update(
'myResourceGroup',
'myEncryptedDisk',
encrypted_disk_parameters
)
encrypted_disk = operation.result()
print(f"Encrypted disk created: {encrypted_disk.name}")# Grant read access to disk for export
grant_access_data = {
'access': 'Read',
'duration_in_seconds': 3600 # 1 hour
}
operation = compute_client.disks.begin_grant_access(
'myResourceGroup',
'myDisk',
grant_access_data
)
access_uri = operation.result()
print(f"Disk export URL: {access_uri.access_sas}")
# Later, revoke access
operation = compute_client.disks.begin_revoke_access(
'myResourceGroup',
'myDisk'
)
operation.result()
print("Disk access revoked")# List disks and check their performance characteristics
disks = compute_client.disks.list_by_resource_group('myResourceGroup')
for disk in disks:
print(f"Disk: {disk.name}")
print(f" SKU: {disk.sku.name}")
print(f" Size: {disk.disk_size_gb} GB")
print(f" IOPS: {disk.disk_iops_read_write}")
print(f" Throughput: {disk.disk_m_bps_read_write} MBps")
print(f" State: {disk.disk_state}")
print(f" Provisioning State: {disk.provisioning_state}")
if disk.share_info:
print(f" Shared with {len(disk.share_info)} VMs")
print()Install with Tessl CLI
npx tessl i tessl/pypi-azure-mgmt-compute