1
votes

I am developing an application that tries to fetch as much information out of Azure as possible. Is there any way using the Java SDK to get a list of the Virtual Machines I have?

2

2 Answers

0
votes

In order to list Virtual Machines in your subscription, you would need to perform Service Management REST API Operations. I briefly looked at Azure SDK for Java on Github and I don't think the API is implemented there. I only saw support for Storage, Media Services and Service Bus. What that means is that you would need to write some code yourself which consumes this REST API.

1
votes

The current version of azure java sdk supports listing virtual machines. You need to import following packages

group: 'com.microsoft.azure', name: 'azure', version: '1.12.0'
group: 'commons-net', name: 'commons-net', version: '3.3'
group: 'com.microsoft.azure', name: 'azure-storage', version: '8.0.0'

Then authenticate with client id and client secret

ApplicationTokenCredentials credentials = new ApplicationTokenCredentials('<client id>', '<tenant id>', '<client secret>', AzureEnvironment.AZURE);
Azure azure = Azure.authenticate(credentials).withSubscription('SubscriptionGuid');

Then use the following code to list virtual machines

PagedList<VirtualMachine> vms = azure.virtualMachines().list();