Search in sources :

Example 1 with DiskSkuTypes

use of com.microsoft.azure.management.compute.DiskSkuTypes 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);
}
Also used : StorageAccountTypes(com.microsoft.azure.management.compute.StorageAccountTypes) ServiceCallback(com.microsoft.rest.ServiceCallback) DiskSkuTypes(com.microsoft.azure.management.compute.DiskSkuTypes) Disk(com.microsoft.azure.management.compute.Disk) AzureProvisioningCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureProvisioningCallback)

Aggregations

Disk (com.microsoft.azure.management.compute.Disk)1 DiskSkuTypes (com.microsoft.azure.management.compute.DiskSkuTypes)1 StorageAccountTypes (com.microsoft.azure.management.compute.StorageAccountTypes)1 ServiceCallback (com.microsoft.rest.ServiceCallback)1 AzureProvisioningCallback (com.vmware.photon.controller.model.adapters.azure.utils.AzureProvisioningCallback)1