2011-02-28 16:25:38 -05:00
|
|
|
require 'fog/core/collection'
|
|
|
|
require 'fog/compute/models/linode/flavor'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Linode
|
|
|
|
class Compute
|
|
|
|
class Flavors < Fog::Collection
|
|
|
|
model Fog::Linode::Compute::Flavor
|
|
|
|
|
|
|
|
def all
|
|
|
|
load flavors
|
|
|
|
end
|
|
|
|
|
|
|
|
def get(id)
|
|
|
|
new flavors(id).first
|
|
|
|
rescue Fog::Linode::Compute::NotFound
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2011-03-01 11:10:59 -05:00
|
|
|
def flavors(id=nil)
|
|
|
|
connection.avail_linodeplans(id).body['DATA'].tap { |data| map_flavors data }
|
2011-02-28 16:25:38 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def map_flavors(flavors)
|
|
|
|
flavors.map! { |flavor| flavor.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v } }
|
2011-03-01 11:10:59 -05:00
|
|
|
flavors.each { |flavor| flavor.merge! :id => flavor[:planid], :name => flavor[:label] }
|
2011-02-28 16:25:38 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|