Class: Cloudcost::Server
- Inherits:
-
Object
- Object
- Cloudcost::Server
- Defined in:
- lib/cloudcost/commands/server/server.rb
Overview
Representation of cloudscale.ch server object
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.
12 13 14 15 |
# File 'lib/cloudcost/commands/server/server.rb', line 12 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.
10 11 12 |
# File 'lib/cloudcost/commands/server/server.rb', line 10 def data @data end |
Instance Method Details
#flavor ⇒ Object
25 26 27 |
# File 'lib/cloudcost/commands/server/server.rb', line 25 def flavor @data[:flavor][:slug] end |
#memory_gb ⇒ Object
33 34 35 |
# File 'lib/cloudcost/commands/server/server.rb', line 33 def memory_gb @data[:flavor][:memory_gb] end |
#name ⇒ Object
17 18 19 |
# File 'lib/cloudcost/commands/server/server.rb', line 17 def name @data[:name] end |
#server_costs_per_day ⇒ Object
53 54 55 |
# File 'lib/cloudcost/commands/server/server.rb', line 53 def server_costs_per_day Pricing.server_costs_per_day(flavor) end |
#storage_costs_per_day(type = :ssd) ⇒ Object
57 58 59 |
# File 'lib/cloudcost/commands/server/server.rb', line 57 def storage_costs_per_day(type = :ssd) Pricing.storage_costs_per_day(type.to_s, storage_size(type)) end |
#storage_size(type = :ssd) ⇒ Object
49 50 51 |
# File 'lib/cloudcost/commands/server/server.rb', line 49 def storage_size(type = :ssd) @total_storage_per_type[type] || 0 end |
#sum_up_storage_per_type ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/cloudcost/commands/server/server.rb', line 65 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
41 42 43 |
# File 'lib/cloudcost/commands/server/server.rb', line 41 def @data[:tags] end |
#tags_to_s ⇒ Object
45 46 47 |
# File 'lib/cloudcost/commands/server/server.rb', line 45 def Cloudcost.() end |
#total_costs_per_day ⇒ Object
61 62 63 |
# File 'lib/cloudcost/commands/server/server.rb', line 61 def total_costs_per_day server_costs_per_day + storage_costs_per_day(:ssd) + storage_costs_per_day(:bulk) end |
#uuid ⇒ Object
21 22 23 |
# File 'lib/cloudcost/commands/server/server.rb', line 21 def uuid @data[:uuid] end |
#vcpu_count ⇒ Object
29 30 31 |
# File 'lib/cloudcost/commands/server/server.rb', line 29 def vcpu_count @data[:flavor][:vcpu_count] end |
#volumes ⇒ Object
37 38 39 |
# File 'lib/cloudcost/commands/server/server.rb', line 37 def volumes @data[:volumes] end |