Search in sources :

Example 11 with DataDisk

use of com.microsoft.azure.management.compute.DataDisk in project azure-sdk-for-java by Azure.

the class TestUtils method print.

/**
     * Shows the virtual machine.
     * @param resource virtual machine to show
     */
public static void print(VirtualMachine resource) {
    StringBuilder storageProfile = new StringBuilder().append("\n\tStorageProfile: ");
    if (resource.storageProfile().imageReference() != null) {
        storageProfile.append("\n\t\tImageReference:");
        storageProfile.append("\n\t\t\tPublisher: ").append(resource.storageProfile().imageReference().publisher());
        storageProfile.append("\n\t\t\tOffer: ").append(resource.storageProfile().imageReference().offer());
        storageProfile.append("\n\t\t\tSKU: ").append(resource.storageProfile().imageReference().sku());
        storageProfile.append("\n\t\t\tVersion: ").append(resource.storageProfile().imageReference().version());
    }
    if (resource.storageProfile().osDisk() != null) {
        storageProfile.append("\n\t\tOSDisk:");
        storageProfile.append("\n\t\t\tOSType: ").append(resource.storageProfile().osDisk().osType());
        storageProfile.append("\n\t\t\tName: ").append(resource.storageProfile().osDisk().name());
        storageProfile.append("\n\t\t\tCaching: ").append(resource.storageProfile().osDisk().caching());
        storageProfile.append("\n\t\t\tCreateOption: ").append(resource.storageProfile().osDisk().createOption());
        storageProfile.append("\n\t\t\tDiskSizeGB: ").append(resource.storageProfile().osDisk().diskSizeGB());
        if (resource.storageProfile().osDisk().image() != null) {
            storageProfile.append("\n\t\t\tImage Uri: ").append(resource.storageProfile().osDisk().image().uri());
        }
        if (resource.storageProfile().osDisk().vhd() != null) {
            storageProfile.append("\n\t\t\tVhd Uri: ").append(resource.storageProfile().osDisk().vhd().uri());
        }
        if (resource.storageProfile().osDisk().encryptionSettings() != null) {
            storageProfile.append("\n\t\t\tEncryptionSettings: ");
            storageProfile.append("\n\t\t\t\tEnabled: ").append(resource.storageProfile().osDisk().encryptionSettings().enabled());
            storageProfile.append("\n\t\t\t\tDiskEncryptionKey Uri: ").append(resource.storageProfile().osDisk().encryptionSettings().diskEncryptionKey().secretUrl());
            storageProfile.append("\n\t\t\t\tKeyEncryptionKey Uri: ").append(resource.storageProfile().osDisk().encryptionSettings().keyEncryptionKey().keyUrl());
        }
    }
    if (resource.storageProfile().dataDisks() != null) {
        int i = 0;
        for (DataDisk disk : resource.storageProfile().dataDisks()) {
            storageProfile.append("\n\t\tDataDisk: #").append(i++);
            storageProfile.append("\n\t\t\tName: ").append(disk.name());
            storageProfile.append("\n\t\t\tCaching: ").append(disk.caching());
            storageProfile.append("\n\t\t\tCreateOption: ").append(disk.createOption());
            storageProfile.append("\n\t\t\tDiskSizeGB: ").append(disk.diskSizeGB());
            storageProfile.append("\n\t\t\tLun: ").append(disk.lun());
            if (resource.isManagedDiskEnabled()) {
                if (disk.managedDisk() != null) {
                    storageProfile.append("\n\t\t\tManaged Disk Id: ").append(disk.managedDisk().id());
                }
            } else {
                if (disk.vhd().uri() != null) {
                    storageProfile.append("\n\t\t\tVhd Uri: ").append(disk.vhd().uri());
                }
            }
            if (disk.image() != null) {
                storageProfile.append("\n\t\t\tImage Uri: ").append(disk.image().uri());
            }
        }
    }
    StringBuilder osProfile = new StringBuilder().append("\n\tOSProfile: ");
    osProfile.append("\n\t\tComputerName:").append(resource.osProfile().computerName());
    if (resource.osProfile().windowsConfiguration() != null) {
        osProfile.append("\n\t\t\tWindowsConfiguration: ");
        osProfile.append("\n\t\t\t\tProvisionVMAgent: ").append(resource.osProfile().windowsConfiguration().provisionVMAgent());
        osProfile.append("\n\t\t\t\tEnableAutomaticUpdates: ").append(resource.osProfile().windowsConfiguration().enableAutomaticUpdates());
        osProfile.append("\n\t\t\t\tTimeZone: ").append(resource.osProfile().windowsConfiguration().timeZone());
    }
    if (resource.osProfile().linuxConfiguration() != null) {
        osProfile.append("\n\t\t\tLinuxConfiguration: ");
        osProfile.append("\n\t\t\t\tDisablePasswordAuthentication: ").append(resource.osProfile().linuxConfiguration().disablePasswordAuthentication());
    }
    StringBuilder networkProfile = new StringBuilder().append("\n\tNetworkProfile: ");
    for (String networkInterfaceId : resource.networkInterfaceIds()) {
        networkProfile.append("\n\t\tId:").append(networkInterfaceId);
    }
    System.out.println(new StringBuilder().append("Virtual Machine: ").append(resource.id()).append("Name: ").append(resource.name()).append("\n\tResource group: ").append(resource.resourceGroupName()).append("\n\tRegion: ").append(resource.region()).append("\n\tTags: ").append(resource.tags()).append("\n\tHardwareProfile: ").append("\n\t\tSize: ").append(resource.size()).append(storageProfile).append(osProfile).append(networkProfile).toString());
}
Also used : DataDisk(com.microsoft.azure.management.compute.DataDisk)

Example 12 with DataDisk

use of com.microsoft.azure.management.compute.DataDisk in project azure-sdk-for-java by Azure.

the class VirtualMachineImpl method withNewDataDisk.

@Override
public VirtualMachineImpl withNewDataDisk(Creatable<Disk> creatable, int lun, CachingTypes cachingType) {
    throwIfManagedDiskDisabled(ManagedUnmanagedDiskErrors.VM_BOTH_UNMANAGED_AND_MANAGED_DISK_NOT_ALLOWED);
    addCreatableDependency(creatable);
    this.managedDataDisks.newDisksToAttach.put(creatable.key(), new DataDisk().withLun(lun).withCaching(cachingType));
    return this;
}
Also used : VirtualMachineUnmanagedDataDisk(com.microsoft.azure.management.compute.VirtualMachineUnmanagedDataDisk) VirtualMachineDataDisk(com.microsoft.azure.management.compute.VirtualMachineDataDisk) DataDisk(com.microsoft.azure.management.compute.DataDisk)

Example 13 with DataDisk

use of com.microsoft.azure.management.compute.DataDisk in project azure-sdk-for-java by Azure.

the class VirtualMachineImpl method withNewDataDisk.

@Override
public VirtualMachineImpl withNewDataDisk(int sizeInGB, int lun, CachingTypes cachingType, StorageAccountTypes storageAccountType) {
    throwIfManagedDiskDisabled(ManagedUnmanagedDiskErrors.VM_BOTH_UNMANAGED_AND_MANAGED_DISK_NOT_ALLOWED);
    ManagedDiskParametersInner managedDiskParameters = new ManagedDiskParametersInner();
    managedDiskParameters.withStorageAccountType(storageAccountType);
    this.managedDataDisks.implicitDisksToAssociate.add(new DataDisk().withLun(lun).withDiskSizeGB(sizeInGB).withCaching(cachingType).withManagedDisk(managedDiskParameters));
    return this;
}
Also used : VirtualMachineUnmanagedDataDisk(com.microsoft.azure.management.compute.VirtualMachineUnmanagedDataDisk) VirtualMachineDataDisk(com.microsoft.azure.management.compute.VirtualMachineDataDisk) DataDisk(com.microsoft.azure.management.compute.DataDisk)

Example 14 with DataDisk

use of com.microsoft.azure.management.compute.DataDisk in project photon-model by vmware.

the class AzureInstanceService method createVM.

