Class: CapacityBiller

Inherits:
Biller
  • Object
show all
Defined in:
service/billers/capacity.rb

Overview

Bills VM Capacity costs(CPU and RAM)

Instance Method Summary collapse

Methods inherited from Biller

#billing_period, #costs, #initialize

Constructor Details

This class inherits a constructor from Biller

Instance Method Details

#bill(bill:, state:, delta:, record: nil) ⇒ Object

See Also:



25
26
27
28
29
30
# File 'service/billers/capacity.rb', line 25

def bill bill:, state:, delta:, record: nil
  if state[:state] == 'on' || billing_period != 'PAYG' then
    bill[:capacity] = delta * @cost
  end
  bill
end

#check_billerObject

Checking if Capacity costs are given, otherwise there is no point to calculate it



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'service/billers/capacity.rb', line 4

def check_biller
  @costs = JSON.parse(costs['CAPACITY_COST'])
  return false if @costs.nil?

  costs =
    @costs.values.inject(0) do | r, c |
      r += c.to_f
    rescue
      r
    end
  if costs > 0 then
    @cost = @costs['CPU_COST'].to_f * @vm['//TEMPLATE/VCPU'].to_i + @costs['MEMORY_COST'].to_f * @vm['//TEMPLATE/MEMORY'].to_i / 1000
    return true
  end

  return false
rescue
  return false
end