class Cloud::InstanceType

Describe a public cloud instance type

Constants

VERSION

Attributes

category[R]
details[R]
key[R]
name[R]
ram_bytes[R]
ram_si_units[R]
sort_value[R]
vcpu_count[R]

Public Class Methods

for(cloud) click to toggle source
# File lib/cloud/instancetype.rb, line 31
def for(cloud)
  load(rails_vendor_path(cloud))
rescue
  load(rails_config_path(cloud))
end
load(data_path) click to toggle source
# File lib/cloud/instancetype.rb, line 37
def load(data_path)
  raw_collection = get_raw_collection(data_path)
  instance_type_collection_factory(
    raw_collection["instance_types"],
    raw_collection["categories"]
  )
end
new(key, raw_data) click to toggle source
# File lib/cloud/instancetype.rb, line 10
def initialize(key, raw_data)
  @key = key
  @name = raw_data["name"]
  @sort_value = raw_data["sort_value"]
  @vcpu_count = raw_data["vcpu_count"]
  @ram_bytes = raw_data["ram_bytes"]
  @ram_si_units = raw_data["ram_si_units"]
  @details = raw_data["details"]
  return unless raw_data["category_key"]

  @category = Cloud::InstanceCategory.new(
    raw_data["category_key"], 
    raw_data["category"]
  )
end

Private Class Methods

get_raw_collection(data_path) click to toggle source
# File lib/cloud/instancetype.rb, line 55
def get_raw_collection(data_path)
  JSON.parse(File.read(data_path))
end
instance_type_collection_factory(raw_types, raw_categories) click to toggle source
# File lib/cloud/instancetype.rb, line 59
def instance_type_collection_factory(raw_types, raw_categories)
  raw_types.collect do |key, values|
    values["category_key"] = values["category"]
    values["category"] = raw_categories[values["category"]]
    InstanceType.new(key, values)
  end.sort!
end
rails_config_path(cloud) click to toggle source
# File lib/cloud/instancetype.rb, line 47
def rails_config_path(cloud)
  Rails.root.join("config", "data", "#{cloud}-types.json")
end
rails_vendor_path(cloud) click to toggle source
# File lib/cloud/instancetype.rb, line 51
def rails_vendor_path(cloud)
  Rails.root.join("vendor", "data", "#{cloud}-types.json")
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/cloud/instancetype.rb, line 26
def <=>(other)
  sort_value <=> other.sort_value
end