First of all thanks to everyone that watched my session at Build. I’ve received quite a bit of positive feedback so far (one wasn’t so positive.. you know who you are ;-)).
One of the common requests I’ve received is to get access to the source code for the demo virtual machine manager app I showed.
I’ve posted the full source for this demo in a repo on GitHub.
Disclaimer: This demo was designed specifically to show off how to how to use the service management API for basic operations. The code has limited (to no) exception handling, best practices or anything else that would work in a production application 🙂
So now that you know the quality level of the code level of the demo I do want to explain a bit of how it works.
There are two projects: SMLibrary which is a very basic wrapper around the Windows Azure Service Management API and MyVMPortal is the other. MyVMPortal is an ASP.NET WebForms app that uses the API to create a VM.
To run it locally you will need to have a management certificate installed on your local machine that is also installed in your Windows Azure subscription.
Open the web.config page and add your subscription ID, cert thumbprint and storage account name(s) (separate them by comma if you want multiple storage accounts). The app by default is hard coded to deploy to West US. So unless you change that you will need to create your storage accounts in West US as well.
Long term it might be nice to further expand this demo to show other functionality for automating virtual machines. If you are interested in contributing please let me know.
I just wanted to share a little tweak added to the PowerShell cmdlets that made it quite a bit easier to troubleshoot them as they were being built.
If you are trying to understand the Service Management API for VMs it may be useful 🙂
For most of the cmdlets that have a significant request payload such as New-AzureVM etc.. We’ve added a -Verbose switch that will dump out the underlying API request as it is executed.
For example, this snippet creates a new Windows Server 2008 R2 VM with port 80 open and a data disk attached with ReadWrite caching enabled.
New-AzureVMConfig -Name 'myvm' -ImageName 'MSFT__Win2K8R2SP1-120514-1520-141205-01-en-us-30GB.vhd' -InstanceSize 'Small' |
Add-AzureProvisioningConfig -Windows -Password 'somepassword' |
Add-AzureEndpoint -Name 'web' -LocalPort 80 -PublicPort 80 -Protocol tcp |
Add-AzureDataDisk -CreateNew -DiskSizeInGB 50 -DiskLabel 'CacheDisk' -HostCaching 'ReadWrite' -LUN 0 |
New-AzureVM -ServiceName 'myservicefromps' -Location 'East US' -Verbose
In the resulting output you can see that the New-AzureVM cmdlet actually makes two API calls in order to create the hosted service and then the new deployment. If you omit the -location parameter it will attempt to use an existing cloud service.
VERBOSE: <CreateHostedService xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/windowsazure">
<Description>Implicitly created hosted service2012-06-11 09:11</Description>
New-AzureVM - Create Cloud Service 68f6b264-c97a-4e85-84f0-6f554494a0e0 Succeeded
VERBOSE: <Deployment xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/windowsazure">
<OsVersion i:nil="true" />
New-AzureVM - Create Deployment with VM myvm d0e4c5d5-9c51-422d-abfa-6e856639272c Succeeded