/// <summary> /// Instantiate for an unmanaged disk /// </summary> /// <param name="attachedLUN">The logical unit number the disk is attached on to the VM</param> /// <param name="storageType">Type of storage account stored on (cannot be UltraSSD_LRS)</param> /// <param name="caching">Type of caching used on the disk</param> /// <param name="sizeInGB">Size in GB (must be from 1 to 1023)</param> /// <param name="vhdBlobUri">Uri to VHD file stored as a blob in an Azure Storage account</param> public ImageDataDisk(int attachedLUN, DiskSkuNamesEnum storageType, CachingTypeNamesEnum caching, int sizeInGB, string vhdBlobUri) { if ((attachedLUN < 0) || (attachedLUN > 254)) { throw new ArgumentOutOfRangeException(nameof(attachedLUN)); } if ((!Enum.IsDefined(typeof(DiskSkuNamesEnum), storageType)) || (storageType == DiskSkuNamesEnum.UltraSSD_LRS)) { throw new ArgumentOutOfRangeException(nameof(storageType)); } if (!Enum.IsDefined(typeof(CachingTypeNamesEnum), caching)) { throw new ArgumentOutOfRangeException(nameof(caching)); } if ((sizeInGB <= 0) || (sizeInGB > 1023)) { throw new ArgumentOutOfRangeException(nameof(sizeInGB)); } if (string.IsNullOrWhiteSpace(vhdBlobUri)) { throw new ArgumentNullException(nameof(vhdBlobUri)); } AttachedOnLUN = attachedLUN; AccountType = storageType; LatestSnapshot = null; ManagedDisk = null; SizeGB = sizeInGB; CacheType = caching; VhdStoredOnBlobUri = vhdBlobUri; }
/// <summary> /// Instantiate for an unmanaged disk /// </summary> /// <param name="osName">Type of OS on the disk</param> /// <param name="isGeneralized">If true, image is generalied, suitable to create a new VM</param> /// <param name="storageType">Type of storage account stored on (cannot be UltraSSD_LRS)</param> /// <param name="caching">Type of caching used on the disk</param> /// <param name="sizeInGB">Size in GB (must be from 1 to 1023)</param> /// <param name="vhdBlobUri">Uri to VHD file stored as a blob in an Azure Storage account</param> public ImageOSDisk(OSTypeNamesEnum osName, bool isGeneralized, DiskSkuNamesEnum storageType, CachingTypeNamesEnum caching, int sizeInGB, string vhdBlobUri) { if (!Enum.IsDefined(typeof(OSTypeNamesEnum), osName)) { throw new ArgumentOutOfRangeException(nameof(osName)); } if ((!Enum.IsDefined(typeof(DiskSkuNamesEnum), storageType)) || (storageType == DiskSkuNamesEnum.UltraSSD_LRS)) { throw new ArgumentOutOfRangeException(nameof(storageType)); } if (!Enum.IsDefined(typeof(CachingTypeNamesEnum), caching)) { throw new ArgumentOutOfRangeException(nameof(caching)); } if ((sizeInGB <= 0) || (sizeInGB > 1023)) { throw new ArgumentOutOfRangeException(nameof(sizeInGB)); } if (string.IsNullOrWhiteSpace(vhdBlobUri)) { throw new ArgumentNullException(nameof(vhdBlobUri)); } OperatingSystemType = osName; StateOfOS = (isGeneralized ? OSStateTypeNamesEnum.Generalized : OSStateTypeNamesEnum.Specialized); AccountType = storageType; LatestSnapshot = null; ManagedDisk = null; SizeGB = sizeInGB; CacheType = caching; VhdStoredOnBlobUri = vhdBlobUri; }
/// <summary> /// Instantiate for an managed disk /// </summary> /// <param name="attachedLUN">The logical unit number the disk is attached on to the VM</param> /// <param name="storageType">Type of storage account stored on (cannot be UltraSSD_LRS)</param> /// <param name="caching">Type of caching used on the disk</param> /// <param name="sizeInGB">Size in GB (must be from 1 to 1023)</param> /// <param name="diskUri">Uri to the managed disk</param> public ImageDataDisk(int attachedLUN, DiskSkuNamesEnum storageType, CachingTypeNamesEnum caching, int sizeInGB, ResourceUri diskUri) { if ((!Enum.IsDefined(typeof(DiskSkuNamesEnum), storageType)) || (storageType == DiskSkuNamesEnum.UltraSSD_LRS)) { throw new ArgumentOutOfRangeException(nameof(storageType)); } if (!Enum.IsDefined(typeof(CachingTypeNamesEnum), caching)) { throw new ArgumentOutOfRangeException(nameof(caching)); } if ((sizeInGB <= 0) || (sizeInGB > 1023)) { throw new ArgumentOutOfRangeException(nameof(sizeInGB)); } if ((diskUri == null) || (!diskUri.IsValid)) { throw new ArgumentNullException(nameof(diskUri)); } AttachedOnLUN = attachedLUN; AccountType = storageType; LatestSnapshot = null; ManagedDisk = new SubResource(diskUri); SizeGB = sizeInGB; CacheType = caching; VhdStoredOnBlobUri = null; }
/// <summary> /// Create a data disk by copying an existing image /// </summary> /// <param name="name">Name of the disk</param> /// <param name="fromImage">URI to the Vhd's blob on a Storage Account</param> /// <param name="caching">Type of caching to enable</param> /// <param name="enableWriteAcceleration">Flag indicating whether to enable write acceleration on the disk</param> public static VMOSDisk FromImage(string name, ResourceUri fromImage, CachingTypeNamesEnum caching = CachingTypeNamesEnum.None, bool enableWriteAcceleration = false) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(nameof(name)); } if (!Enum.IsDefined(typeof(CachingTypeNamesEnum), caching)) { throw new ArgumentOutOfRangeException(nameof(caching)); } if ((fromImage == null) || (!fromImage.IsValid) || (!fromImage.Is(ResourceUriCompareLevel.Provider, "Microsoft.Storage")) || (!fromImage.Is(ResourceUriCompareLevel.Type, "storageAccounts"))) { throw new ArgumentException(nameof(fromImage)); } VMOSDisk disk = new VMOSDisk() { Name = name, CreateUsing = DiskCreationOptionsEnum.FromImage, CreateModeSourceImage = new UriResource(fromImage.ToString()), Caching = caching, IsWriteAccelerationEnabled = enableWriteAcceleration }; return(disk); }
/// <summary> /// Attach a managed data disk /// </summary> /// <param name="attachedLUN">The logical unit number the disk is attached on to the VM</param> /// <param name="storageType">Type of storage account stored on (cannot be UltraSSD_LRS)</param> /// <param name="caching">Type of caching used on the disk</param> /// <param name="sizeInGB">Size in GB (must be from 1 to 1023)</param> /// <param name="diskUri">Uri to the managed disk</param> public void AttachDataDisk(int attachedLUN, DiskSkuNamesEnum storageType, CachingTypeNamesEnum caching, int sizeInGB, ResourceUri diskUri) { if (DataDisks == null) { DataDisks = new List <ImageDataDisk>(); } DataDisks.Add(new ImageDataDisk(attachedLUN, storageType, caching, sizeInGB, diskUri)); }
/// <summary> /// Create a data disk by attaching an managed disk /// </summary> /// <param name="name">Name of the disk</param> /// <param name="managedDiskUri">URI to the existing unmanaged Vhd on a Storage Account</param> /// <param name="caching">Type of caching to enable</param> /// <param name="enableWriteAcceleration">Flag indicating whether to enable write acceleration on the disk</param> /// <param name="attachToLUN">The LUN to attach the disk to. Set to -1 to automatically pick a LUN (Azure will decide)</param> public static VMDataDisk FromManagedDisk(string name, ResourceUri managedDiskUri, DiskSkuNamesEnum typeOfDisk = DiskSkuNamesEnum.Standard_LRS, CachingTypeNamesEnum caching = CachingTypeNamesEnum.None, bool enableWriteAcceleration = false, int attachToLUN = -1) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(nameof(name)); } if (!Enum.IsDefined(typeof(CachingTypeNamesEnum), caching)) { throw new ArgumentOutOfRangeException(nameof(caching)); } if (!Enum.IsDefined(typeof(DiskSkuNamesEnum), typeOfDisk)) { throw new ArgumentOutOfRangeException(nameof(typeOfDisk)); } if (attachToLUN < -1) { throw new ArgumentOutOfRangeException(nameof(attachToLUN)); } if ((managedDiskUri == null) || (!managedDiskUri.IsValid) || (!managedDiskUri.Is(ResourceUriCompareLevel.Provider, "Microsoft.Storage")) || (!managedDiskUri.Is(ResourceUriCompareLevel.Type, "storageAccounts"))) { throw new ArgumentException(nameof(managedDiskUri)); } VMDataDisk disk = new VMDataDisk() { Name = name, CreateUsing = DiskCreationOptionsEnum.Attach, ManagedDisk = new VMManagedDisk() { Id = managedDiskUri.ToString(), Type = typeOfDisk }, Caching = caching, IsWriteAccelerationEnabled = enableWriteAcceleration }; if (attachToLUN != -1) { disk.LogicalUnitNumber = attachToLUN; } return(disk); }
/// <summary> /// Create a data disk by attaching an unmanaged Vhd /// </summary> /// <param name="name">Name of the disk</param> /// <param name="unmanagedVhdFile">URI to the existing unmanaged Vhd on a Storage Account</param> /// <param name="caching">Type of caching to enable</param> /// <param name="enableWriteAcceleration">Flag indicating whether to enable write acceleration on the disk</param> /// <param name="attachToLUN">The LUN to attach the disk to. Set to -1 to automatically pick a LUN (Azure will decide)</param> public static VMDataDisk FromUmanagedVhd(string name, ResourceUri unmanagedVhdFile, CachingTypeNamesEnum caching = CachingTypeNamesEnum.None, bool enableWriteAcceleration = false, int attachToLUN = -1) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(nameof(name)); } if (!Enum.IsDefined(typeof(CachingTypeNamesEnum), caching)) { throw new ArgumentOutOfRangeException(nameof(caching)); } if (attachToLUN < -1) { throw new ArgumentOutOfRangeException(nameof(attachToLUN)); } if ((unmanagedVhdFile == null) || (!unmanagedVhdFile.IsValid) || (!unmanagedVhdFile.Is(ResourceUriCompareLevel.Provider, "Microsoft.Storage")) || (!unmanagedVhdFile.Is(ResourceUriCompareLevel.Type, "storageAccounts"))) { throw new ArgumentException(nameof(unmanagedVhdFile)); } VMDataDisk disk = new VMDataDisk() { Name = name, CreateUsing = DiskCreationOptionsEnum.Copy, VhdFile = new UriResource(unmanagedVhdFile.ToString()), Caching = caching, IsWriteAccelerationEnabled = enableWriteAcceleration }; if (attachToLUN != -1) { disk.LogicalUnitNumber = attachToLUN; } return(disk); }
/// <summary> /// Set the cache type /// </summary> /// <param name="cachingType">Type of cache</param> /// <returns>ImageOSDisk</returns> public ImageOSDisk WithCache(CachingTypeNamesEnum cachingType) { CacheType = cachingType; return(this); }
/// <summary> /// Set primary disk (for an managed disk) /// </summary> /// <param name="osName">Type of OS on the disk</param> /// <param name="isGeneralized">If true, image is generalied, suitable to create a new VM</param> /// <param name="storageType">Type of storage account stored on (cannot be UltraSSD_LRS)</param> /// <param name="caching">Type of caching used on the disk</param> /// <param name="sizeInGB">Size in GB (must be from 1 to 1023)</param> /// <param name="diskUri">Uri to the managed disk</param> public void SetPrimaryDisk(OSTypeNamesEnum osName, bool isGeneralized, DiskSkuNamesEnum storageType, CachingTypeNamesEnum caching, int sizeInGB, ResourceUri diskUri) => PrimaryDisk = new ImageOSDisk(osName, isGeneralized, storageType, caching, sizeInGB, diskUri);