use of com.vmware.photon.controller.model.adapters.azure.utils.AzureProvisioningCallback in project photon-model by vmware.
the class AzureSubnetService method createSubnet.
private DeferredResult<AzureSubnetContext> createSubnet(AzureSubnetContext context) {
SubnetInner subnet = new SubnetInner();
subnet.withName(context.subnetState.name);
subnet.withAddressPrefix(context.subnetState.subnetCIDR);
String rgName = context.parentNetworkResourceGroupName;
String vNetName = context.parentNetwork.name;
final String msg = "Creating Azure Subnet [" + subnet.name() + "] in vNet [" + vNetName + "] in resource group [" + rgName + "].";
SubnetsInner subnetsInner = context.azureSdkClients.getNetworkManagementClientImpl().subnets();
AzureProvisioningCallback<SubnetInner> handler = new AzureProvisioningCallback<SubnetInner>(this, msg) {
@Override
protected DeferredResult<SubnetInner> consumeProvisioningSuccess(SubnetInner subnet) {
// Populate the subnet id with Azure Subnet ID
context.subnetState.id = subnet.id();
return DeferredResult.completed(subnet);
}
@Override
protected String getProvisioningState(SubnetInner subnet) {
return subnet.provisioningState();
}
@Override
protected Runnable checkProvisioningStateCall(ServiceCallback<SubnetInner> checkProvisioningStateCallback) {
return () -> subnetsInner.getAsync(rgName, vNetName, subnet.name(), null, /* expand */
checkProvisioningStateCallback);
}
};
subnetsInner.createOrUpdateAsync(rgName, vNetName, subnet.name(), subnet, handler);
return handler.toDeferredResult().thenApply(ignore -> context);
}
use of com.vmware.photon.controller.model.adapters.azure.utils.AzureProvisioningCallback in project photon-model by vmware.
the class AzureDiskService method createDisk.
/**
* Method to define the data disk to be created. We also specify to handle call backs from Azure
*/
private DeferredResult<AzureDiskContext> createDisk(AzureDiskContext context) {
// If ResourceGroupName is not given choose one randomly
if (context.diskState.customProperties != null && context.diskState.customProperties.containsKey(AzureConstants.AZURE_RESOURCE_GROUP_NAME)) {
context.resourceGroupName = context.diskState.customProperties.get(AzureConstants.AZURE_RESOURCE_GROUP_NAME);
} else {
context.resourceGroupName = SdkContext.randomResourceName(PREFIX_OF_RESOURCE_GROUP_FOR_DISK, PREFIX_OF_RESOURCE_GROUP_FOR_DISK.length() + 5);
}
StorageAccountTypes accountType = StorageAccountTypes.STANDARD_LRS;
if (context.diskState.customProperties != null && context.diskState.customProperties.containsKey(AzureConstants.AZURE_MANAGED_DISK_TYPE)) {
accountType = StorageAccountTypes.fromString(context.diskState.customProperties.get(AzureConstants.AZURE_MANAGED_DISK_TYPE));
}
Disk.DefinitionStages.WithGroup basicDiskDefinition = context.azureSdkClients.getComputeManager().disks().define(context.diskState.name).withRegion(context.diskState.regionId);
Disk.DefinitionStages.WithDiskSource diskDefinitionIncludingResourceGroup;
// Create new resource group or resuse existing one
if (context.diskState.customProperties != null && context.diskState.customProperties.containsKey(AzureConstants.AZURE_RESOURCE_GROUP_NAME)) {
diskDefinitionIncludingResourceGroup = basicDiskDefinition.withExistingResourceGroup(context.resourceGroupName);
} else {
diskDefinitionIncludingResourceGroup = basicDiskDefinition.withNewResourceGroup(context.resourceGroupName);
}
final String msg = "Creating new independent disk with name [" + context.diskState.name + "]";
AzureProvisioningCallback<Disk> handler = new AzureProvisioningCallback<Disk>(this, msg) {
@Override
protected DeferredResult<Disk> consumeProvisioningSuccess(Disk disk) {
// Populate the disk state with disk id.
context.diskState.id = disk.id();
return DeferredResult.completed(disk);
}
@Override
protected String getProvisioningState(Disk disk) {
return disk.inner().provisioningState();
}
@Override
protected Runnable checkProvisioningStateCall(ServiceCallback<Disk> checkProvisioningStateCallback) {
return () -> context.azureSdkClients.getComputeManager().disks().getByResourceGroupAsync(context.resourceGroupName, context.diskState.name, checkProvisioningStateCallback);
}
};
diskDefinitionIncludingResourceGroup.withData().withSizeInGB((int) context.diskState.capacityMBytes / 1024).withSku(new DiskSkuTypes(accountType)).createAsync(handler);
return handler.toDeferredResult().thenApply(ignore -> context);
}
use of com.vmware.photon.controller.model.adapters.azure.utils.AzureProvisioningCallback 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.vmware.photon.controller.model.adapters.azure.utils.AzureProvisioningCallback in project photon-model by vmware.
the class AzureLoadBalancerService method createOrUpdateLoadBalancer.
/**
* Create or update load balancer in Azure
*
* @param context Azure load balancer context
* @param msg message to log
* @return DeferredResult
*/
private DeferredResult<LoadBalancerInner> createOrUpdateLoadBalancer(AzureLoadBalancerContext context, String msg) {
LoadBalancersInner azureLoadBalancerClient = context.azureSdkClients.getNetworkManagementClientImpl().loadBalancers();
logInfo(() -> msg);
AzureProvisioningCallback<LoadBalancerInner> handler = new AzureProvisioningCallback<LoadBalancerInner>(this, msg) {
@Override
protected DeferredResult<LoadBalancerInner> consumeProvisioningSuccess(LoadBalancerInner loadBalancer) {
// Populate the load balancer id with Azure Load Balancer ID
context.loadBalancerStateExpanded.id = loadBalancer.id();
return DeferredResult.completed(loadBalancer);
}
@Override
protected String getProvisioningState(LoadBalancerInner loadBalancer) {
return loadBalancer.provisioningState();
}
@Override
protected Runnable checkProvisioningStateCall(ServiceCallback<LoadBalancerInner> checkProvisioningStateCallback) {
return () -> azureLoadBalancerClient.getByResourceGroupAsync(context.resourceGroupName, context.loadBalancerAzure.name(), null, /* expand */
checkProvisioningStateCallback);
}
};
azureLoadBalancerClient.createOrUpdateAsync(context.resourceGroupName, context.loadBalancerStateExpanded.name, context.loadBalancerAzure, handler);
return handler.toDeferredResult();
}
use of com.vmware.photon.controller.model.adapters.azure.utils.AzureProvisioningCallback 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