private void createVM(AzureInstanceContext ctx, AzureInstanceStage nextStage) {
    ComputeDescriptionService.ComputeDescription description = ctx.child.description;
    Map<String, String> customProperties = description.customProperties;
    if (customProperties == null) {
        handleError(ctx, new IllegalStateException("Custom properties not specified"));
        return;
    }
    // DiskService.DiskStateExpanded bootDisk = ctx.bootDiskState;
    if (ctx.bootDiskState == null) {
        handleError(ctx, new IllegalStateException("Azure bootDisk not specified"));
        return;
    }
    String cloudConfig = null;
    if (ctx.bootDiskState.bootConfig != null && ctx.bootDiskState.bootConfig.files.length > CLOUD_CONFIG_DEFAULT_FILE_INDEX) {
        cloudConfig = ctx.bootDiskState.bootConfig.files[CLOUD_CONFIG_DEFAULT_FILE_INDEX].contents;
    }
    VirtualMachineInner request = new VirtualMachineInner();
    request.withLocation(ctx.resourceGroup.location());
    SubResource availabilitySetSubResource = new SubResource().withId(ctx.availabilitySet.id());
    request.withAvailabilitySet(availabilitySetSubResource);
    // Set OS profile.
    OSProfile osProfile = new OSProfile();
    osProfile.withComputerName(ctx.vmName);
    if (ctx.childAuth != null) {
        osProfile.withAdminUsername(ctx.childAuth.userEmail);
        osProfile.withAdminPassword(EncryptionUtils.decrypt(ctx.childAuth.privateKey));
    }
    if (cloudConfig != null) {
        try {
            osProfile.withCustomData(Base64.getEncoder().encodeToString(cloudConfig.getBytes(Utils.CHARSET)));
        } catch (UnsupportedEncodingException e) {
            logWarning(() -> "Error encoding user data");
            return;
        }
    }
    request.withOsProfile(osProfile);
    // Set hardware profile.
    HardwareProfile hardwareProfile = new HardwareProfile();
    hardwareProfile.withVmSize(description.instanceType != null ? VirtualMachineSizeTypes.fromString(description.instanceType) : VirtualMachineSizeTypes.BASIC_A0);
    request.withHardwareProfile(hardwareProfile);
    // Set storage profile.
    // Create destination OS VHD
    final OSDisk osDisk = newAzureOsDisk(ctx);
    final StorageProfile storageProfile = new StorageProfile();
    storageProfile.withOsDisk(osDisk);
    List<DataDisk> dataDisks = new ArrayList<>();
    List<Integer> LUNsOnImage = new ArrayList<>();
    storageProfile.withImageReference(ctx.imageSource.asImageReferenceInner());
    if (ctx.imageSource.type == ImageSource.Type.PRIVATE_IMAGE) {
        // set LUNs of data disks present on the custom image.
        final ImageState imageState = ctx.imageSource.asImageState();
        if (imageState != null && imageState.diskConfigs != null) {
            for (DiskConfiguration diskConfig : imageState.diskConfigs) {
                if (diskConfig.properties != null && diskConfig.properties.containsKey(AzureConstants.AZURE_DISK_LUN)) {
                    DataDisk imageDataDisk = new DataDisk();
                    int lun = Integer.parseInt(diskConfig.properties.get(AzureConstants.AZURE_DISK_LUN));
                    LUNsOnImage.add(lun);
                    imageDataDisk.withLun(lun);
                    imageDataDisk.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE);
                    dataDisks.add(imageDataDisk);
                }
            }
        }
        String dataDiskCaching = ctx.bootDiskState.customProperties.get(AZURE_DATA_DISK_CACHING);
        if (dataDiskCaching != null) {
            dataDisks.stream().forEach(dataDisk -> dataDisk.withCaching(CachingTypes.fromString(dataDiskCaching)));
        }
        String diskType = ctx.bootDiskState.customProperties.get(AZURE_MANAGED_DISK_TYPE);
        if (diskType != null) {
            ManagedDiskParametersInner managedDiskParams = new ManagedDiskParametersInner();
            managedDiskParams.withStorageAccountType(StorageAccountTypes.fromString(diskType));
            dataDisks.stream().forEach(dataDisk -> dataDisk.withManagedDisk(managedDiskParams));
        }
    }
    // choose LUN greater than the one specified in case of custom image. Else start from zero.
    int LUNForAdditionalDisk = LUNsOnImage.size() == 0 ? 0 : Collections.max(LUNsOnImage) + 1;
    dataDisks.addAll(newAzureDataDisks(ctx, LUNForAdditionalDisk));
    storageProfile.withDataDisks(dataDisks);
    request.withStorageProfile(storageProfile);
    // Set network profile {{
    NetworkProfile networkProfile = new NetworkProfile();
    networkProfile.withNetworkInterfaces(new ArrayList<>());
    for (AzureNicContext nicCtx : ctx.nics) {
        NetworkInterfaceReferenceInner nicRef = new NetworkInterfaceReferenceInner();
        nicRef.withId(nicCtx.nic.id());
        // NOTE: First NIC is marked as Primary.
        nicRef.withPrimary(networkProfile.networkInterfaces().isEmpty());
        networkProfile.networkInterfaces().add(nicRef);
    }
    request.withNetworkProfile(networkProfile);
    logFine(() -> String.format("Creating virtual machine with name [%s]", ctx.vmName));
    AzureAsyncCallback<VirtualMachineInner> callback = new AzureAsyncCallback<VirtualMachineInner>() {

        @Override
        public void onError(Throwable e) {
            // exception and try again with a shorter name
            if (isIncorrectNameLength(e)) {
                request.osProfile().withComputerName(generateWindowsComputerName(ctx.vmName));
                getComputeManagementClientImpl(ctx).virtualMachines().createOrUpdateAsync(ctx.resourceGroup.name(), ctx.vmName, request, this);
                return;
            }
            handleCloudError(String.format("Provisioning VM %s: FAILED. Details:", ctx.vmName), ctx, COMPUTE_NAMESPACE, e);
        }

        // Cannot tell for sure, but these checks should be enough
        private boolean isIncorrectNameLength(Throwable e) {
            if (e instanceof CloudException) {
                CloudException ce = (CloudException) e;
                CloudError body = ce.body();
                if (body != null) {
                    String code = body.code();
                    String target = body.target();
                    return INVALID_PARAMETER.equals(code) && COMPUTER_NAME.equals(target) && request.osProfile().computerName().length() > WINDOWS_COMPUTER_NAME_MAX_LENGTH && body.message().toLowerCase().contains("windows");
                }
            }
            return false;
        }

        private String generateWindowsComputerName(String vmName) {
            String computerName = vmName;
            if (vmName.length() > WINDOWS_COMPUTER_NAME_MAX_LENGTH) {
                // Take the first 12 and the last 3 chars of the generated VM name
                computerName = vmName.substring(0, 12) + vmName.substring(vmName.length() - 3, vmName.length());
            }
            return computerName;
        }

        @Override
        public void onSuccess(VirtualMachineInner result) {
            logFine(() -> String.format("Successfully created vm [%s]", result.name()));
            ctx.provisionedVm = result;
            ComputeState cs = new ComputeState();
            // Azure for some case changes the case of the vm id.
            ctx.vmId = result.id().toLowerCase();
            cs.id = ctx.vmId;
            cs.type = ComputeType.VM_GUEST;
            cs.environmentName = ComputeDescription.ENVIRONMENT_NAME_AZURE;
            cs.lifecycleState = LifecycleState.READY;
            if (ctx.child.customProperties == null) {
                cs.customProperties = new HashMap<>();
            } else {
                cs.customProperties = ctx.child.customProperties;
            }
            cs.customProperties.put(RESOURCE_GROUP_NAME, ctx.resourceGroup.name());
            Operation.CompletionHandler completionHandler = (ox, exc) -> {
                if (exc != null) {
                    handleError(ctx, exc);
                    return;
                }
                handleAllocation(ctx, nextStage);
            };
            sendRequest(Operation.createPatch(ctx.computeRequest.resourceReference).setBody(cs).setCompletion(completionHandler));
        }
    };
    getComputeManagementClientImpl(ctx).virtualMachines().createOrUpdateAsync(ctx.resourceGroup.name(), ctx.vmName, request, callback);
}
Also used : AzureNicContext(com.vmware.photon.controller.model.adapters.azure.instance.AzureInstanceContext.AzureNicContext) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine) NetworkManagementClientImpl(com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl) PROVISIONING_STATE_SUCCEEDED(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.PROVISIONING_STATE_SUCCEEDED) ComputeManager(com.microsoft.azure.management.compute.implementation.ComputeManager) IpAssignment(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.IpAssignment) VirtualNetworkInner(com.microsoft.azure.management.network.implementation.VirtualNetworkInner) LifecycleState(com.vmware.photon.controller.model.resources.ComputeService.LifecycleState) COMPUTE_NAMESPACE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.COMPUTE_NAMESPACE) DISK_CONTROLLER_NUMBER(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DISK_CONTROLLER_NUMBER) StorageManagementClientImpl(com.microsoft.azure.management.storage.implementation.StorageManagementClientImpl) AzureDiagnosticSettings(com.vmware.photon.controller.model.adapters.azure.model.diagnostics.AzureDiagnosticSettings) INVALID_RESOURCE_GROUP(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.INVALID_RESOURCE_GROUP) Utils(com.vmware.xenon.common.Utils) Map(java.util.Map) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) ProvisioningState(com.microsoft.azure.management.storage.ProvisioningState) OSDisk(com.microsoft.azure.management.compute.OSDisk) AZURE_STORAGE_ACCOUNT_KEY1(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_ACCOUNT_KEY1) ProviderInner(com.microsoft.azure.management.resources.implementation.ProviderInner) CachingTypes(com.microsoft.azure.management.compute.CachingTypes) Indexable(com.microsoft.azure.management.resources.fluentcore.model.Indexable) StorageAccountListKeysResultInner(com.microsoft.azure.management.storage.implementation.StorageAccountListKeysResultInner) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) StatelessService(com.vmware.xenon.common.StatelessService) AZURE_STORAGE_ACCOUNT_DEFAULT_RG_NAME(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_ACCOUNT_DEFAULT_RG_NAME) Disk(com.microsoft.azure.management.compute.Disk) AzureProvisioningCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureProvisioningCallback) CompletionStage(java.util.concurrent.CompletionStage) AzureSecurityGroupUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureSecurityGroupUtils) StorageAccountTypes(com.microsoft.azure.management.compute.StorageAccountTypes) SkuInner(com.microsoft.azure.management.storage.implementation.SkuInner) StorageDescriptionService(com.vmware.photon.controller.model.resources.StorageDescriptionService) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) STATUS_CODE_UNAUTHORIZED(com.vmware.xenon.common.Operation.STATUS_CODE_UNAUTHORIZED) InvalidKeyException(java.security.InvalidKeyException) StorageAccountCreateParametersInner(com.microsoft.azure.management.storage.implementation.StorageAccountCreateParametersInner) DiskCreateOptionTypes(com.microsoft.azure.management.compute.DiskCreateOptionTypes) ResourceGroupsInner(com.microsoft.azure.management.resources.implementation.ResourceGroupsInner) AzureProvisioningCallbackWithRetry(com.vmware.photon.controller.model.adapters.azure.utils.AzureProvisioningCallbackWithRetry) AZURE_DATA_DISK_CACHING(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_DATA_DISK_CACHING) INVALID_PARAMETER(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.INVALID_PARAMETER) STORAGE_ACCOUNT_ALREADY_EXIST(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.STORAGE_ACCOUNT_ALREADY_EXIST) VirtualNetworksInner(com.microsoft.azure.management.network.implementation.VirtualNetworksInner) ImageReferenceInner(com.microsoft.azure.management.compute.implementation.ImageReferenceInner) OperationContext(com.vmware.xenon.common.OperationContext) PROVISIONING_STATE_FAILED_NO_SUBNET(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.PROVISIONING_STATE_FAILED_NO_SUBNET) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) ArrayList(java.util.ArrayList) OSProfile(com.microsoft.azure.management.compute.OSProfile) ComputeInstanceRequest(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) StorageException(com.microsoft.azure.storage.StorageException) AzureAsyncCallback(com.vmware.photon.controller.model.adapters.azure.AzureAsyncCallback) AzureImageSource(com.vmware.photon.controller.model.adapters.azure.instance.AzureInstanceContext.AzureImageSource) MISSING_SUBSCRIPTION_CODE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.MISSING_SUBSCRIPTION_CODE) StorageProfile(com.microsoft.azure.management.compute.StorageProfile) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) BiConsumer(java.util.function.BiConsumer) CloudPageBlob(com.microsoft.azure.storage.blob.CloudPageBlob) OperationStatusResponseInner(com.microsoft.azure.management.compute.implementation.OperationStatusResponseInner) VirtualMachineInner(com.microsoft.azure.management.compute.implementation.VirtualMachineInner) PublicIPAddressInner(com.microsoft.azure.management.network.implementation.PublicIPAddressInner) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) ServiceErrorResponse(com.vmware.xenon.common.ServiceErrorResponse) DataDisk(com.microsoft.azure.management.compute.DataDisk) ServiceCallback(com.microsoft.rest.ServiceCallback) STORAGE_NAMESPACE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.STORAGE_NAMESPACE) SubnetInner(com.microsoft.azure.management.network.implementation.SubnetInner) ImageSource(com.vmware.photon.controller.model.adapters.util.instance.BaseComputeInstanceContext.ImageSource) File(java.io.File) ManagedDiskParametersInner(com.microsoft.azure.management.compute.implementation.ManagedDiskParametersInner) NETWORK_NAMESPACE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.NETWORK_NAMESPACE) AzureUtils.getStorageAccountKeyName(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.getStorageAccountKeyName) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) IPAllocationMethod(com.microsoft.azure.management.network.IPAllocationMethod) CloudError(com.microsoft.azure.CloudError) HardwareProfile(com.microsoft.azure.management.compute.HardwareProfile) AzureNicContext(com.vmware.photon.controller.model.adapters.azure.instance.AzureInstanceContext.AzureNicContext) URISyntaxException(java.net.URISyntaxException) NetworkProfile(com.microsoft.azure.management.compute.NetworkProfile) VirtualMachineImageResourceInner(com.microsoft.azure.management.compute.implementation.VirtualMachineImageResourceInner) AzureUriPaths(com.vmware.photon.controller.model.adapters.azure.AzureUriPaths) SubscriptionInner(com.microsoft.azure.management.resources.implementation.SubscriptionInner) AZURE_MANAGED_DISK_TYPE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_MANAGED_DISK_TYPE) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) Creatable(com.microsoft.azure.management.resources.fluentcore.model.Creatable) AzureSdkClients(com.vmware.photon.controller.model.adapters.azure.utils.AzureSdkClients) ResourceManagementClientImpl(com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) URI(java.net.URI) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) AvailabilitySet(com.microsoft.azure.management.compute.AvailabilitySet) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) SkuName(com.microsoft.azure.management.storage.SkuName) AddressSpace(com.microsoft.azure.management.network.AddressSpace) COMPUTER_NAME(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.COMPUTER_NAME) Predicate(java.util.function.Predicate) Collection(java.util.Collection) DiskConfiguration(com.vmware.photon.controller.model.resources.ImageService.ImageState.DiskConfiguration) AvailabilitySetInner(com.microsoft.azure.management.compute.implementation.AvailabilitySetInner) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) InstanceRequestType(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest.InstanceRequestType) Collectors(java.util.stream.Collectors) Base64(java.util.Base64) List(java.util.List) VirtualHardDisk(com.microsoft.azure.management.compute.VirtualHardDisk) AzureUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils) NetworkSecurityGroupsInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupsInner) NetworkInterfacesInner(com.microsoft.azure.management.network.implementation.NetworkInterfacesInner) Optional(java.util.Optional) NetworkSecurityGroupInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner) DiskService(com.vmware.photon.controller.model.resources.DiskService) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Default(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback.Default) SubResource(com.microsoft.azure.SubResource) AZURE_OSDISK_CACHING(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_OSDISK_CACHING) ResourceGroupInner(com.microsoft.azure.management.resources.implementation.ResourceGroupInner) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Region(com.microsoft.azure.management.resources.fluentcore.arm.Region) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) AzureDeferredResultServiceCallbackWithRetry(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallbackWithRetry) VirtualMachineSizeTypes(com.microsoft.azure.management.compute.VirtualMachineSizeTypes) SubscriptionClientImpl(com.microsoft.azure.management.resources.implementation.SubscriptionClientImpl) Kind(com.microsoft.azure.management.storage.Kind) Level(java.util.logging.Level) FileUtils(com.vmware.xenon.common.FileUtils) AZURE_STORAGE_ACCOUNT_RG_NAME(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_ACCOUNT_RG_NAME) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) PublicIPAddressesInner(com.microsoft.azure.management.network.implementation.PublicIPAddressesInner) STORAGE_CONNECTION_STRING(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.STORAGE_CONNECTION_STRING) AzureDecommissionCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDecommissionCallback) ComputeManagementClientImpl(com.microsoft.azure.management.compute.implementation.ComputeManagementClientImpl) NetworkInterfaceIPConfigurationInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceIPConfigurationInner) EncryptionUtils(com.vmware.photon.controller.model.security.util.EncryptionUtils) CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) Operation(com.vmware.xenon.common.Operation) AvailabilitySetSkuTypes(com.microsoft.azure.management.compute.AvailabilitySetSkuTypes) StorageAccountKey(com.microsoft.azure.management.storage.StorageAccountKey) BaseAdapterStage(com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.BaseAdapterStage) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) NetworkInterfaceReferenceInner(com.microsoft.azure.management.compute.implementation.NetworkInterfaceReferenceInner) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) AZURE_STORAGE_ACCOUNT_NAME(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_ACCOUNT_NAME) CloudException(com.microsoft.azure.CloudException) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) StorageAccountInner(com.microsoft.azure.management.storage.implementation.StorageAccountInner) NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) NetworkInterfaceInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceInner) CLOUD_CONFIG_DEFAULT_FILE_INDEX(com.vmware.photon.controller.model.constants.PhotonModelConstants.CLOUD_CONFIG_DEFAULT_FILE_INDEX) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) RESOURCE_GROUP_NAME(com.vmware.photon.controller.model.ComputeProperties.RESOURCE_GROUP_NAME) PROVIDER_REGISTRED_STATE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.PROVIDER_REGISTRED_STATE) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) OSProfile(com.microsoft.azure.management.compute.OSProfile) ArrayList(java.util.ArrayList) Operation(com.vmware.xenon.common.Operation) StorageProfile(com.microsoft.azure.management.compute.StorageProfile) VirtualMachineInner(com.microsoft.azure.management.compute.implementation.VirtualMachineInner) AzureAsyncCallback(com.vmware.photon.controller.model.adapters.azure.AzureAsyncCallback) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) ManagedDiskParametersInner(com.microsoft.azure.management.compute.implementation.ManagedDiskParametersInner) SubResource(com.microsoft.azure.SubResource) OSDisk(com.microsoft.azure.management.compute.OSDisk) NetworkInterfaceReferenceInner(com.microsoft.azure.management.compute.implementation.NetworkInterfaceReferenceInner) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CloudError(com.microsoft.azure.CloudError) CloudException(com.microsoft.azure.CloudException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DiskConfiguration(com.vmware.photon.controller.model.resources.ImageService.ImageState.DiskConfiguration) DataDisk(com.microsoft.azure.management.compute.DataDisk) NetworkProfile(com.microsoft.azure.management.compute.NetworkProfile) HardwareProfile(com.microsoft.azure.management.compute.HardwareProfile) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState)

