Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

The Case of the Latest Windows Azure VM Image

DZone's Guide to

The Case of the Latest Windows Azure VM Image

· Cloud Zone
Free Resource

Linkerd, the open source service mesh for cloud native applications. Get the complete guide to using Linkerd and Kubernetes to build scalable, resilient applications.

When creating new Windows Azure VMs, an Operating System (OS) image needs to be specified.  Microsoft maintains a repository of images that are available to be used when creating a new VM.  These images could be regular Windows Server 2012 or Windows Server 2008 images, server images with software like SQL Server or BizTalk server installed, or even various Linux distributions.

To get a list of all available images, execute the Get-AzureVMImage cmdlet.  This will return a list of all possible images and details for each.

get-azurevmimage

Sometimes there may be multiple versions of a particular type of image.  For example, Microsoft will maintain a few versions of Window Server images – these very by patch level.

Notice the properties available (Location, Label, OS, ImageFamily, etc.) for each image.  These can be very helpful in narrowing the list of images.

Find the Image Type

In order to find a particular type of image, the ImageFamily property can be used.

Get-AzureVMImage `
| where { $_.ImageFamily -eq “Windows Server 2012 Datacenter” }

This returns details of only the Windows Server 2012 Datacenter images.

get-azurevmimage - imagefamily

Find the Latest Image

In order to find the most recent version of a particular type of image, the PublishDateproperty can be used to enhance the query.

$images = Get-AzureVMImage `
| where { $_.ImageFamily -eq “Windows Server 2012 Datacenter” } `
| Sort-Object -Descending -Property PublishedDate
 
$latestImage = $images[0]
$latestImage

Using the above snippet, only the most recent version of the “Windows Server 2012 Datacenter” image will be returned.

Images Aren’t Always Available

Take another look at the properties returned by Get-AzureVMImage.  Notice there is aLocation property.  This specifies in which Windows Azure data centers the particular image is available.  All images may not be available in all data centers.  I’ve only seen this happen a few times, and it seemed to be related to a new OS image rolling out to the various data centers.  If trying to create a new VM with an image that is not supported in the target data center, the Windows Azure service management interface will return a 400 error related to a location constraint:

New-AzureVM : “An exception occurred when calling the ServiceManagement API. HTTP Status Code: 400. Service 
Management Error Code: BadRequest. Message: The location constraint is not valid. Operation Tracking ID: 
0ba6c633f3xxxxxxxxxxxxxxxxxxxxxx.”

To remedy this, slightly modify the script to include logic to select images that are only available in the desired data center location.

$images = Get-AzureVMImage `
| where { $_.ImageFamily -eq "Windows Server 2012 Datacenter" } `
    | where { $_.Location.Split(";") -contains "West US"} `
    | Sort-Object -Descending -Property PublishedDate

Using the above snippet, only the most recent version of the “Windows Server 2012 Datacenter” image that is supported in the “West US” datacenter will be returned.

Create the Virtual Machine

Now that the desired VM OS image has been found, the New-AzureVMConfig andNew-AzureVM cmdlets can be used to create the new Virtual Machine.

# Get the latest version of the Windows Server 2012 Datacenter image.
$images = Get-AzureVMImage `
| where { $_.ImageFamily -eq $imageFamily } `
    | where { $_.Location.Split(";") -contains $location} `
    | Sort-Object -Descending -Property PublishedDate
$myVM = New-AzureVMConfig -Name “myvm01” -InstanceSize “Small” -ImageName $images[0].ImageName -DiskLabel "OS" `
| Add-AzureProvisioningConfig -Windows -Password $password -AdminUsername $username -DisableAutomaticUpdates
 
New-AzureVM -ServiceName “myvmservice” -VMs $myVM -Location “West US” -WaitForBoot












Linkerd, the open source service mesh for cloud native applications. Get the complete guide to using Linkerd and Kubernetes to build scalable, resilient applications.

Topics:

Published at DZone with permission of Michael Collier, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}