Class: DiskBiller

Inherits:
Biller show all
Defined in:
service/billers/disk.rb

Overview

VM Disk costs biller

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:



29
30
31
32
33
34
35
36
37
38
# File 'service/billers/disk.rb', line 29

def bill bill:, state:, delta:, record: nil
  bill[:disk] = delta * @cost * @size
  for rec in state[:system_disk] do
    bill[:disk] += delta * @cost * rec[:size].to_i / 1000.0
  end if state[:system_disk]
  for rec in state[:backup_disk] do
    bill[:disk] += delta * @costs[rec[:img].to_s].to_f * rec[:size].to_i / 1000.0
  end if state[:backup_disk]
  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
23
24
25
26
# File 'service/billers/disk.rb', line 4

def check_biller
  @costs = JSON.parse(costs['DISK_COSTS'])
  res =
    @costs.values.inject(0) do | r, c |
      r += c.to_f
    rescue
      r
    end
  @cost = @costs[@vm['/VM/USER_TEMPLATE/DRIVE']].to_f

  @costs = JSON.parse(costs['BACKUP_IMAGE_COSTS'])
  res +=
    @costs.values.inject(0) do | r, c |
      r += c.to_f
    rescue
      r
    end
  @size = @vm.drives.first['SIZE'].to_i / 1000.0

  return res > 0
rescue
  return false
end