use of com.vmware.photon.controller.model.adapters.azure.model.network.VirtualNetworkListResult in project photon-model by vmware.
the class AzureNetworkEnumerationAdapterService method getVirtualNetworks.
/**
* Retrieve a page of Virtual Network resources from azure, based on the provided compute host
* description.
*/
private void getVirtualNetworks(NetworkEnumContext context, NetworkEnumStages next) {
logFine(() -> "Enumerating Virtual Networks from Azure.");
URI uri;
if (context.enumNextPageLink == null) {
// First request to fetch Virtual Networks from Azure.
String uriStr = AdapterUriUtil.expandUriPathTemplate(LIST_VIRTUAL_NETWORKS_URI, context.endpointAuth.userLink);
uri = UriUtils.extendUriWithQuery(UriUtils.buildUri(uriStr), QUERY_PARAM_API_VERSION, NETWORK_REST_API_VERSION);
} else {
// Request to fetch next page of Virtual Networks from Azure.
uri = UriUtils.buildUri(context.enumNextPageLink);
}
final Operation operation = Operation.createGet(uri);
operation.addRequestHeader(Operation.ACCEPT_HEADER, Operation.MEDIA_TYPE_APPLICATION_JSON);
operation.addRequestHeader(Operation.CONTENT_TYPE_HEADER, Operation.MEDIA_TYPE_APPLICATION_JSON);
try {
operation.addRequestHeader(Operation.AUTHORIZATION_HEADER, AUTH_HEADER_BEARER_PREFIX + context.credentials.getToken(AzureUtils.getAzureBaseUri()));
} catch (Exception ex) {
handleError(context, ex);
return;
}
operation.setCompletion((op, ex) -> {
op.complete();
if (ex != null) {
handleError(context, ex);
return;
}
VirtualNetworkListResult results = op.getBody(VirtualNetworkListResult.class);
List<VirtualNetwork> virtualNetworks = results.value;
// If there are no Virtual Networks in Azure we directly skip over to deletion phase.
if (virtualNetworks == null || virtualNetworks.size() == 0) {
handleSubStage(context, NetworkEnumStages.DELETE_NETWORK_STATES);
return;
}
// Store next page link.
context.enumNextPageLink = results.nextLink;
logFine(() -> String.format("Retrieved %d Virtual Networks from Azure", virtualNetworks.size()));
logFine(() -> String.format("Next page link %s", context.enumNextPageLink));
// Store virtual networks for further processing during the next stages.
virtualNetworks.forEach(virtualNetwork -> {
context.addVirtualNetwork(virtualNetwork);
});
logFine(() -> String.format("Processing %d virtual networks", context.virtualNetworks.size()));
handleSubStage(context, next);
});
sendRequest(operation);
}
Aggregations