Class: Cloudcost::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudcost/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Server

Returns a new instance of Server.



13
14
15
16
# File 'lib/cloudcost/server.rb', line 13

def initialize(data)
  @data = data
  @total_storage_per_type = sum_up_storage_per_type
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



11
12
13
# File 'lib/cloudcost/server.rb', line 11

def data
  @data
end

Instance Method Details

#flavorObject



26
27
28
# File 'lib/cloudcost/server.rb', line 26

def flavor
  @data[:flavor][:slug]
end

#memory_gbObject



34
35
36
# File 'lib/cloudcost/server.rb', line 34

def memory_gb
  @data[:flavor][:memory_gb]
end

#nameObject



18
19
20
# File 'lib/cloudcost/server.rb', line 18

def name
  @data[:name]
end

#server_costs_per_dayObject



54
55
56
# File 'lib/cloudcost/server.rb', line 54

def server_costs_per_day
  Pricing.server_costs_per_day(flavor)
end

#storage_costs_per_day(type = :ssd) ⇒ Object



58
59
60
# File 'lib/cloudcost/server.rb', line 58

def storage_costs_per_day(type = :ssd)
  Pricing.storage_costs_per_day(type.to_s, storage_size(type))
end

#storage_size(type = :ssd) ⇒ Object



50
51
52
# File 'lib/cloudcost/server.rb', line 50

def storage_size(type = :ssd)
  @total_storage_per_type[type] || 0
end

#sum_up_storage_per_typeObject



66
67
68
69
70
71
72
73
# File 'lib/cloudcost/server.rb', line 66

def sum_up_storage_per_type
  sum = {}
  volumes.group_by { |volume| volume[:type].itself }.each do |group, vols|
    sum.store(group.to_sym, 0)
    vols.each { |volume| sum[volume[:type].to_sym] += volume[:size_gb] }
  end
  sum
end

#tagsObject



42
43
44
# File 'lib/cloudcost/server.rb', line 42

def tags
  @data[:tags]
end

#tags_to_sObject



46
47
48
# File 'lib/cloudcost/server.rb', line 46

def tags_to_s
  Cloudcost.tags_to_s(tags)
end

#total_costs_per_dayObject



62
63
64
# File 'lib/cloudcost/server.rb', line 62

def total_costs_per_day
  server_costs_per_day + storage_costs_per_day(:ssd) + storage_costs_per_day(:bulk)
end

#uuidObject



22
23
24
# File 'lib/cloudcost/server.rb', line 22

def uuid
  @data[:uuid]
end

#vcpu_countObject



30
31
32
# File 'lib/cloudcost/server.rb', line 30

def vcpu_count
  @data[:flavor][:vcpu_count]
end

#volumesObject



38
39
40
# File 'lib/cloudcost/server.rb', line 38

def volumes
  @data[:volumes]
end