简体   繁体   中英

How to get list of Azure classic virtual networks using java API

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM