The Azure Python SDK now supports Azure Managed Disks!
Azure Managed Disks and 1000 VMs in a Scale Set are now generally available. Azure Managed Disks provide a simplified disk management, enhanced scalability, and better security. It takes away the notion of storage account for disks, enabling developers to scale without worrying about the limitations associated with storage accounts. This post provides a quick introduction and reference to consuming key service features from Python.
From a developer perspective, the Managed Disks experience in Azure CLI is idomatic to the CLI experience in other cross-platform tools. You can use the Azure Python SDK and the azure-mgmt-compute package 0.33.0 to administer Managed Disks. You can create a compute client using this tutorial. The complete API documentation is available on ReadTheDocs.
Standalone Managed Disks
Prior to Managed Disks, developers needed to maintain images for their VMs in multiple storage accounts to avoid the risk of running out of disk space. It is easy to see how this can complicate the architecture, and the dev-ops, for a service that requires a large number of VMs quickly, and has to be available across multiple regions. With Managed Disks, you do not need to worry about replicating images into new storage accounts. You can have a single image per region, and the service will make sure they are available for up to 10,000 VMs under a single subscription.
You can create new disks from various starting points with a lines of Python code. Here are a few specific examples:
Create an empty Managed Disk
Create a Managed Disk from Blob Storage
Create a Managed Disk from our own Image
Here’s a quick preview for creating an empty Managed disk in Python with a few lines of code:
from azure.mgmt.compute.models import DiskCreateOption
async_creation = compute_client.disks.create_or_update(
'my_resource_group&039;,
&039;my_disk_name&039;,
{
&039;location&039;: &039;westus&039;,
&039;disk_size_gb&039;: 20,
&039;creation_data&039;: {
&039;create_option&039;: DiskCreateOption.empty
}
}
)
disk_resource = async_creation.result()
Virtual Machine with Managed Disks
Now that you know the basics of creating managed disks, but how do you configure your service to create VMs from images stored on a Managed Disk? The service affords flexibility to create VMs from various types of Managed Disks. You can create a VM with an implicit Managed Disk for a specific disk image. Creation is simplified with implicit creation of managed disks without specifying all the disk details. You do not have to worry about creating and managing Storage Accounts.
A Managed Disk is also implicitly created when provisioning a VM from an OS image on the Azure Marketplace. Here’s an example for a Ubuntu VM. Notice how the storage account parameter is optional in the VM definition.
storage_profile = azure.mgmt.compute.models.StorageProfile(
image_reference = azure.mgmt.compute.models.ImageReference(
publisher=&039;Canonical&039;,
offer=&039;UbuntuServer&039;,
sku=&039;16.04.0-LTS&039;,
version=&039;latest&039;
)
)
You can easily attach a previously provisioned Managed Disk as shown here. See a complete example on how to create a VM in Python (including network), and how check the full VM tutorial in Python.
Virtual Machine Scale Sets with Managed Disks
For very large scale services, Azure recommends using Virtual Machine Scale Sets (VMSS). VMSS allows developers to create a pool of VMs with identical configuration. The service allows “true autoscale” – developers do not need to pre-provision VMs. Prior to Managed Disks, the developers needed to consider the design carefully to ensure efficient Disk IO, ideally using a single storage account for up to 20 VMs. This limitation required developers to create and manage additional storage accounts to support a larger scale. With Managed Disk, you don’t have to manage any storage account at all. If you are used to the VMSS Python SDK, your storage_profile can now be exactly the same as the one used in VM creation. This feature also simplifies programming – you no longer have to manage any storage account at all.
The official guide to transitioning from user managed storage to Managed Disks is available in this article. Quick samples are also available for preview.
Get productive with the Azure CLI
If the CLI is your management tool of choice, there are several handy commands available for various scenarios. For example, here’s how you can create a stand alone Managed Disk from the Azure CLI with a single command:
az disk create -n myDisk -g myResourceGroup –size-gb 20
Check out Aaron Roney’s blog post to learn more CLI commands for programming Managed Disks.
Other operations
There are numerous other quick management operations you might need to get started with Managed Disks. See sample code for the following operations:
Resizing a managed disk from the Azure CLI
Updating the Storage Account type of the Managed Disks
Creating an image from Blob Storage
Creating a snapshot of a Managed Disk that is currently attached to a Virtual Machine
In summary
Managed Disks can tighten your workflow, simplify your service architecture, and offer you greater peace of mind in running a highly scalable Python cloud service. It also offers better reliability for Availability Sets by ensuring that the disks of VMs in an Availability Set are sufficiently isolated from each other to avoid single points of failure, and offers better security via granular role based access to resources. You can use the Azure CLI to create and manage your Managed Disks. Hopefully this blog post serves as a quick reference as you try Managed Disks on your own. For more information about the service, head over the Azure documentation. For feedback on the Python SDK, please send an email to azurepysdk@microsoft.com.
Quelle: Azure
Published by