0
votes

i've deployed a vm using Resource Manager deployment model.

Using rest api as described here: https://msdn.microsoft.com/en-us/library/azure/mt163682.aspx i'm able to get informations about my VM. But i cannot see if the VM is running or not. I want that information to start/stop the VM Automatically via code.

Does anyone have tried that and get the VM powerstate?

best regards...

i make a GET using this URI

string.Format("https://management.azure.com/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Compute/virtualMachines/{2}?api-version={3}", subscriptionID, resssourcegroup, vmname,apiversion);

apiversion is 2016-03-30.

3
My bad , i needed to use the second uri to get information about the instance view of a virtual machine. How to make it resolved?Oumar Diarra
It would be good if you could put that as an answer to help anyone else who comes here with the same problemMichael B
A small hint: since the new .Net Framework, you are able to do such string formattings without String.Format. You can do it in a more intuitive way. You just need it to like this: string foo = $"This is my {number}. String in a row of {totalNumber} Strings"; There you can easily use your variables in the string and it's more readable.wuerzelchen
@MichaelB-AzureMVP still looking how to make it as an answer.Oumar Diarra
@wuerzelchen thank you for tip.Oumar Diarra

3 Answers

1
votes

The API call for this information is:

https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/Microsoft.Compute/virtualMachines/{vm-name}/InstanceView?api-version={api-version}
0
votes

Needed to use the second request uri "Get information about the instance view of a virtual machine" from the following url https://msdn.microsoft.com/en-us/library/azure/mt163682.aspx to get the instance powerstate.

Thank you.

0
votes

This is the link to the documentation where you can see the Status of the VM: https://docs.microsoft.com/en-us/rest/api/compute/virtual-machines/instance-view?tabs=HTTP

This is an example of the output

"statuses": [
    {
        "code": "ProvisioningState/succeeded",
        "level": "Info",
        "displayStatus": "Provisioning succeeded",
        "time": "2022-07-25T02:12:52.7726725+00:00"
    },
    {
        "code": "PowerState/running",
        "level": "Info",
        "displayStatus": "VM running"
    }
]