/// <summary>
        /// Get the AzureResourceInfo object for the specified Azure VM SKU
        /// </summary>
        /// <param name="azureVMInstanceType">Azure VM SKU</param>
        /// <param name="operatingSystem">Operating System of the instance</param>
        /// <param name="location">Azure Location</param>
        /// <returns> Returns the AzureResourceInfo object for the specified Azure VM SKU</returns>
        public static AzureResourceInfo GetAzureResourceInfoForAzureVM(string azureVMInstanceType, string operatingSystem, string location)
        {
            AzureResourceInfo resourceInfo = new AzureResourceInfo()
            {
                MeterCategory    = AzureResourceMeterConstants.VMComputeMeterCategory,
                MeterName        = AzureResourceMeterConstants.VMComputeMeterName,
                MeterRegion      = location,
                MeterSubCategory = null
            };

            try
            {
                string modifiedVMSizeString = ModifyVMSizeStringAsPerPricingSpecs(azureVMInstanceType);

                switch (operatingSystem.ToUpper())
                {
                case "WINDOWS":
                    resourceInfo.MeterSubCategory = string.Format(AzureResourceMeterConstants.VMComputeMeterSubCategoryWindowsString, modifiedVMSizeString, operatingSystem);
                    break;

                case "LINUX":
                    resourceInfo.MeterSubCategory = string.Format(AzureResourceMeterConstants.VMComputeMeterSubCategoryLinuxString, modifiedVMSizeString);
                    break;
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(resourceInfo);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the Meter for the specified Azure resource
        /// </summary>
        /// <param name="resourceInfo">the Azure resource</param>
        /// <returns> Returns the Meter for the resource</returns>
        private Meter GetResourceMeter(AzureResourceInfo resourceInfo)
        {
            Meter meter = null;

            try
            {
                meter = this.meterList.Find(x => resourceInfo.MeterCategory.Equals(x.MeterCategory, StringComparison.OrdinalIgnoreCase) &&
                                            resourceInfo.MeterSubCategory.Equals(x.MeterSubCategory, StringComparison.OrdinalIgnoreCase) &&
                                            resourceInfo.MeterName.Equals(x.MeterName, StringComparison.OrdinalIgnoreCase) &&
                                            resourceInfo.MeterRegion.Equals(x.MeterRegion, StringComparison.OrdinalIgnoreCase));

                if (meter == null)
                {
                    meter = this.meterList.Find(x => resourceInfo.MeterCategory.Equals(x.MeterCategory, StringComparison.OrdinalIgnoreCase) &&
                                                resourceInfo.MeterSubCategory.Equals(x.MeterSubCategory, StringComparison.OrdinalIgnoreCase) &&
                                                resourceInfo.MeterName.Equals(x.MeterName, StringComparison.OrdinalIgnoreCase) &&
                                                x.MeterRegion.Equals(string.Empty, StringComparison.OrdinalIgnoreCase));
                }

                if (meter == null)
                {
                    throw new Exception(string.Format(Constants.AzureResourceMeterMissing, resourceInfo.MeterCategory, resourceInfo.MeterSubCategory, resourceInfo.MeterName, resourceInfo.MeterRegion));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(meter);
        }
        /// <summary>
        /// Get the cost for the specified list of mapped managed disks
        /// </summary>
        /// <param name="listofDisks">the list of mapped disks</param>
        /// <param name="location">the Azure location</param>
        /// <param name="rateCalc">the object that can fetch the rates for Azure resources</param>
        /// <returns> Returns the total estimated cost for the list of mapped managed disks</returns>
        private static double GetCostforSpecifiedListofDisks(List <AzureMappedDisks> listofDisks, string location, AzureResourceRateCalc rateCalc)
        {
            double totalDiskCost = 0;

            try
            {
                foreach (AzureMappedDisks managedDisks in listofDisks)
                {
                    AzureResourceInfo resourceInfo = new AzureResourceInfo()
                    {
                        MeterCategory    = AzureResourceMeterConstants.VMManagedDiskMeterCategory,
                        MeterName        = managedDisks.MappedDisk.DiskMeterName,
                        MeterRegion      = location,
                        MeterSubCategory = AzureResourceMeterConstants.VMManagedDiskMeterSubCategory
                    };

                    totalDiskCost = totalDiskCost + (rateCalc.GetResourceRate(resourceInfo) * managedDisks.DiskCount);
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(totalDiskCost);
        }
        /// <summary>
        /// Get the Azure VM SKU cost
        /// </summary>
        /// <param name="vmListItem">The Azure VM SKU</param>
        /// <param name="specs">The input specifications</param>
        /// <returns> Returns the Azure VM SKU cost</returns>
        private static double GetAzureVMCost(AzureVMSizeListItem vmListItem, VMSpecs specs)
        {
            double rate = 0;

            try
            {
                AzureResourceInfo resourceInfo = AzureVMMeterHelper.GetAzureResourceInfoForAzureVM(vmListItem.Name, specs.OperatingSystem, location);
                rate = rateCalc.GetResourceRate(resourceInfo);
            }
            catch (Exception)
            {
                throw;
            }

            return(rate);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the rate for the specified Azure resource
        /// </summary>
        /// <param name="resourceInfo">the Azure resource</param>
        /// <returns> Returns the rate for the resource</returns>
        public double GetResourceRate(AzureResourceInfo resourceInfo)
        {
            double rate = 0;

            try
            {
                Meter             meter      = this.GetResourceMeter(resourceInfo);
                OrderedDictionary meterRates = meter.MeterRates;

                if (meterRates.Count >= 1)
                {
                    rate = (double)meterRates[0];
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(rate);
        }