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.
The Windows Azure Team
I’ve been spending quite a bit of time exploring the command line tools for the Windows Azure SDK for PHP. As I’ve done so, I found that I needed to add functionality in some areas (essentially, I needed the ability to access role instance properties). What I want to share in this post is just how easy it was to extend the command line tools.
The first thing to understand about the Windows Azure SDK for PHP command line tools is that the functionality for each tool is defined in the classes in the \library\Microsoft\WindowsAzure\CommandLine directory:
(The .bat and .sh files that are actually called at the command line are essentially wrappers for these classes and can be found in the \bin directory.) The key to easily extending command line functionality is that each of these classes extends the Microsoft_Console_Command class (read Maarten Balliauw’s post A hidden gem in the Windows Azure SDK for PHP: command line parsing for more information about how this works). So, to add functionality for getting role instance properties, I just needed to add an appropriately decorated method to the Deployment class:
Pay close attention to the comments on the method – it’s the comments that allow the Microsoft_Console_Command class to do its magic. And, if you look closely, you’ll see that I call two methods on the $client object (getRoleInstancesByDeploymentSlot and getRoleInstancesByDeploymentId). I had to add those methods to the Microsoft_WindowsAzure_Management_Client class (which was easy to do by using the existing methods as models). Here’s the getRoleInstancesByDeploymentSlot class:
That’s it. Typing deployment at the command line shows that my new getiroleinstanceproperties operation is now part of the deployment tool.
So, in summary, to add operations to a command line tool: Add a method to the class in the \library\Microsoft\WindowsAzure\CommandLine directory that corresponds to the command line tool you want to extend. Be sure to appropriately comment the method (as shown above or explained in this post). Depending on what your added method does, you may have to add functionality to other classes in the SDK. Of course, after you are done, submit your work as a patch! (I’m in the process of doing that now.)