【问题标题】:How to start Azure VM(Deallocated) use REST API如何启动 Azure VM(Deallocated) 使用 REST API
【发布时间】:2018-08-23 18:36:23
【问题描述】:

我在这里发现了一个很奇怪的问题: 在 Azure PowerShell 中,我们可以使用 启动-AzureVM -ServiceName "mypc" -Name "mypc" 对于 VM 状态 = 停止或停止(已解除分配)。 但是对于 Azure 管理 API 我们只能将start role 用于VM state=stop

VM state=stop(deallocated) 无法使用该 API.. 如何使用 REST API 以 State=Stop(deallocated) 启动 VM? 谢谢。

【问题讨论】:

    标签: azure azure-powershell


    【解决方案1】:

    Windows Azure PowerShell cmdlet 使用服务管理 REST API - 但它使用 undocumented 2013-06-01 版本。此操作可能仅在服务管理 REST API 的未记录版本中可用。

    您可以通过使用 Fiddler 代理请求来查看 cmdlet 实际执行的操作 - 这使您可以访问调用的操作 (URL) 以及发送和接收的负载。或者,您可以查看 GitHub 上提供的 PowerShell cmdlet source

    【讨论】:

    • 您好,我试过 fiddler,但它对我不起作用,因为代理请求会得到 403 禁止问题,cmdlet 将首先发送 get 请求以获取 vm 信息,然后发送 post 请求,如果你用 fiddler 只能获取 get 请求,会导致 403 问题,我有什么不对吗?
    • 是的,使用 x-ms-version: 2013-06-01 可以解决问题,但我仍然想知道如何使用 fiddler 作为代理但不会得到 403 fobidden
    • 您将 Windows Azure 身份验证证书放入 %USERPROFILE%\My Documents\Fiddler2\ClientCertificate.cer fiddler2.com/documentation/Configure-Fiddler/Tasks/…
    • 我花了这么多时间来解决这个问题,却发现这是一个未记录的 api 问题。 Grr.
    【解决方案2】:
    POST https://management.core.windows.net/<subscription-id>/services/hostedservices/<service-name>/deployments/<deployment-name>/roleinstances/<role-name>/Operations
    
    **x-ms-version: 2013-06-01**
    
    <StartRoleOperation xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><OperationType>StartRoleOperation</OperationType></StartRoleOperation>
    

    【讨论】:

    • 谢谢,你的回答对我也有帮助!
    【解决方案3】:
    public Task<ComputeLongRunningOperationResponse> StartVirtualMachineAsync(string subscriptionId, string name, string resource_group)
    {
        TokenCloudCredentials tokenCloudCredential = new TokenCloudCredentials(subscriptionId, token);
    
        ComputeManagementClient computeManagementClient = new ComputeManagementClient(tokenCloudCredential);
    
        return computeManagementClient.VirtualMachines.StartAsync(resource_group, name);
    }
    

    【讨论】:

      猜你喜欢
      • 2017-04-15
      • 2021-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-13
      • 2020-04-20
      • 1970-01-01
      相关资源
      最近更新 更多