0

I am working on a small project to list all the VirtualNetworks details under a subscription. In our subscription we have both classic and ARM Virtual networks. I am using Azure latest Java SDK(1.1.2) to pull the info. I am using the below API call and it is returning only the VNets from ARM, not from classic. Please see the code snippet.

ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(
                clientId, tenantId, clientKey, AzureEnvironment.AZURE);
        Azure azure = Azure.authenticate(credentials).withSubscription(subscriptionId);
for (Network virtualNetwork : azure.networks().list()){
            Utils.print(virtualNetwork);
        }

How can I get both ARM and classic VNets?

1 Answers1

0

The APIs of ASM (Azure Service Management) support the feature for listing the classic Virtual Networks.

There are two ways as below.

  1. Using Azure Java SDK for ASM, you can install it via maven repositories azure-svc-mgmt & azure-svc-mgmt-network, and follow the blog to authenticate for NetworkManagementService to create an instance of NetworkManagementClient to getNetworksOperations() to list() the NetworkListResponse.

  2. Via the ASM REST API List Virtual Network Sites to get the XML response, and refer to the reference Authenticating Service Management Requests, Service to service calls using client credentials (shared secret or certificate) & Create the request to create an authenticated request to call the REST API.

Meanwhile, you also can refer to these similar SO thread for ASM as below.

  1. Azure retrieving the PublicIPAddress of VirtualMachines from Azure Java SDK
  2. MS Azure java client code throws the error

Hope it helps.

Peter Pan
  • 23,476
  • 4
  • 25
  • 43
  • Thanks for your quick response. So, I have to use two different SDKs so two different APIs to pull the information. The worst part is that the authentication procedure is also different. We cannot ask our customer to do two different things to pull the information. I think the better option is to implement the plain REST java client to pull the information. – Ilangathir NM Jul 27 '17 at 20:50