How to start Azure VM(Deallocated) use REST API

a 夏天 提交于 2020-01-16 02:14:38

问题


I found a very strange problem here: In Azure powershell, we can use Start-AzureVM -ServiceName "mypc" -Name "mypc" for both VM state= stop or stop(Deallocated). But for Azure Mangement API We can use start role only for VM state= stop

VM state=stop(deallocated) can't use that API.. How can I use REST API to start VM with State=Stop(deallocated)? Thanks.


回答1:


The Windows Azure PowerShell cmdlets use the Service Management REST API - but it uses an undocumented 2013-06-01 version. It is possible that this operation is available only in the undocumented version of the Service Management REST API.

You can see what the cmdlets actually do by using Fiddler to proxy the request - this gives you access to the operation invoked (URL) as well as the payload sent and received. Alternatively, you can look at the PowerShell cmdlets source which is available on GitHub.




回答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);
}


来源:https://stackoverflow.com/questions/19065253/how-to-start-azure-vmdeallocated-use-rest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!