2010-03-19 18:29:42 -07:00
|
|
|
require 'fog/collection'
|
2010-09-08 14:00:43 -07:00
|
|
|
require 'fog/rackspace/models/compute/image'
|
2010-03-19 18:29:42 -07:00
|
|
|
|
2009-11-19 08:19:46 -08:00
|
|
|
module Fog
|
|
|
|
module Rackspace
|
2010-09-08 13:50:23 -07:00
|
|
|
class Compute
|
2009-11-19 08:19:46 -08:00
|
|
|
|
|
|
|
class Images < Fog::Collection
|
|
|
|
|
2010-09-08 13:50:23 -07:00
|
|
|
model Fog::Rackspace::Compute::Image
|
2009-11-19 08:19:46 -08:00
|
|
|
|
|
|
|
attribute :server
|
|
|
|
|
|
|
|
def all
|
2010-03-06 20:02:10 -08:00
|
|
|
data = connection.list_images_detail.body['images']
|
2010-03-16 23:36:45 -07:00
|
|
|
load(data)
|
2009-11-19 08:19:46 -08:00
|
|
|
if server
|
2010-03-06 20:02:10 -08:00
|
|
|
self.replace(self.select {|image| image.server_id == server.id})
|
2009-11-19 08:19:46 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get(image_id)
|
2010-04-08 12:55:55 -07:00
|
|
|
data = connection.get_image_details(image_id).body['image']
|
|
|
|
new(data)
|
2010-09-08 13:50:23 -07:00
|
|
|
rescue Fog::Rackspace::Compute::NotFound
|
2009-11-19 08:19:46 -08:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|