mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
35 lines
825 B
Ruby
35 lines
825 B
Ruby
|
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
|
||
|
def flavors(flavor_id=nil)
|
||
|
connection.avail_linodeplans(flavor_id).body['DATA'].tap { |data| map_flavors data }
|
||
|
end
|
||
|
|
||
|
def map_flavors(flavors)
|
||
|
flavors.map! { |flavor| flavor.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v } }
|
||
|
flavors.each { |flavor| flavor.merge! :name => flavor[:label], :id => flavor[:planid] }
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|