1

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.

EthenHY
  • 551
  • 3
  • 9
  • 19

3 Answers3

5

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.

Neil Mackenzie
  • 2,817
  • 14
  • 11
  • Hi I tried fiddler, but it doesn't work for me, because the proxy request will get 403 forbidden issue, the cmdlet will first send a get reqeust to get vm information then send post request, if you use fiddler you can only get the get request, then will cause the 403 issue, does I get any thing wrong? – EthenHY Oct 08 '13 at 09:32
  • 1
    Yes use **x-ms-version: 2013-06-01** can resolve the problem, but I still want to know how to use fiddler as proxy but not get 403 fobidden – EthenHY Oct 08 '13 at 09:42
  • You put your Windows Azure authentication certificate into %USERPROFILE%\My Documents\Fiddler2\ClientCertificate.cer http://fiddler2.com/documentation/Configure-Fiddler/Tasks/RespondWithClientCert – Neil Mackenzie Oct 14 '13 at 21:35
  • I spent so many hours working on this, only to discover it is an undocumented api issue. Grr. – Daniel Compton Nov 04 '13 at 06:36
1
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>
ChiYuen
  • 41
  • 5
0
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);
}
Mariot
  • 266
  • 3
  • 2