use of com.microsoft.azure.management.network.implementation.PublicIPAddressInner in project photon-model by vmware.
the class AzureInstanceService method newAzurePublicIPAddress.
/**
* Converts Photon model constructs to underlying Azure PublicIPAddress model.
*/
private PublicIPAddressInner newAzurePublicIPAddress(AzureInstanceContext ctx, AzureNicContext nicCtx) {
PublicIPAddressInner publicIPAddress = new PublicIPAddressInner();
publicIPAddress.withLocation(ctx.resourceGroup.location());
publicIPAddress.withPublicIPAllocationMethod(new IPAllocationMethod(nicCtx.nicStateWithDesc.description.assignment.name()));
return publicIPAddress;
}
use of com.microsoft.azure.management.network.implementation.PublicIPAddressInner in project photon-model by vmware.
the class AzureInstanceService method getPublicIPAddress.
private DeferredResult<AzureInstanceContext> getPublicIPAddress(AzureInstanceContext ctx) {
if (ctx.getPrimaryNic().publicIP == null) {
// No public IP address created -> do nothing.
return DeferredResult.completed(ctx);
}
NetworkManagementClientImpl client = getNetworkManagementClientImpl(ctx);
String msg = "Get public IP address for resource group [" + ctx.resourceGroup.name() + "] and name [" + ctx.getPrimaryNic().publicIP.name() + "].";
AzureDeferredResultServiceCallback<PublicIPAddressInner> callback = new AzureDeferredResultServiceCallback<PublicIPAddressInner>(ctx.service, msg) {
@Override
protected DeferredResult<PublicIPAddressInner> consumeSuccess(PublicIPAddressInner result) {
ctx.getPrimaryNic().publicIP = result;
return DeferredResult.completed(result);
}
};
client.publicIPAddresses().getByResourceGroupAsync(ctx.resourceGroup.name(), ctx.getPrimaryNic().publicIP.name(), null, /* expand */
callback);
return callback.toDeferredResult().thenApply(ignored -> ctx);
}
use of com.microsoft.azure.management.network.implementation.PublicIPAddressInner 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.PublicIPAddressInner in project photon-model by vmware.
the class AzureLoadBalancerService method buildPublicIPAddress.
/**
* Build Azure PublicIPAddress model
*
* @param context Azure load balancer context
* @return PublicIPAddressInner
*/
private PublicIPAddressInner buildPublicIPAddress(AzureLoadBalancerContext context) {
PublicIPAddressInner publicIPAddress = new PublicIPAddressInner();
publicIPAddress.withLocation(context.loadBalancerStateExpanded.regionId);
publicIPAddress.withPublicIPAllocationMethod(IPAllocationMethod.DYNAMIC);
return publicIPAddress;
}
use of com.microsoft.azure.management.network.implementation.PublicIPAddressInner 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));
}
Aggregations