Class: Cloudcost::Server
- Inherits:
-
Object
- Object
- Cloudcost::Server
- Defined in:
- lib/cloudcost/server.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
- #flavor ⇒ Object
-
#initialize(data) ⇒ Server
constructor
A new instance of Server.
- #memory_gb ⇒ Object
- #name ⇒ Object
- #server_costs_per_day ⇒ Object
- #storage_costs_per_day(type = :ssd) ⇒ Object
- #storage_size(type = :ssd) ⇒ Object
- #sum_up_storage_per_type ⇒ Object
- #tags ⇒ Object
- #tags_to_s ⇒ Object
- #total_costs_per_day ⇒ Object
- #uuid ⇒ Object
- #vcpu_count ⇒ Object
- #volumes ⇒ Object
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
#data ⇒ Object
Returns the value of attribute data.
11 12 13 |
# File 'lib/cloudcost/server.rb', line 11 def data @data end |
Instance Method Details
#flavor ⇒ Object
26 27 28 |
# File 'lib/cloudcost/server.rb', line 26 def flavor @data[:flavor][:slug] end |
#memory_gb ⇒ Object
34 35 36 |
# File 'lib/cloudcost/server.rb', line 34 def memory_gb @data[:flavor][:memory_gb] end |
#name ⇒ Object
18 19 20 |
# File 'lib/cloudcost/server.rb', line 18 def name @data[:name] end |
#server_costs_per_day ⇒ Object
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_type ⇒ Object
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 |
#tags ⇒ Object
42 43 44 |
# File 'lib/cloudcost/server.rb', line 42 def @data[:tags] end |
#tags_to_s ⇒ Object
46 47 48 |
# File 'lib/cloudcost/server.rb', line 46 def Cloudcost.() end |
#total_costs_per_day ⇒ Object
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 |
#uuid ⇒ Object
22 23 24 |
# File 'lib/cloudcost/server.rb', line 22 def uuid @data[:uuid] end |
#vcpu_count ⇒ Object
30 31 32 |
# File 'lib/cloudcost/server.rb', line 30 def vcpu_count @data[:flavor][:vcpu_count] end |
#volumes ⇒ Object
38 39 40 |
# File 'lib/cloudcost/server.rb', line 38 def volumes @data[:volumes] end |