Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
PRE_PAID_REDUCE_FACTOR settings and functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
slntopp committed Apr 29, 2021
1 parent 16e0b5f commit 0594dda
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion core/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
['USERS_DEFAULT_LANG', "en_US", "Default locale for new users", 1, "str"],
['VCENTER_CPU_LIMIT_FREQ_PER_CORE', "{\"default\":2000}", "Frequency per Core limit for different Nodes(don't remove default)", 1, "object"],
['VCENTER_DRIVES_IOPS', "{\"HDD\":350,\"SSD\":1000}", "IOPs limits for Drive types", 1, "object"],
['VNETS_TEMPLATES', "{}", "VNs Types to VNs Templates mapping(types must be upper case)", 1, "object"]
['VNETS_TEMPLATES', "{}", "VNs Types to VNs Templates mapping(types must be upper case)", 1, "object"],
['PRE_PAID_REDUCE_FACTOR', "{\"0\": 1}", "Reduce factor for Pre-Paid VMs depending on billing period", 1, "object"]
]
required.each do | record |
begin
Expand Down
15 changes: 14 additions & 1 deletion service/objects/vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ def calculate_showback stime_req, etime_req, _group_by_day = false
}
elsif bp.include? 'PRE' then
curr = self['/VM/STIME'].to_i
delta = bp.split('_')[1].to_i * 86400
period = bp.split('_')[1].to_i
delta = period * 86400

total = 0

Expand All @@ -412,6 +413,18 @@ def calculate_showback stime_req, etime_req, _group_by_day = false
curr += delta
end

reduce_factor = 1
reduce_factors = IONe::Settings['PRE_PAID_REDUCE_FACTOR'].keys_to_i!.sort.to_h

reduce_factors.each do | period_key, factor |
if period >= period_key then
reduce_factor = factor
else
break
end
end
reduce_factor = reduce_factor.to_f

return {
id: id, name: name,
total_billed: total, reduce_factor: reduce_factor,
Expand Down

0 comments on commit 0594dda

Please sign in to comment.