1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/linode/models/compute/flavors.rb
2013-01-07 20:53:28 +00:00

32 lines
755 B
Ruby

require 'fog/core/collection'
require 'fog/linode/models/compute/flavor'
module Fog
module Compute
class Linode
class Flavors < Fog::Collection
model Fog::Compute::Linode::Flavor
def all
load flavors
end
def get(id)
new flavors(id).first
rescue Fog::Linode::Compute::NotFound
nil
end
private
def flavors(id=nil)
service.avail_linodeplans(id).body['DATA'].map { |flavor| map_flavor flavor }
end
def map_flavor(flavor)
flavor = flavor.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v }
flavor.merge! :id => flavor[:planid], :name => flavor[:label]
end
end
end
end
end