Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List Azure Virtual Machines via REST API

Tags:

rest

azure

I am currently attempting to get a list of all of the Virtual Machines that I have running under a Windows Azure subscription programmatically. For this, I am attempting to use the Azure REST API (https://management.core.windows.net), and not use the power-shell cmdlets.

Using the cmdlets I can run 'Get-AzureVM' and get a listing of all of the VM's with ServiceName, Name, and Status without any modifications. The problem is that I cannot find anywhere in the documentation of how to list out the VMs via the API.

I have looked through the various Azure REST API's but have not been able to find anything. The documentation for VM REST API does not show or provide a list function.

Am I missing the fundamentals somewhere?

// Create the request.
            // https://management.core.windows.net/<subscription-id>/services/hostedservices
            requestUri = new Uri("https://management.core.windows.net/"
                                 + subscriptionId 
                                 + "/services/" 
                                 + operation);

This is what I am using for the base of the request. I can get a list of hosted services but not the Virtual Machines.

like image 270
maximumgeek Avatar asked May 22 '13 13:05

maximumgeek


People also ask

How do I get a list of VMs in Azure?

Once the Azure subscription is set, we can use the below command to retrieve the Azure VMs. To get the particular azure VM using CLI, we need to provide the VM name and resource group name. “az vm show” command finds the VM from the list using parameter -n (VMName) -g (resource group Name).

Is there a console for Azure VMs?

Serial Console in the Azure portal provides access to a text-based console for virtual machines (VMs) and virtual machine scale set instances running either Linux or Windows.


2 Answers

You can use Azure node SDK to list out all VMs in your subscription

computeClient.virtualMachines.listAll(function (err, result))

More details on Azure Node SDK here: https://github.com/Azure-Samples/compute-node-manage-vm

like image 168
Karishma Tiwari - MSFT Avatar answered Nov 14 '22 07:11

Karishma Tiwari - MSFT


You would need to get a list all the Cloud Services (Hosted Services), and then the deployment properties for each. Look for the deployment in the Production environment/slot. Then check for a role type of "PersistentVMRole".

VMs are really just a type of Cloud Service, along with Web and Worker roles. The Windows Azure management portal and PowerShell cmdlets abstracts this away to make things a little easier to understand and view.

like image 41
mcollier Avatar answered Nov 14 '22 07:11

mcollier