mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
35 lines
979 B
Ruby
35 lines
979 B
Ruby
require 'fog/core/collection'
|
|
require 'fog/compute/models/linode/image'
|
|
|
|
module Fog
|
|
module Linode
|
|
class Compute
|
|
class Images < Fog::Collection
|
|
model Fog::Linode::Compute::Image
|
|
|
|
def all
|
|
load images
|
|
end
|
|
|
|
def get(id)
|
|
new images(id).first
|
|
rescue Fog::Linode::Compute::NotFound
|
|
nil
|
|
end
|
|
|
|
private
|
|
def images(id=nil)
|
|
connection.avail_distributions(id).body['DATA'].tap { |data| map_images data }
|
|
end
|
|
|
|
def map_images(images)
|
|
images.map! { |image| image.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v } }
|
|
images.each do |image|
|
|
image.merge!(:id => image[:distributionid], :name => image[:label], :image_size => image[:minimagesize],
|
|
:kernel_id => image[:requirespvopskernel], :bits => ((image[:is64bit] == 1) ? 64 : 32 ))
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|