【问题标题】:Using powershell windows azure commandlets, how to I execute Reset-RoleInstance and wait for the operation to complete使用 powershell windows azure commandlets,如何执行 Reset-RoleInstance 并等待操作完成
【发布时间】:2012-05-04 03:16:39
【问题描述】:

如何执行 Reset-RoleInstance 并等待操作完成...

我一直在尝试使用 windows azure powershell commandlet 来执行 Reset-RoleInstance,然后是 | Get-OperationStatus -WaitToComplete。

因此文档说“此操作异步执行。要确定管理服务是否已完成对请求的处理,请使用 Reset-RoleInstance 返回的操作 ID 调用 Get-OperationStatus cmdlet,并可选择通过指定 – WaitToComplete 参数。”

我试过这个版本:

Reset-RoleInstance -ServiceName MyTodo -DeploymentSlot production -SubscriptionId $subsId -Certificate $cert –reboot | GetOperationStatus -WaitToComplete

但这在“GetOperationStatus”中有一个类型。因此,当我用“Get-OperationStatus”替换时,PS 会抱怨 OperationId 为 null 或为空。

"Get-OperationStatus : 无法验证参数“OperationId”上的参数。参数 为空或为空。提供一个不为空或不为空的参数,然后尝试使用命令 d 再次。”

所以,接下来我试试这个版本的 PS 脚本...

Reset-RoleInstance -ServiceName $serviceName -DeploymentSlot Production -InstanceName $i.InstanceName -SubscriptionId $subid -Certificate $cert -Reboot -OutVariable out | Get-OperationStatus -OperationId out.OperationId -WaitToComplete

这一次,Get-OperationStatus 开始抛出错误......

Get-OperationStatus:HTTP 状态代码:BadRequest - HTTP 错误消息:未找到操作请求 ID ...在 Microsoft.WindowsAzure.Samples.ManagementTools.PowerShell.Services.Common.GetOperationStatusCommand

Get-OperationStatus:对象引用未设置为对象的实例....在 Microsoft.WindowsAzure.Samples.ManagementTools.PowerShell.Services.Common.GetOperationStatusCommand"*

我还设法打印了 $out 并且 OperationId 实际上是 null 但是在输出的 RoleInstances 成员中有这个值... RoleInstances : {Instance Name: MyService.MyWorker_IN_0 - Operation Id: 6e87a07fb9a5474499aed3f9ebe99129}

这是 $out 变量的输出... “角色实例:{实例名称:MyService.MyWorker_IN_0 - 操作 ID:6e87a07fb9a5474499aed3f9ebe99129} ServiceName : ...我的服务名称 SubscriptionId : ... 我的订阅 ID 证书:...我的证书信息

操作 ID: "

【问题讨论】:

    标签: powershell azure powershell-2.0


    【解决方案1】:

    当您使用 Reset-RoleInstance 时,它会重新启动/重新映像部署实例。
    整个操作本身没有 OperationId,但单个 RoleInstances 有相应的 >OperationId 每个。

    Reset-RoleInstance 的输出如下所示:

    PS > $operation = Reset-RoleInstance -ServiceName "MyServiceName" -DeploymentSlot "production" -Restart -SubscriptionId "MySubscriptionID" -Certificate $cert
    PS > $operation
    -
    RoleInstances  : { Instance Name: MyInst1 - Operation Id: OpId1, 
    -                  Instance Name: MyInst2 - Operation Id: OpId2 }
    
    ServiceName    : MyServiceName
    SubscriptionId : MySubscriptionID
    Certificate    : [Subject]
    -                ------- blah --------
    
    -                [Issuer]
    -                ------- blah --------
    
    -                [Serial Number]
    -                ------- blah --------
    
    -                [Not Before]
    -                ------- blah --------
    
    -                [Not After]
    -                ------- blah --------
    
    -                [Thumbprint]
    -                ------- blah --------
    
    OperationId    : <NullOrEmpty>
    

    如您所见,末尾的 OperationIdNullOrEmpty。因此,您不应等待 Reset-RoleInstanceOperationId,而应等待 OperationIds em> 个人 RoleInstances
    例如:OpId1、OpId2

    PS > Write-Host "Rebooting the instances"
    PS > $operation = Reset-RoleInstance -Reboot -SubscriptionId $SubscriptionId -ServiceName $ServiceName -DeploymentSlot "Production" -Certificate $certificate
    PS > Write-Host "Waiting for all reboot operations to complete..."
    PS > $operation.RoleInstances | % { Get-OperationStatus -OperationId $_.OperationId -WaitToComplete -SubscriptionId $SubscriptionId -Certificate $certificate }
    PS > Write-Host "All role-instances have been rebooted"
    

    【讨论】:

      猜你喜欢
      • 2014-12-22
      • 2016-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-31
      • 1970-01-01
      • 2011-12-16
      • 1970-01-01
      相关资源
      最近更新 更多