Azure Powershell cmdlets for 1.7, June 2012: what's happened to Get-OperationStatus?
Asked Answered
K

2

5

The new Powershell cmdlets (documented here: http://msdn.microsoft.com/en-us/library/windowsazure/jj152841) look lovely, but there's one that appears missing:

Get-OperationStatus -WaitToComplete

Without this my Azure operations (e.g. Set-AzureDeployment) don't wait for completion.

This makes it hard to know when e.g. a staging instance is running before doing a VIP swap.

Are there any alternatives?

Keener answered 5/7, 2012 at 10:25 Comment(3)
Also, I don't seem to be able to install the older versions of the Powershell cmdlets; they fail on the dependency checker, as it appears that 1.6 of the SDK isn't available any more...Keener
v1.6 SDK download is here, in case you decide to go that route.Anabolite
See my answer below. In general the cmdlets do wait for completion, except for Set-AzureDeployment, which is of course the one we'd like to wait! But we have the relevant bits we'll need to sort this.Keener
K
10

So, after investigation, my initial supposition was partly wrong: calls to the new Powershell cmdlets do wait for successful completion, except for Set-AzureDeployment -newStatus "Running".

This is good, as we no longer need to have calls to Get-OperationStatus scattered through the script; it's bad, though, as Set-AzureDeployment leaves the deployment spinning up.

We can call Get-AzureDeployment, though, and iterate through the RoleInstanceList to figure out what's going on. Like so:

function Get-StagingReady {
    $stagingStatus = Get-AzureDeployment $azureService -slot staging 
    if (-not $($stagingStatus.Status -eq "Running")) {
        Write-Host $(" ... ... Staging slot status is not Running; value is " + $stagingStatus.Running)
        return $False
    }

    if (-not $stagingStatus.RoleInstanceList) {
        Write-Host " ... ... Staging slot has no instances configured yet."
        return $False
    }

    $notReady = $False

    Foreach ($roleInstance in $stagingStatus.RoleInstanceList) {
        if (-not $($roleInstance.InstanceStatus -eq "ReadyRole")) {
            Write-Host $(" ... ... ... Staging slot instance " + $roleInstance.InstanceName + " has status " + $roleInstance.InstanceStatus)
            $notReady = $True
        }
    }

    if ($notReady) {
        Write-Host " ... ... One or more instances not running."
        return $False
    }

    Write-Host " ... Staging slot ready for use."
    return $True
}


function Wait-ForStagingToBeReady {
    while ( -not $(Get-StagingReady) ) {
        Write-Host " ... ... Staging slot not ready, waiting 15 seconds for Azure to spin up instances."
        Start-Sleep -s 15
    }
}


function Start-Staging {
    Write-Host " ... Starting staging slot."

    $staging = Get-Staging $azureService 
    $result = Set-AzureDeployment `
            -Status `
            -serviceName $azureService `
            -slot "Staging" `
            -newStatus "Running" 

    if (-not $?) {
        Write-Host
        Write-Host "Unable to start staging slot."
        Write-Host "DEPLOY FAILED"
        Write-Host
        exit 1
    }

    Wait-ForStagingToBeReady

    Write-Host " ... Deployment in Staging slot started."
}
Keener answered 9/7, 2012 at 14:37 Comment(1)
Good work! I was thinking if there is a alternative way for Get-OperationStatus. And It is bad to remove it in the newer version without any explain.Selfdelusion
H
0

but there's one that appears missing

If it’s not supported, then please find an alternative. For example, please use the REST API directly instead of using PowerShell. The REST API allows us to track async requests: http://msdn.microsoft.com/en-us/library/windowsazure/ee460791.

In addition, you can also submit a feature request on http://www.mygreatwindowsazureidea.com/forums/34192-windows-azure-feature-voting.

Best Regards,

Ming Xu.

Hachure answered 6/7, 2012 at 9:44 Comment(2)
There is much that makes the Powershell cmdlets difficult to use in a scripted environment, which is what I'd like to do for our continuous deployment scenario. Having to write my own Powershell script against the REST API to make sure each operation is atomically complete frankly takes the biscuit.Keener
I've posted the suggestion here: mygreatwindowsazureidea.com/forums/…Keener

© 2022 - 2024 — McMap. All rights reserved.