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
2014-09-02 15:58:00 -04: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::Compute::Linode::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