新的 Powershell cmdlet(在此处记录:http: //msdn.microsoft.com/en-us/library/windowsazure/jj152841)看起来很可爱,但似乎缺少一个:
Get-OperationStatus -WaitToComplete
没有这个我的 Azure 操作(例如Set-AzureDeployment
)不要等待完成。
这使得在进行 VIP 交换之前很难知道登台实例何时运行。
有没有其他选择?
新的 Powershell cmdlet(在此处记录:http: //msdn.microsoft.com/en-us/library/windowsazure/jj152841)看起来很可爱,但似乎缺少一个:
Get-OperationStatus -WaitToComplete
没有这个我的 Azure 操作(例如Set-AzureDeployment
)不要等待完成。
这使得在进行 VIP 交换之前很难知道登台实例何时运行。
有没有其他选择?
因此,经过调查,我最初的假设部分错误:对新 Powershell cmdlet 的调用确实会等待成功完成,但.Set-AzureDeployment -newStatus "Running"
这很好,因为我们不再需要Get-OperationStatus
分散在脚本中的调用;但是,这很糟糕,因为Set-AzureDeployment
会使部署旋转。
不过,我们可以调用Get-AzureDeployment
,并遍历RoleInstanceList
以找出发生了什么。像这样:
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."
}
但是有一个似乎不见了
如果不支持,请寻找替代方案。例如,请直接使用 REST API 而不是使用 PowerShell。REST API 允许我们跟踪异步请求:http: //msdn.microsoft.com/en-us/library/windowsazure/ee460791。
此外,您还可以在http://www.mygreatwindowsazureidea.com/forums/34192-windows-azure-feature-voting上提交功能请求。
最好的祝福,
明旭。