Example 15 with DataDisk

use of com.microsoft.azure.management.compute.DataDisk in project photon-model by vmware.

the class AzureInstanceService method newAzureDataDisks.

/**
 * Converts Photon model data DiskState to underlying Azure DataDisk model.
 */
private List<DataDisk> newAzureDataDisks(AzureInstanceContext ctx, int startLUNForAdditionalDisks) {
    int lunIndex = startLUNForAdditionalDisks;
    final List<DataDisk> azureDataDisks = new ArrayList<>();
    for (DiskService.DiskStateExpanded diskState : ctx.dataDiskStates) {
        if (diskState.persistent == true && ctx.useManagedDisks()) {
            continue;
        }
        final DataDisk dataDisk = new DataDisk();
        dataDisk.withName(diskState.name);
        if (ctx.reuseExistingStorageAccount()) {
            dataDisk.withVhd(getVHDUriForDataDisk(ctx.vmName, diskState.storageDescription.name, lunIndex));
        } else if (ctx.useManagedDisks()) {
            ManagedDiskParametersInner managedDiskParams = new ManagedDiskParametersInner();
            String accountType = diskState.customProperties.getOrDefault(AzureConstants.AZURE_MANAGED_DISK_TYPE, StorageAccountTypes.STANDARD_LRS.toString());
            managedDiskParams.withStorageAccountType(StorageAccountTypes.fromString(accountType));
            dataDisk.withManagedDisk(managedDiskParams);
        } else {
            dataDisk.withVhd(getVHDUriForDataDisk(ctx.vmName, ctx.storageAccountName, lunIndex));
        }
        dataDisk.withCreateOption(DiskCreateOptionTypes.EMPTY);
        dataDisk.withDiskSizeGB((int) diskState.capacityMBytes / 1024);
        dataDisk.withCaching(CachingTypes.fromString(diskState.customProperties.getOrDefault(AZURE_DATA_DISK_CACHING, CachingTypes.READ_WRITE.toString())));
        dataDisk.withLun(lunIndex);
        azureDataDisks.add(dataDisk);
        lunIndex++;
    }
    // Add the external existing disks
    if (!ctx.externalDataDisks.isEmpty()) {
        for (DiskService.DiskStateExpanded diskState : ctx.externalDataDisks) {
            final DataDisk dataDisk = new DataDisk();
            if (ctx.reuseExistingStorageAccount()) {
                dataDisk.withVhd(getVHDUriForDataDisk(ctx.vmName, diskState.storageDescription.name, lunIndex));
            } else if (ctx.useManagedDisks()) {
                ManagedDiskParametersInner managedDiskParams = new ManagedDiskParametersInner();
                managedDiskParams.withId(diskState.id);
                dataDisk.withManagedDisk(managedDiskParams);
            } else {
                dataDisk.withVhd(getVHDUriForDataDisk(ctx.vmName, ctx.storageAccountName, lunIndex));
            }
            dataDisk.withCreateOption(DiskCreateOptionTypes.ATTACH);
            dataDisk.withCaching(CachingTypes.fromString(diskState.customProperties.getOrDefault(AZURE_DATA_DISK_CACHING, CachingTypes.READ_WRITE.toString())));
            dataDisk.withLun(lunIndex);
            azureDataDisks.add(dataDisk);
            lunIndex++;
        }
    }
    return azureDataDisks;
}
Also used : ManagedDiskParametersInner(com.microsoft.azure.management.compute.implementation.ManagedDiskParametersInner) DataDisk(com.microsoft.azure.management.compute.DataDisk) ArrayList(java.util.ArrayList) DiskService(com.vmware.photon.controller.model.resources.DiskService)

