2011-02-28 16:25:38 -05:00
|
|
|
require 'fog/core/collection'
|
2011-08-24 21:24:45 -04:00
|
|
|
require 'fog/linode/models/compute/flavor'
|
2011-02-28 16:25:38 -05:00
|
|
|
|
|
|
|
module Fog
|
2011-06-16 19:28:54 -04:00
|
|
|
module Compute
|
|
|
|
class Linode
|
2011-02-28 16:25:38 -05:00
|
|
|
class Flavors < Fog::Collection
|
2011-06-16 19:28:54 -04:00
|
|
|
model Fog::Compute::Linode::Flavor
|
2011-02-28 16:25:38 -05:00
|
|
|
|
|
|
|
def all
|
|
|
|
load flavors
|
|
|
|
end
|
|
|
|
|
|
|
|
def get(id)
|
|
|
|
new flavors(id).first
|
2014-09-02 15:58:00 -04:00
|
|
|
rescue Fog::Compute::Linode::NotFound
|
2011-02-28 16:25:38 -05:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2011-03-01 11:10:59 -05:00
|
|
|
def flavors(id=nil)
|
2012-12-22 18:25:24 -05:00
|
|
|
service.avail_linodeplans(id).body['DATA'].map { |flavor| map_flavor flavor }
|
2011-02-28 16:25:38 -05:00
|
|
|
end
|
2012-12-22 18:25:24 -05:00
|
|
|
|
2011-03-01 16:37:27 -05:00
|
|
|
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]
|
2011-02-28 16:25:38 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|