Advanced Windows Azure IaaS – Demo Code

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.

Thanks!
Michael Washam

Windows Azure Service Management API Cheat Sheet with PowerShell

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: New-AzureVM
VERBOSE: <CreateHostedService xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/windowsazure">
  <ServiceName>myservicefromps</ServiceName>
  <Label>bXlzZXJ2aWNlZnJvbXBz</Label>
  <Description>Implicitly created hosted service2012-06-11 09:11</Description>
  <Location>East US</Location>
</CreateHostedService>

New-AzureVM - Create Cloud Service                    68f6b264-c97a-4e85-84f0-6f554494a0e0                  Succeeded

VERBOSE: New-AzureVM
VERBOSE: <Deployment xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/windowsazure">
  <Name>myservicefromps</Name>
  <DeploymentSlot>Production</DeploymentSlot>
  <Label>myservicefromps</Label>
  <RoleList>
    <Role i:type="PersistentVMRole">
      <RoleName>myvm</RoleName>
      <OsVersion i:nil="true" />
      <RoleType>PersistentVMRole</RoleType>
      <ConfigurationSets>
        <ConfigurationSet i:type="WindowsProvisioningConfigurationSet">
          <ConfigurationSetType>WindowsProvisioningConfiguration</ConfigurationSetType>
          <ComputerName>myvm</ComputerName>
          <AdminPassword>somepassword</AdminPassword>
          <EnableAutomaticUpdates>true</EnableAutomaticUpdates>
          <ResetPasswordOnFirstLogon>false</ResetPasswordOnFirstLogon>
        </ConfigurationSet>
        <ConfigurationSet i:type="NetworkConfigurationSet">
          <ConfigurationSetType>NetworkConfiguration</ConfigurationSetType>
          <InputEndpoints>
            <InputEndpoint>
              <LocalPort>3389</LocalPort>
              <Name>RDP</Name>
              <Protocol>tcp</Protocol>
            </InputEndpoint>
            <InputEndpoint>
              <LocalPort>80</LocalPort>
              <Name>web</Name>
              <Port>80</Port>
              <Protocol>tcp</Protocol>
            </InputEndpoint>
          </InputEndpoints>
        </ConfigurationSet>
      </ConfigurationSets>
      <DataVirtualHardDisks>
        <DataVirtualHardDisk>
          <HostCaching>ReadWrite</HostCaching>
          <DiskLabel>CacheDisk</DiskLabel>
          <LogicalDiskSizeInGB>50</LogicalDiskSizeInGB>
          <MediaLink>https://mweaststorage1.blob.core.windows.net/vhds/myservicefromps-myvm-CacheDisk-2012-6-11-649.vhd</MediaLink>
        </DataVirtualHardDisk>
      </DataVirtualHardDisks>
      <Label>bXl2bQ==</Label>
      <OSVirtualHardDisk>
        <MediaLink>https://mweaststorage1.blob.core.windows.net/vhds/myservicefromps-myvm-2012-6-11-649.vhd</MediaLink>
        <SourceImageName>MSFT__Win2K8R2SP1-120514-1520-141205-01-en-us-30GB.vhd</SourceImageName>
      </OSVirtualHardDisk>
      <RoleSize>Small</RoleSize>
    </Role>
  </RoleList>
</Deployment>
New-AzureVM - Create Deployment with VM myvm          d0e4c5d5-9c51-422d-abfa-6e856639272c                  Succeeded