/// <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;
        }
示例#2
0
        /// <summary>
        /// Create an image from a marketplace image
        /// </summary>
        /// <param name="osType">Type of OS we are provisioning for</param>
        /// <param name="marketplaceImageResourceUri">ResourceUri to the marketplace image</param>
        /// <returns>Disk creation metadata</returns>
        public static DiskCreationMetadata ViaPlatformImage(OSTypeNamesEnum osType, ResourceUri marketplaceImageResourceUri)
        {
            if (!Enum.IsDefined(typeof(OSTypeNamesEnum), osType))
            {
                throw new ArgumentOutOfRangeException(nameof(osType));
            }
            if ((marketplaceImageResourceUri == null) || (!marketplaceImageResourceUri.IsValid))
            {
                throw new ArgumentException(nameof(marketplaceImageResourceUri));
            }

            return(new DiskCreationMetadata()
            {
                CreationMode = DiskCreationOptionsEnum.FromImage,
                SourceDiskImageReference = new SubResource()
                {
                    ResourceId = marketplaceImageResourceUri.ToString()
                }
            });
        }
        /// <summary>
        /// Get a list of available application stacks
        /// </summary>
        /// <param name="bearerToken">Azure Bearer Token</param>
        /// <param name="operatingSystem">Operating system to fetch the stacks for</param>
        /// <returns>List of application stacks for the operating system specified, or an empty list</returns>
        public static async Task <IList <ApplicationStack> > GetApplicationStacks(string bearerToken, OSTypeNamesEnum operatingSystem)
        {
            if (string.IsNullOrWhiteSpace(bearerToken))
            {
                throw new ArgumentNullException(nameof(bearerToken));
            }
            if (!Enum.IsDefined(typeof(OSTypeNamesEnum), operatingSystem))
            {
                throw new ArgumentOutOfRangeException(nameof(operatingSystem));
            }

            RestApiResponse response = await RestApiClient.GETWithContinuations <ApplicationStack>(
                bearerToken,
                $"https://management.azure.com/providers/Microsoft.Web/availableStacks?osTypeSelected={Enum.GetName(typeof(OSTypeNamesEnum), operatingSystem)}",
                CLIENT_API_VERSION,
                null, null,
                new int[] { 200 }
                );

            if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body))
            {
                return(new List <ApplicationStack>());
            }

            return(JsonConvert.DeserializeObject <ListResultWithContinuations <ApplicationStack> >(response.Body).Values);
        }
 /// <summary>
 /// Set the OS on the disk
 /// </summary>
 /// <param name="operatingSystem">OS on the disk</param>
 /// <returns>ImageOSDisk</returns>
 public ImageOSDisk WithOS(OSTypeNamesEnum operatingSystem)
 {
     OperatingSystemType = operatingSystem;
     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);