2011-03-01 11:10:59 -05:00
|
|
|
require 'fog/core/collection'
|
2011-08-24 21:24:45 -04:00
|
|
|
require 'fog/linode/models/compute/image'
|
2011-03-01 11:10:59 -05:00
|
|
|
|
|
|
|
module Fog
|
2011-06-16 19:28:54 -04:00
|
|
|
module Compute
|
|
|
|
class Linode
|
2011-03-01 11:10:59 -05:00
|
|
|
class Images < Fog::Collection
|
2011-06-16 19:28:54 -04:00
|
|
|
model Fog::Compute::Linode::Image
|
2011-03-01 11:10:59 -05:00
|
|
|
|
|
|
|
def all
|
|
|
|
load images
|
|
|
|
end
|
|
|
|
|
|
|
|
def get(id)
|
|
|
|
new images(id).first
|
2011-06-16 19:28:54 -04:00
|
|
|
rescue Fog::Compute::Linode::NotFound
|
2011-03-01 11:10:59 -05:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def images(id=nil)
|
2011-03-01 16:37:27 -05:00
|
|
|
connection.avail_distributions(id).body['DATA'].map { |image| map_image image }
|
2011-03-01 11:10:59 -05:00
|
|
|
end
|
|
|
|
|
2011-03-01 16:37:27 -05:00
|
|
|
def map_image(image)
|
|
|
|
image = image.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v }
|
|
|
|
image.merge!(:id => image[:distributionid], :name => image[:label], :image_size => image[:minimagesize],
|
|
|
|
:kernel_id => image[:requirespvopskernel], :bits => ((image[:is64bit] == 1) ? 64 : 32 ))
|
2011-03-01 11:10:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|