-
Notifications
You must be signed in to change notification settings - Fork 898
/
consumption_without_rollups.rb
66 lines (55 loc) · 1.76 KB
/
consumption_without_rollups.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class Chargeback
class ConsumptionWithoutRollups < Consumption
delegate :id, :name, :type, :to => :resource, :prefix => :resource
attr_reader :resource
def initialize(resource, start_time, end_time)
super(start_time, end_time)
@resource = resource
end
def timestamp
@start_time
end
def parent_ems
resource.ext_management_system
end
def tag_names
resource.tags.collect(&:name)
end
def hash_features_affecting_rate
resource.id
end
def tag_list_with_prefix
tag_names.map { |t| "vm/tag#{t}" }
end
def parents_determining_rate
[resource.host, resource.ems_cluster, resource.storage, parent_ems, resource.tenant,
MiqEnterprise.my_enterprise].compact
end
def none?(metric)
current_value(metric).nil?
end
def chargeback_fields_present
1 # Yes, charge this interval as fixed_compute_*_*
end
def metering_used_fields_present
0 # we don't count used hours in metering report
end
def current_value(metric, _sub_metric = nil)
# 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
alias sum_of_maxes_from_grouped_values current_value
private :current_value
end
end