2
votes

I am using ARM in Azure.

Azure provides a REST API to get a list of virtual machines.

https://msdn.microsoft.com/en-us/library/azure/mt163572.aspx

Strangely the response data does not seem to provide the state of those machines. Am I looking in the wrong place?

I need to be able to get a list of all virtual machines and carry out actions on them depending on whether or not they are running or stopped etc.

1

1 Answers

3
votes

You could use https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/Microsoft.Compute/virtualMachines/{vm-name}/InstanceView?api-version={api-version} to get vm status from its response. For details please look at Get information about a virtual machine.

{
  ...
  ...
  "statuses": [
    {
      "code": "ProvisioningState/succeeded",
      "level": "Info",
      "displayStatus": "Provisioning succeeded",
      "time": "2015-04-10T12:50:09.0031588-07:00"
    },
    {
      "code": "PowerState/running",
      "level": "Info",
      "displayStatus": "VM running"
    }
  ]
}