Ejemplo n.º 1
0
        /// <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>
        public static VMOSDisk FromUmanagedVhd(string name, ResourceUri unmanagedVhdFile, 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 ((unmanagedVhdFile == null) || (!unmanagedVhdFile.IsValid) ||
                (!unmanagedVhdFile.Is(ResourceUriCompareLevel.Provider, "Microsoft.Storage")) || (!unmanagedVhdFile.Is(ResourceUriCompareLevel.Type, "storageAccounts")))
            {
                throw new ArgumentException(nameof(unmanagedVhdFile));
            }

            VMOSDisk disk = new VMOSDisk()
            {
                Name        = name,
                CreateUsing = DiskCreationOptionsEnum.Copy,
                VhdFile     = new UriResource(unmanagedVhdFile.ToString()),
                Caching     = caching,
                IsWriteAccelerationEnabled = enableWriteAcceleration
            };

            return(disk);
        }
Ejemplo n.º 2
0
        /// <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>
        public static VMOSDisk FromManagedDisk(string name, ResourceUri managedDiskUri, DiskSkuNamesEnum typeOfDisk = DiskSkuNamesEnum.Standard_LRS, 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 (!Enum.IsDefined(typeof(DiskSkuNamesEnum), typeOfDisk))
            {
                throw new ArgumentOutOfRangeException(nameof(typeOfDisk));
            }

            if ((managedDiskUri == null) || (!managedDiskUri.IsValid) ||
                (!managedDiskUri.Is(ResourceUriCompareLevel.Provider, "Microsoft.Storage")) || (!managedDiskUri.Is(ResourceUriCompareLevel.Type, "storageAccounts")))
            {
                throw new ArgumentException(nameof(managedDiskUri));
            }

            VMOSDisk disk = new VMOSDisk()
            {
                Name        = name,
                CreateUsing = DiskCreationOptionsEnum.Attach,
                ManagedDisk = new VMManagedDisk()
                {
                    Id   = managedDiskUri.ToString(),
                    Type = typeOfDisk
                },
                Caching = caching,
                IsWriteAccelerationEnabled = enableWriteAcceleration
            };

            return(disk);
        }