I am using Java SDK to collect the Azure Virutal Machines. However I am not able to figure out the vnet/subnet associated with the VM. The SDK doesn't provide this info directly and the REST API as well.
Asked
Active
Viewed 470 times
0
-
The SDK will not show the vnet/subnet information if you just get the VM through the SDK. – Charles Xu May 30 '19 at 06:13
-
Thats exactly my problem.. How could we get that info? I am trying to get the vnet/subnet info through network interface but its not working.. – Anil Chandran May 30 '19 at 14:16
2 Answers
0
I finally figure it out and posting the answer . We need to get it from the Primary IP Configuration associated with the primary network interface. Please let me know if anyone has a better solution.
NicIPConfiguration ipConfiguration = virtualMachine.getPrimaryNetworkInterface().primaryIPConfiguration();
String vnet = ipConfiguration.networkId();
String subnet = ipConfiguration.subnetName();

Anil Chandran
- 11
- 5
0
To get the VNet and Subnet name associated with the VM
String vNet = virtualmachine.getPrimaryNetworkInterface().primaryIPConfiguration().getNetwork().name();
String subnet = virtualmachine.getPrimaryNetworkInterface().primaryIPConfiguration().subnetName();

slfan
- 8,950
- 115
- 65
- 78