0
votes

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
Consider posting version numbers - the "latest Java SDK" will change with time.user3486184
I am using the SDK version - 1.1.2 ie, 'com.microsoft.azure:azure:1.1.2'Ilangathir NM

1 Answers

0
votes

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.