Aggregations

DataDisk (com.microsoft.azure.management.compute.DataDisk)17 VirtualMachineUnmanagedDataDisk (com.microsoft.azure.management.compute.VirtualMachineUnmanagedDataDisk)8 VirtualMachineDataDisk (com.microsoft.azure.management.compute.VirtualMachineDataDisk)7 DiskState (com.vmware.photon.controller.model.resources.DiskService.DiskState)5 Map (java.util.Map)5 OSDisk (com.microsoft.azure.management.compute.OSDisk)4 DiskService (com.vmware.photon.controller.model.resources.DiskService)4 Operation (com.vmware.xenon.common.Operation)4 ArrayList (java.util.ArrayList)4 Disk (com.microsoft.azure.management.compute.Disk)3 VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)3 ManagedDiskParametersInner (com.microsoft.azure.management.compute.implementation.ManagedDiskParametersInner)3 VirtualMachineInner (com.microsoft.azure.management.compute.implementation.VirtualMachineInner)3 AzureConstants (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants)3 UriUtils (com.vmware.xenon.common.UriUtils)3 Level (java.util.logging.Level)3 StorageProfile (com.microsoft.azure.management.compute.StorageProfile)2 VirtualHardDisk (com.microsoft.azure.management.compute.VirtualHardDisk)2 NetworkManagementClientImpl (com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl)2 NetworkSecurityGroupInner (com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner)2