Getting Role Instance Information with the Windows Azure SDK for PHP Command Line Tools

June 7, 2012 update: The Microsoft Windows Azure team has released a new Windows Azure SDK for PHP. This release is part of an effort to keep PHP client libraries up to date with new Windows Azure features and to make PHP a first-class citizen in Windows Azure. The latest client libraries are on GitHub: https://github.com/WindowsAzure/azure-sdk-for-php. While the SDK hosted on CodePlex will continue to work for the foreseeable future, it is strongly recommended that new PHP/Windows Azure application use the SDK hosted on GitHub.

The work done by Maarten Balliauw and other contributors in building the SDK hosted on CodePlex was critical in unifying the PHP developer experience for Windows Azure. The Windows Azure team is grateful to these contributors for their pioneering work and looks forward to their continued support (and yours!) in adding to the new SDK on GitHub.

Thanks,

      
The Windows Azure Team


Last week I wrote a couple of posts (here and here) about the command line tools in the Windows Azure SDK for PHP. And, as I pointed out in the latter of those posts, I found it necessary to extend the functionality of the command line tools. After a bit of reflection, I started wondering two things:

  1. Would others find my extension to the command line tools useful? If yes, is my design for the extension useful. Is it designed in a way that you would expect?
  2. More broadly, how do developers envision using the command line tools? I have ideas about scenarios where the tools are useful, but I’m just one person.

So, in this post, I’ll share a bit more detail about the work I’ve done in extending the command line tools in hopes of stimulating some discussion around the questions above. (BTW, I've submitted the code for the functionality below as a patch for the Windows Azure SDK for PHP. Hopefully, my patch will be accepted soon. EDIT: My patch has been accepted to the SDK, so the functionality described below is now available!)

In a nutshell, I added 3 operations to the deployment command line tool:

  • getRoleInstances: Returns the number of instances that are running for a specified deployment as well as the name and status for each instance.
  • getRoleInstanceProperties: Returns the status, upgrade domain, fault domain, and size of a specified instance.
  • getRoleInstanceProperty: Returns the role name, status, upgrade domain, fault domain, or size of a specified instance by instance name and property name.

Note: All the information I’m surfacing in these operations is already available via the PHP API of the Windows Azure SDK, it just wasn’t accessible via the command line.

Here’s how these operations are used and example outputs:

getRoleInstances

Example command (getting role instances by specifying the deployment slot – production or staging):

 deployment getRoleInstances -F="C:\config.ini" --Name="dns_prefix" --BySlot=Production

Example output:

InstanceCount:2

Instance0
Name:PhpOnAzure.Web_IN_0
Status:Ready

Instance1
Name:PhpOnAzure.Web_IN_1
Status:Ready

You can get the same information by specifying a deployment by name (instead of by “slot”, as shown above)

getRoleInstanceProperties

Example command (getting role instance properties for a specified deployment and specified instance):

 deployment getRoleInstanceProperties -F="C:\config.ini" --Name="dns_prefix" --BySlot=Production --InstanceName="PhpOnAzure.Web_IN_1"

Example output:

Status:Ready
Upgrade domain:1
Fault domain:1
Size:Small

You can get the same information by specifying a deployment by name (instead of by “slot”, as shown).

getRoleInstanceProperty

Example command:

 deployment getRoleInstanceProperty -F="C:\config.ini" --Name="dns_prefix" --BySlot=Production --InstanceName="PhpOnAzure.Web_IN_0" --PropertyName="Status"

Example output:

Ready

Again, you can also specify the deployment by name instead of by “slot”.

So, what good are these new operators? Well, at the risk of showing my inexperience with batch scripts, now you can write a script that will create a service, deploy a package, and return when all instances are running:

 @echo off
 echo Creating service...
 call service create -F="C:\config.ini" --Name="dns_prefix" --Location="North Central US" --Label="service_label" --WaitFor
 echo.
 echo Creating deployment...
 call deployment createfromlocal -F="C:\config.ini" --Name="dns_prefix" --DeploymentName="deployment_name" --Label="deployment_label" --Production --PackageLocation="path\to\.cspkg" --ServiceConfigLocation="path\to\.cscfg" --StorageAccount="your_storage_account_name" --WaitFor
 echo.
 echo Starting instances...
 :loop
 call deployment getRoleInstances -F="C:\config.ini" --Name="dns_prefix" --BySlot=Production --WaitFor>; status.txt
 set I=0
 set J=0
 FOR /F "tokens=1,2 delims=:" %%G in (status.txt) DO (
 if [%%G]==[InstanceCount] set J=%%H
 if [%%G]==[Status] if [%%H]==[Ready] set /a I+=1
 )
 if %I% NEQ %J% goto loop
 echo.
 echo All instances in Ready state.
 echo Services:
 call service list -F="C:\config.ini"
 echo.
 echo New deployment properties:
 call deployment getproperties -F="C:\config.ini" --Name="dns_prefix" --BySlot="production" --WaitFor

Of course, that is just one possibility. You can now write scripts that become the tools for easily deploying and managing your Azure deployments. Which brings me back to my original questions: Basically, does this seem useful?

Thanks.

-Brian

Share this on Twitter