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:
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:
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:
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
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)
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"
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).
Example command:
deployment getRoleInstanceProperty -F="C:\config.ini" --Name="dns_prefix" --BySlot=Production --InstanceName="PhpOnAzure.Web_IN_0" --PropertyName="Status"
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
@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 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 All instances in Ready state.
echo Services:
call service list -F="C:\config.ini"
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