-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'allocated cpu cores' chargeback rate detail to existing chargeba…
…ck rates
- Loading branch information
Ari Zellner
committed
Oct 26, 2017
1 parent
267c684
commit 2425ed9
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
db/migrate/20171026103833_add_cores_allocated_rate_detail.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class AddCoresAllocatedRateDetail < ActiveRecord::Migration[5.0] | ||
def up | ||
chargeable_field = ChargeableField.find_or_create(:metric => "derived_vm_numvcpus_cores", | ||
:description => "Allocated CPU Cores", | ||
:group => "cpu_cores", | ||
:source => "allocated") if chargeable_field.nil? | ||
|
||
rate_detail_template = ChargebackRateDetail.where(:description => "Allocated CPU Count").first | ||
return if rate_detail_template.nil? # No rates that need this detail. | ||
rate_detail_template = rate_detail_template.dup | ||
rate_detail_template.chargeable_field = chargeable_field | ||
rate_detail_template.description = "Allocated CPU Cores" | ||
rate_detail_template.per_unit = "cpu core" | ||
tier_template = {:start => 0, :finish => Float::INFINITY, :fixed_rate => 1.0, :variable_rate => 0.0} | ||
|
||
# Add to cb rates that do not have the "Allocated CPU Cores" cb detail | ||
ChargebackRate.where(:rate_type => "Compute").where.not(:id => ChargebackRateDetail.where(:description => "Allocated CPU Cores").select(:chargeback_rate_id)).each do |rate| | ||
new_rate_detail = rate_detail_template.dup | ||
new_rate_detail.chargeback_tiers << ChargebackTier.new(tier_template.slice(*ChargebackTier::FORM_ATTRIBUTES)) | ||
rate.chargeback_rate_details << new_rate_detail | ||
end | ||
end | ||
|
||
def down | ||
ChargebackRateDetail.where(:description => "Allocated CPU Cores").destroy_all | ||
end | ||
end |