use of com.microsoft.azure.management.network.implementation.PublicIPAddressesInner in project photon-model by vmware.
the class AzureLoadBalancerService method createPublicIP.
/**
* Create a public IP in Azure if it is an internet facing load balancer
*
* @param context Azure load balancer context
* @return DeferredResult
*/
private DeferredResult<AzureLoadBalancerContext> createPublicIP(AzureLoadBalancerContext context) {
if (!context.loadBalancerStateExpanded.internetFacing) {
return DeferredResult.completed(context);
}
PublicIPAddressesInner azurePublicIPAddressClient = context.azureSdkClients.getNetworkManagementClientImpl().publicIPAddresses();
PublicIPAddressInner publicIPAddress = buildPublicIPAddress(context);
String publicIPName = String.format("%s-pip", context.loadBalancerStateExpanded.name);
final String msg = "Creating Public IP Address [" + publicIPName + "] for Azure Load Balancer [" + context.loadBalancerStateExpanded.name + "].";
logInfo(() -> msg);
AzureProvisioningCallback<PublicIPAddressInner> handler = new AzureProvisioningCallback<PublicIPAddressInner>(this, msg) {
@Override
protected DeferredResult<PublicIPAddressInner> consumeProvisioningSuccess(PublicIPAddressInner publicIPAddress) {
context.publicIPAddressInner = publicIPAddress;
return DeferredResult.completed(publicIPAddress);
}
@Override
protected String getProvisioningState(PublicIPAddressInner loadBalancer) {
return loadBalancer.provisioningState();
}
@Override
protected Runnable checkProvisioningStateCall(ServiceCallback<PublicIPAddressInner> checkProvisioningStateCallback) {
return () -> azurePublicIPAddressClient.getByResourceGroupAsync(context.resourceGroupName, publicIPName, null, /* expand */
checkProvisioningStateCallback);
}
};
azurePublicIPAddressClient.createOrUpdateAsync(context.resourceGroupName, publicIPName, publicIPAddress, handler);
return handler.toDeferredResult().thenApply(ignore -> context);
}
use of com.microsoft.azure.management.network.implementation.PublicIPAddressesInner in project photon-model by vmware.
the class AzureInstanceService method createPublicIPs.
private void createPublicIPs(AzureInstanceContext ctx, AzureInstanceStage nextStage) {
if (ctx.nics.isEmpty()) {
handleAllocation(ctx, nextStage);
return;
}
AzureNicContext nicCtx = ctx.getPrimaryNic();
// For now if not specified default to TRUE!
if (nicCtx.nicStateWithDesc.description.assignPublicIpAddress == null) {
nicCtx.nicStateWithDesc.description.assignPublicIpAddress = Boolean.TRUE;
}
if (nicCtx.nicStateWithDesc.description.assignPublicIpAddress == Boolean.FALSE) {
// Do nothing in this method -> proceed to next stage.
handleAllocation(ctx, nextStage);
return;
}
PublicIPAddressesInner azureClient = getNetworkManagementClientImpl(ctx).publicIPAddresses();
final PublicIPAddressInner publicIPAddress = newAzurePublicIPAddress(ctx, nicCtx);
final String publicIPName = ctx.vmName + "-pip";
final String publicIPRGName = ctx.resourceGroup.name();
String msg = "Creating Azure Public IP [" + publicIPName + "] for [" + ctx.vmName + "] VM";
AzureProvisioningCallback<PublicIPAddressInner> handler = new AzureProvisioningCallback<PublicIPAddressInner>(this, msg) {
@Override
protected DeferredResult<PublicIPAddressInner> consumeProvisioningSuccess(PublicIPAddressInner publicIP) {
nicCtx.publicIP = publicIP;
return DeferredResult.completed(publicIP);
}
@Override
protected String getProvisioningState(PublicIPAddressInner publicIP) {
return publicIP.provisioningState();
}
@Override
protected Runnable checkProvisioningStateCall(ServiceCallback<PublicIPAddressInner> checkProvisioningStateCallback) {
return () -> azureClient.getByResourceGroupAsync(publicIPRGName, publicIPName, null, /* expand */
checkProvisioningStateCallback);
}
};
azureClient.createOrUpdateAsync(publicIPRGName, publicIPName, publicIPAddress, handler);
handler.toDeferredResult().thenApply(ignore -> ctx).whenComplete(thenAllocation(ctx, nextStage, NETWORK_NAMESPACE));
}
use of com.microsoft.azure.management.network.implementation.PublicIPAddressesInner in project photon-model by vmware.
the class AzureLoadBalancerService method deletePublicIP.
/**
* Delete Public IP address from Azure
*
* @param context Azure load balancer context
* @return DeferredResult
*/
private DeferredResult<AzureLoadBalancerContext> deletePublicIP(AzureLoadBalancerContext context) {
String rgName = context.resourceGroupName;
String publicIPName = String.format("%s-pip", context.loadBalancerStateExpanded.name);
PublicIPAddressesInner azurePublicIPAddressClient = context.azureSdkClients.getNetworkManagementClientImpl().publicIPAddresses();
final String msg = String.format("Deleting Azure Public IP [%s] in resource group [%s].", publicIPName, rgName);
AzureDeferredResultServiceCallback<Void> handler = createDeleteHandler(msg);
azurePublicIPAddressClient.deleteAsync(rgName, publicIPName, handler);
return handler.toDeferredResult().thenApply(ignore -> context);
}
Aggregations