lib/cloudcost/azure.rb
# We will collect all us locations but when building the price
# in the azure_build_price_file.rb script we will only get
# eastus data.
#Locations = {
# "eastus"         => "US East",
# "westus"         => "US West",
# "centralus"      => "US Central",
# "eastus2"        => "US East 2",
# "westus2"        => "US West 2",
# "northcentralus" => "US North Central",
# "southcentralus" => "US South Central",
# "westcentralus"  => "US West Central",
# }
We will collect all us locations but when building the price
in the azure_build_price_file.rb script we will only get
eastus data.
We will collect all us locations but when building the price in the azure_build_price_file . rb script we will only get eastus data .
def collect_and_build(output_dir)
        storage = get_price_data_for('Storage')
        vms = get_price_data_for('Virtual Machines')
        skus = filter_sku_for_us_locations_and_vms_disks_only(get_azure_sku_card())
        skus.each{ |x| cap = sku_cap_to_h(x); x['capabilities'] = cap }
        eastus_skus_only            = skus.group_by{ |sku| sku['locations'].first }['eastus']
        skus_by_type                = eastus_skus_only.group_by{ |sku| sku['resourceType'] }
        vm_skus                     = skus_by_type['virtualMachines']
        storage_skus                = skus_by_type['disks']
        vms_eastus_only             = vms.group_by{ |x| x['armRegionName'] == 'eastus' }[true]
        vms_no_spot_or_low_priority = vms_eastus_only.group_by do |x| 
            x['skuName'].match(/(Low Priority|Spot)/i) or 
            x['meterName'].match?(/free/i) 
        end[false]
        vms_eastus_ondemand         = vms_no_spot_or_low_priority.group_by{ |x| x['type'] == 'Consumption' }[true]
        vms_by_os                   = vms_eastus_ondemand.group_by{ |x| x['productName'] =~ /windows$/i ? true : false }
        vms_windows                 = vms_by_os[true].group_by{ |x| x['armSkuName']}
        vms_linux                   = vms_by_os[false].group_by{ |x| x['armSkuName']}
        vms_eastus_res               = vms_no_spot_or_low_priority.group_by{ |x| x['type'] == 'Reservation' }[true];
        vms_eastus_res_by_term       = vms_eastus_res.group_by{ |x| x['reservationTerm'] }
        vms_eastus_res_1yr           = vms_eastus_res_by_term['1 Year'].group_by{ |x| x['armSkuName']}
        vms_eastus_res_3yr           = vms_eastus_res_by_term['3 Years'].group_by{ |x| x['armSkuName']}
        vms_eastus_res_5yr           = vms_eastus_res_by_term['5 Years'].group_by{ |x| x['armSkuName']}
        vms_eastus_price_list = []
        vm_skus.each do |sku|
            name = sku['name']
            sku['terms'] = {
                'OnDemand': {
                    'windows': check_terms(vms_windows[name]),
                    'linux': check_terms(vms_linux[name])
                },
                'Reserved': {
                    '1year': check_terms(vms_eastus_res_1yr[name]),
                    '3year': check_terms(vms_eastus_res_3yr[name]),
                    '5year': check_terms(vms_eastus_res_5yr[name])
                }
            }
            vms_eastus_price_list << sku
        end
        outname = "#{output_dir}/azure.json"
        File.open(outname,'w'){ |f| f << vms_eastus_price_list.to_json }
        Log.info("Merging all Azure files to '#{outname}'")
    end
def collect_and_build ( output_dir ) storage = get_price_data_for ( 'Storage' ) vms = get_price_data_for ( 'Virtual Machines' ) skus = filter_sku_for_us_locations_and_vms_disks_only ( get_azure_sku_card ( ) ) skus . each { | x | cap = sku_cap_to_h ( x ) ; x [ 'capabilities' ] = cap } eastus_skus_only = skus . group_by { | sku | sku [ 'locations' ] . first } [ 'eastus' ] skus_by_type = eastus_skus_only . group_by { | sku | sku [ 'resourceType' ] } vm_skus = skus_by_type [ 'virtualMachines' ] storage_skus = skus_by_type [ 'disks' ] vms_eastus_only = vms . group_by { | x | x [ 'armRegionName' ] == 'eastus' } [ true ] vms_no_spot_or_low_priority = vms_eastus_only . group_by do | x | x [ 'skuName' ] . match ( / (Low Priority|Spot) /i ) or x [ 'meterName' ] . match? ( / free /i ) end [ false ] vms_eastus_ondemand = vms_no_spot_or_low_priority . group_by { | x | x [ 'type' ] == 'Consumption' } [ true ] vms_by_os = vms_eastus_ondemand . group_by { | x | x [ 'productName' ] =~ / windows$ /i ? true : false } vms_windows = vms_by_os [ true ] . group_by { | x | x [ 'armSkuName' ] } vms_linux = vms_by_os [ false ] . group_by { | x | x [ 'armSkuName' ] } vms_eastus_res = vms_no_spot_or_low_priority . group_by { | x | x [ 'type' ] == 'Reservation' } [ true ] ; vms_eastus_res_by_term = vms_eastus_res . group_by { | x | x [ 'reservationTerm' ] } vms_eastus_res_1yr = vms_eastus_res_by_term [ '1 Year' ] . group_by { | x | x [ 'armSkuName' ] } vms_eastus_res_3yr = vms_eastus_res_by_term [ '3 Years' ] . group_by { | x | x [ 'armSkuName' ] } vms_eastus_res_5yr = vms_eastus_res_by_term [ '5 Years' ] . group_by { | x | x [ 'armSkuName' ] } vms_eastus_price_list = [ ] vm_skus . each do | sku | name = sku [ 'name' ] sku [ 'terms' ] = { 'OnDemand' : { 'windows' : check_terms ( vms_windows [ name ] ) , 'linux' : check_terms ( vms_linux [ name ] ) } , 'Reserved' : { '1year' : check_terms ( vms_eastus_res_1yr [ name ] ) , '3year' : check_terms ( vms_eastus_res_3yr [ name ] ) , '5year' : check_terms ( vms_eastus_res_5yr [ name ] ) } } vms_eastus_price_list << sku end outname = "#{output_dir}/azure.json" File . open ( outname , 'w' ) { | f | f << vms_eastus_price_list . to_json } Log . info ( "Merging all Azure files to '#{outname}'" ) end
We will collect all us locations but when building the price
in the azure_build_price_file.rb script we will only get
eastus data.
We will collect all us locations but when building the price in the azure_build_price_file . rb script we will only get eastus data .
# Fetch and compile pricing for storage and vms # This is all the sku or product data limited to disks and vms # Get product from the sku file. Split by vms and disks (storage) # VMs are a service id of "DZH313Z7MMC8" # Type of "Consumption", "Reservation", "DevTestConsumption" # productName e.g "Virtual Machines A Series Basic Windows", # skuName e.g "A0 Low Priority", Low Priority,  # armRegionName             => 'eastus'  (we don't use region for AWS. Can use it here right now.) # Let's remove spot, Low or free versions # Get ondemand / consumption pricing # Get reserved pricing
output_dir