use of com.microsoft.azure.management.network.implementation.NetworkInterfacesInner in project photon-model by vmware.
the class AzureComputeEnumerationAdapterService method createNetworkInterfaceStates.
/**
* Create network interface states for each VM
*/
private void createNetworkInterfaceStates(EnumerationContext ctx, ComputeEnumerationSubStages next) {
Consumer<Throwable> failure = e -> {
logWarning("Failure getting Azure network interface states [endpointLink:%s] [Exception:%s]", ctx.request.endpointLink, e.getMessage());
handleError(ctx, e);
};
PhotonModelUtils.runInExecutor(this.executorService, () -> {
Azure azureClient = ctx.azureSdkClients.getAzureClient();
NetworkInterfacesInner netOps = azureClient.networkInterfaces().inner();
List<DeferredResult<Pair<NetworkInterfaceInner, String>>> remoteNics = ctx.virtualMachines.values().stream().filter(vm -> vm.networkProfile() != null && !vm.networkProfile().networkInterfaces().isEmpty()).flatMap(vm -> vm.networkProfile().networkInterfaces().stream().map(nic -> Pair.of(nic, vm.id()))).map(pair -> loadRemoteNic(pair, netOps)).collect(Collectors.toList());
DeferredResult.allOf(remoteNics).thenCompose(rnics -> loadSubnets(ctx, rnics).thenCompose(subnetPerNicId -> doCreateUpdateNics(ctx, subnetPerNicId, rnics))).whenComplete(thenHandleSubStage(ctx, next));
}, failure);
}
use of com.microsoft.azure.management.network.implementation.NetworkInterfacesInner in project photon-model by vmware.
the class AzureInstanceService method createNICs.
private void createNICs(AzureInstanceContext ctx, AzureInstanceStage nextStage) {
if (ctx.nics.isEmpty()) {
handleAllocation(ctx, nextStage);
return;
}
// Shared state between multi async calls {{
AzureCallContext callContext = AzureCallContext.newBatchCallContext(ctx.nics.size());
NetworkInterfacesInner azureClient = getNetworkManagementClientImpl(ctx).networkInterfaces();
for (AzureNicContext nicCtx : ctx.nics) {
final String nicName = nicCtx.nicStateWithDesc.name;
final NetworkInterfaceInner nic = newAzureNetworkInterface(ctx, nicCtx);
String msg = "Creating Azure NIC [" + nicName + "] for [" + ctx.vmName + "] VM";
azureClient.createOrUpdateAsync(ctx.resourceGroup.name(), nicName, nic, new TransitionToCallback<NetworkInterfaceInner>(ctx, nextStage, callContext, msg) {
@Override
protected CompletionStage<NetworkInterfaceInner> handleSuccess(NetworkInterfaceInner nic) {
nicCtx.nic = nic;
return CompletableFuture.completedFuture(nic);
}
});
}
}
use of com.microsoft.azure.management.network.implementation.NetworkInterfacesInner in project photon-model by vmware.
the class AzureLoadBalancerService method getNetworkInterfaceInner.
/**
* Fetch single Network Interface from Azure
*
* @param context Azure load balancer context
* @param networkInterfaceState state of the network interface to be fetched from Azure
* @return DeferredResult
*/
private DeferredResult<NetworkInterfaceInner> getNetworkInterfaceInner(AzureLoadBalancerContext context, NetworkInterfaceState networkInterfaceState) {
String networkInterfaceResGrp = AzureUtils.getResourceGroupName(networkInterfaceState.id);
final String msg = "Getting network Interface [" + networkInterfaceState.name + "] in resource group [" + networkInterfaceResGrp + "].";
logInfo(() -> msg);
AzureDeferredResultServiceCallback<NetworkInterfaceInner> callback = new AzureDeferredResultServiceCallback<NetworkInterfaceInner>(this, msg) {
@Override
protected DeferredResult<NetworkInterfaceInner> consumeSuccess(NetworkInterfaceInner networkInterface) {
if (networkInterface == null) {
logWarning("Failed to get information for network interface: %s", networkInterfaceState.name);
}
return DeferredResult.completed(networkInterface);
}
};
NetworkInterfacesInner azureNetworkInterfaceClient = context.azureSdkClients.getNetworkManagementClientImpl().networkInterfaces();
azureNetworkInterfaceClient.getByResourceGroupAsync(networkInterfaceResGrp, networkInterfaceState.name, null, /* expand */
callback);
return callback.toDeferredResult();
}
use of com.microsoft.azure.management.network.implementation.NetworkInterfacesInner in project photon-model by vmware.
the class AzureLoadBalancerService method createOrUpdateNetworkInterface.
/**
* Create or Update network interface in Azure
*
* @param context Azure load balancer context
* @param networkInterfaceInner Azure network interface construct
* @return DeferredResult
*/
private DeferredResult<NetworkInterfaceInner> createOrUpdateNetworkInterface(AzureLoadBalancerContext context, NetworkInterfaceInner networkInterfaceInner) {
String networkInterfaceResGrp = AzureUtils.getResourceGroupName(networkInterfaceInner.id());
final String msg = "Update network Interface [" + networkInterfaceInner.name() + "] in resource group [" + networkInterfaceResGrp + "].";
logInfo(() -> msg);
NetworkInterfacesInner azureNetworkInterfaceClient = context.azureSdkClients.getNetworkManagementClientImpl().networkInterfaces();
AzureProvisioningCallbackWithRetry<NetworkInterfaceInner> handler = new AzureProvisioningCallbackWithRetry<NetworkInterfaceInner>(this, msg) {
@Override
protected DeferredResult<NetworkInterfaceInner> consumeProvisioningSuccess(NetworkInterfaceInner networkInterfaceInner) {
return DeferredResult.completed(networkInterfaceInner);
}
@Override
protected Runnable checkProvisioningStateCall(ServiceCallback<NetworkInterfaceInner> checkProvisioningStateCallback) {
return () -> azureNetworkInterfaceClient.getByResourceGroupAsync(networkInterfaceResGrp, networkInterfaceInner.name(), null, /* expand */
checkProvisioningStateCallback);
}
@Override
protected String getProvisioningState(NetworkInterfaceInner body) {
return body.provisioningState();
}
@Override
protected Runnable retryServiceCall(ServiceCallback<NetworkInterfaceInner> retryCallback) {
return () -> azureNetworkInterfaceClient.createOrUpdateAsync(networkInterfaceResGrp, networkInterfaceInner.name(), networkInterfaceInner, retryCallback);
}
};
azureNetworkInterfaceClient.createOrUpdateAsync(networkInterfaceResGrp, networkInterfaceInner.name(), networkInterfaceInner, handler);
return handler.toDeferredResult();
}
Aggregations