Azure CLI: Managed Disks

Today, we announce Azure CLI support for Azure Managed Disks!

Microsoft announced the general availability of Azure Managed Disks – it simplifies the management and scaling of Virtual Machines.  The Managed Disks experience in Azure CLI is idomatic to the CLI experience in other cross-platform tools, and we know you will love it!

You can use the Azure CLI to administer Managed Disks: check out the install guide for information on how to install or update the Azure CLI.

Standalone Managed Disks

You can easily create standalone Managed Disks in a variety of ways.

Create an empty Managed Disk.

az disk create
-n myDisk
-g myResourceGroup
–size-gb 20

Create a Managed Disk from Blob Storage.

az disk create
  -g myResourceGroup
  -n myDisk
  –source https://bg09.blob.core.windows.net/vm-images/non-existent.vhd

Create a Managed Disk from an existing image.

az disk create
-n myDisk
-g myResourceGroup
​ –source <…id…>/Microsoft.Compute/disks/mdvm1_OsDisk_1_<guid>

It&;s as easy as that, and each of these disks can be subsequently attached to a Virtual Machine (see below).

Virtual Machine with Managed Disks

You can create a Virtual Machine 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 created implicitly when creating VM from an OS image in Azure.

az vm create
  -n myVm
  -g myResourceGroup
  –generate-ssh-keys
  –image UbuntuLTS

This Managed Disk is created by default, and you can easily verify its ID by using the –query feature of Azure CLI.

az vm list
  –query "[].{ name:name, os:storageProfile.osDisk.managedDisk.id }"
  -o tsv

As mentioned previously, you can easily attach a previously provisioned Managed Disk.

az vm disk attach
  –vm-name myVm
  -g myResourceGroup
  –disk <…id…>/Microsoft.Compute/disks/testmd

Create a new VM Scale Set with new resources (Virtual Machines and Managed Disks) from an image.

az vmss create
  -n myVmScaleSet
  -g myResourceGroup
  –admin-username <user>
  –admin-password <password>
  –instance-count 4
  –image Win2012R2Datacenter

Other Operations with Managed Disks

Resizing a managed disk from the Azure CLI is easy and straightforward.

az disk update
  -n myDisk
  -g myResourceGroup
  -z 25

You can also update the Storage Account type of the Managed Disks.

az disk update
  -n myDisk
  -g myResourceGroup
  –sku Standard_LRS

Create an image from Blob Storage.

az image create
  -g myResourceGroup
  -n myImage
  –os-type Linux
  –source <…id…>/Microsoft.Compute/disks/osdisk_<guid>

Create a snapshot of a Managed Disk that is currently attached to a Virtual Machine.

az snapshot create
  -g myResourceGroup
  -n mySnapshot
  –source <…id…>/Microsoft.Compute/disks/mdvm1_OsDisk_1_<guid>

Try It

You can run the examples above as they appear (with the proper values, of course). Give it a try and let us know what do you think (in the comments below).  Azure CLI has more exciting services on the way, and we are excited to hear your thoughts on how the idiomatic experience integrates with the shell tools you know and love.
Quelle: Azure

Published by