/// <summary> /// Initializes a new instance of the OSDisk class. /// </summary> public OSDisk(string name, VirtualHardDisk vhd, DiskCreateOptionTypes?createOption, OperatingSystemTypes?osType = default(OperatingSystemTypes?), DiskEncryptionSettings encryptionSettings = default(DiskEncryptionSettings), VirtualHardDisk image = default(VirtualHardDisk), CachingTypes?caching = default(CachingTypes?), int?diskSizeGB = default(int?)) { OsType = osType; EncryptionSettings = encryptionSettings; Name = name; Vhd = vhd; Image = image; Caching = caching; CreateOption = createOption; DiskSizeGB = diskSizeGB; }
/// <summary> /// Initializes a new instance of the RestorePointSourceVMOSDisk class. /// </summary> /// <param name="osType">Gets the Operating System type. Possible /// values include: 'Windows', 'Linux'</param> /// <param name="encryptionSettings">Gets the disk encryption /// settings.</param> /// <param name="name">Gets the disk name.</param> /// <param name="caching">Gets the caching type. Possible values /// include: 'None', 'ReadOnly', 'ReadWrite'</param> /// <param name="diskSizeGB">Gets the disk size in GB.</param> /// <param name="managedDisk">Gets the managed disk details</param> /// <param name="diskRestorePoint">Gets the disk restore point /// Id.</param> public RestorePointSourceVMOSDisk(string osType = default(string), DiskEncryptionSettings encryptionSettings = default(DiskEncryptionSettings), string name = default(string), CachingTypes?caching = default(CachingTypes?), int?diskSizeGB = default(int?), ManagedDiskParameters managedDisk = default(ManagedDiskParameters), ApiEntityReference diskRestorePoint = default(ApiEntityReference)) { OsType = osType; EncryptionSettings = encryptionSettings; Name = name; Caching = caching; DiskSizeGB = diskSizeGB; ManagedDisk = managedDisk; DiskRestorePoint = diskRestorePoint; CustomInit(); }
/// <summary> /// Initializes a new instance of the OSDisk class. /// </summary> /// <param name="createOption">Specifies how the virtual machine should /// be created.<br><br> Possible values /// are:<br><br> **Attach** \u2013 This value is used when /// you are using a specialized disk to create the virtual /// machine.<br><br> **FromImage** \u2013 This value is /// used when you are using an image to create the virtual machine. If /// you are using a platform image, you also use the imageReference /// element described above. If you are using a marketplace image, you /// also use the plan element previously described. Possible values /// include: 'FromImage', 'Empty', 'Attach'</param> /// <param name="osType">This property allows you to specify the type /// of the OS that is included in the disk if creating a VM from /// user-image or a specialized VHD. <br><br> Possible /// values are: <br><br> **Windows** <br><br> /// **Linux**. Possible values include: 'Windows', 'Linux'</param> /// <param name="encryptionSettings">Specifies the encryption settings /// for the OS Disk. <br><br> Minimum api-version: /// 2015-06-15</param> /// <param name="name">The disk name.</param> /// <param name="vhd">The virtual hard disk.</param> /// <param name="image">The source user image virtual hard disk. The /// virtual hard disk will be copied before being attached to the /// virtual machine. If SourceImage is provided, the destination /// virtual hard drive must not exist.</param> /// <param name="caching">Specifies the caching requirements. /// <br><br> Possible values are: <br><br> /// **None** <br><br> **ReadOnly** <br><br> /// **ReadWrite** <br><br> Default: **None** for Standard /// storage. **ReadOnly** for Premium storage. Possible values include: /// 'None', 'ReadOnly', 'ReadWrite'</param> /// <param name="writeAcceleratorEnabled">Specifies whether /// writeAccelerator should be enabled or disabled on the disk.</param> /// <param name="diffDiskSettings">Specifies the ephemeral Disk /// Settings for the operating system disk used by the virtual /// machine.</param> /// <param name="diskSizeGB">Specifies the size of an empty data disk /// in gigabytes. This element can be used to overwrite the size of the /// disk in a virtual machine image. <br><br> This value /// cannot be larger than 1023 GB</param> /// <param name="managedDisk">The managed disk parameters.</param> public OSDisk(string createOption, OperatingSystemTypes?osType = default(OperatingSystemTypes?), DiskEncryptionSettings encryptionSettings = default(DiskEncryptionSettings), string name = default(string), VirtualHardDisk vhd = default(VirtualHardDisk), VirtualHardDisk image = default(VirtualHardDisk), CachingTypes?caching = default(CachingTypes?), bool?writeAcceleratorEnabled = default(bool?), DiffDiskSettings diffDiskSettings = default(DiffDiskSettings), int?diskSizeGB = default(int?), ManagedDiskParameters managedDisk = default(ManagedDiskParameters)) { OsType = osType; EncryptionSettings = encryptionSettings; Name = name; Vhd = vhd; Image = image; Caching = caching; WriteAcceleratorEnabled = writeAcceleratorEnabled; DiffDiskSettings = diffDiskSettings; CreateOption = createOption; DiskSizeGB = diskSizeGB; ManagedDisk = managedDisk; CustomInit(); }
protected DiskEncryptionSettings GetEncryptionSettings(bool addKek = false) { string testVaultId = @"/subscriptions/21466899-20b2-463c-8c30-b8fb28a43248/resourceGroups/RgTest1/providers/Microsoft.KeyVault/vaults/TestVault123"; string encryptionKeyFakeUri = @"https://testvault123.vault.azure.net/secrets/Test1/514ceb769c984379a7e0230bdd703272"; DiskEncryptionSettings diskEncryptionSettings = new DiskEncryptionSettings { DiskEncryptionKey = new KeyVaultSecretReference { SecretUrl = encryptionKeyFakeUri, SourceVault = new SourceVaultReference { ReferenceUri = testVaultId } } }; if (addKek) { string nonExistentKekUri = @"https://testvault123.vault.azure.net/keys/TestKey/514ceb769c984379a7e0230bdd703272"; diskEncryptionSettings.KeyEncryptionKey = new KeyVaultKeyReference { KeyUrl = nonExistentKekUri, SourceVault = new SourceVaultReference { ReferenceUri = testVaultId } }; } return diskEncryptionSettings; }
/// <summary> /// This function gets the VM model, fills in the OSDisk properties with encryptionSettings and does an UpdateVM /// </summary> private ComputeLongRunningOperationResponse UpdateVmEncryptionSettings() { string statusMessage = GetExtensionStatusMessage(); VirtualMachine vmParameters = (this.ComputeClient.ComputeManagementClient.VirtualMachines.Get(this.ResourceGroupName, this.VMName)).VirtualMachine; if ((vmParameters == null) || (vmParameters.StorageProfile == null) || (vmParameters.StorageProfile.OSDisk == null)) { //VM should have been created and have valid storageProfile and OSDisk by now ThrowTerminatingError(new ErrorRecord(new ApplicationException(string.Format(CultureInfo.CurrentUICulture, "Set-AzureDiskEncryptionExtension can enable encryption only on a VM that was already created and has appropriate storageProfile and OS disk")), "InvalidResult", ErrorCategory.InvalidResult, null)); } DiskEncryptionSettings encryptionSettings = new DiskEncryptionSettings(); encryptionSettings.DiskEncryptionKey = new KeyVaultSecretReference(); encryptionSettings.DiskEncryptionKey.SourceVault = new SourceVaultReference(); encryptionSettings.DiskEncryptionKey.SourceVault.ReferenceUri = this.DiskEncryptionKeyVaultId; encryptionSettings.DiskEncryptionKey.SecretUrl = statusMessage; if (this.KeyEncryptionKeyUrl != null) { encryptionSettings.KeyEncryptionKey = new KeyVaultKeyReference(); encryptionSettings.KeyEncryptionKey.SourceVault = new SourceVaultReference(); encryptionSettings.KeyEncryptionKey.SourceVault.ReferenceUri = this.KeyEncryptionKeyVaultId; encryptionSettings.KeyEncryptionKey.KeyUrl = this.KeyEncryptionKeyUrl; } vmParameters.StorageProfile.OSDisk.EncryptionSettings = encryptionSettings; var parameters = new VirtualMachine { DiagnosticsProfile = vmParameters.DiagnosticsProfile, HardwareProfile = vmParameters.HardwareProfile, StorageProfile = vmParameters.StorageProfile, NetworkProfile = vmParameters.NetworkProfile, OSProfile = vmParameters.OSProfile, Plan = vmParameters.Plan, AvailabilitySetReference = vmParameters.AvailabilitySetReference, Location = vmParameters.Location, Name = vmParameters.Name, Tags = vmParameters.Tags }; return this.ComputeClient.ComputeManagementClient.VirtualMachines.CreateOrUpdate(this.ResourceGroupName, parameters); }
/// <summary> /// This function gets the VM model, fills in the OSDisk properties with encryptionSettings and does an UpdateVM /// </summary> private AzureOperationResponse<VirtualMachine> UpdateVmEncryptionSettings() { var vmParameters = (this.ComputeClient.ComputeManagementClient.VirtualMachines.Get( this.ResourceGroupName, this.VMName)); if ((vmParameters == null) || (vmParameters.StorageProfile == null) || (vmParameters.StorageProfile.OsDisk == null)) { // VM should have been created and have valid storageProfile and OSDisk by now ThrowTerminatingError( new ErrorRecord( new ApplicationException( string.Format( CultureInfo.CurrentUICulture, "Set-AzureDiskEncryptionExtension can enable encryption only on a VM that was already created and has appropriate storageProfile and OS disk")), "InvalidResult", ErrorCategory.InvalidResult, null)); } DiskEncryptionSettings encryptionSettings = new DiskEncryptionSettings(); encryptionSettings.Enabled = false; vmParameters.StorageProfile.OsDisk.EncryptionSettings = encryptionSettings; var parameters = new VirtualMachine { DiagnosticsProfile = vmParameters.DiagnosticsProfile, HardwareProfile = vmParameters.HardwareProfile, StorageProfile = vmParameters.StorageProfile, NetworkProfile = vmParameters.NetworkProfile, OsProfile = vmParameters.OsProfile, Plan = vmParameters.Plan, AvailabilitySet = vmParameters.AvailabilitySet, Location = vmParameters.Location, Tags = vmParameters.Tags }; return this.ComputeClient.ComputeManagementClient.VirtualMachines.CreateOrUpdateWithHttpMessagesAsync( this.ResourceGroupName, vmParameters.Name, parameters).GetAwaiter().GetResult(); }