Skip to content

Commit

Permalink
Charge allocation of hyperv instances without rollups
Browse files Browse the repository at this point in the history
(cherry picked from commit 44cfadd)
  • Loading branch information
isimluk committed Jan 10, 2017
1 parent 215a225 commit 57e4f1c
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions app/models/chargeback/consumption_without_rollups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,29 @@ def parents_determining_rate
MiqEnterprise.my_enterprise].compact
end

def none?(_metric)
true # No, values except for fixed (RateDetail.fixed?)
end

def max(_metric)
raise NotImplementedError # Unreachable code since none?==true
end

def avg(_metric)
raise NotImplementedError # Unreachable code since none?==true
def none?(metric)
current_value(metric).nil?
end

def chargeback_fields_present
1 # Yes, charge this interval as fixed_compute_*_*
end

def current_value(metric)
# Return the last seen allocation for charging purposes.
@value ||= {}
@value[metric] ||= case metric
when 'derived_vm_numvcpus' # Allocated CPU count
resource.hardware.try(:cpu_total_cores)
when 'derived_memory_available'
resource.hardware.try(:memory_mb)
when 'derived_vm_allocated_disk_storage'
resource.allocated_disk_storage
end
@value[metric]
end
alias avg current_value
alias max current_value
private :current_value
end
end

0 comments on commit 57e4f1c

Please sign in to comment.