Azure Disk Storage
A high-performance, durable block storage designed to be used with Azure Virtual Machines and Azure VMware Solution.
661 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Is there a way to create a disk from a snapshot using the Azure python SDK? In the DiskOperations class begin_create_or_update has no parameter for a snapshot.
You can create the parameters using below block , that API Begin_Create_or_Update just requires the RG , DiskName, DiskParameters.
Disk Parameters can be created using below block !
snapshot_resource_id = f"/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.Compute/snapshots/{snapshot_name}"
disk_params = {
'location': 'EastUS',
'creation_data': {
'create_option': 'Copy',
'source_resource_id': snapshot_resource_id
},
'disk_size_gb': disk_size_gb,
'os_type': 'Linux'
}
disk_result = compute_client.disks.begin_create_or_update(resource_group_name, disk_name, disk_params).result()
//////////// Final piece of tested code to create disk from snapshots looks like below://///
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
# Set your subscription ID and resource group name
subscription_id = 'subid'
resource_group_name = 'testsnapshot'
# Set the snapshot details
snapshot_name = 'testsnapshot'
disk_name = 'testdiskfromtestsnapshot'
disk_size_gb = 100 # Specify the desired size of the new disk in GB
# Initialize the Azure credentials
credential = DefaultAzureCredential()
# Create a ComputeManagementClient object
compute_client = ComputeManagementClient(credential, subscription_id)
# Get the snapshot resource ID
snapshot_resource_id = f"/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.Compute/snapshots/{snapshot_name}"
# Create the disk
disk_params = {
'location': 'EastUS',
'creation_data': {
'create_option': 'Copy',
'source_resource_id': snapshot_resource_id
},
'disk_size_gb': disk_size_gb,
'os_type': 'Linux'
}
disk_result = compute_client.disks.begin_create_or_update(resource_group_name, disk_name, disk_params).result()
Regards,
Shiva.