2012-02-23 18:57:48 +08:00
|
|
|
require 'fog/core/collection'
|
|
|
|
require 'fog/openstack/models/image/image'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Image
|
|
|
|
class OpenStack
|
|
|
|
class Images < Fog::Collection
|
|
|
|
model Fog::Image::OpenStack::Image
|
|
|
|
|
|
|
|
def all
|
2012-12-22 23:24:36 +00:00
|
|
|
load(service.list_public_images_detailed.body['images'])
|
2012-02-27 20:12:52 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def details
|
2012-12-22 23:24:36 +00:00
|
|
|
load(service.list_public_images_detailed.body['images'])
|
2012-02-27 20:12:52 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def find_by_id(id)
|
2013-07-03 00:30:38 +02:00
|
|
|
all.find {|image| image.id == id}
|
2012-02-28 15:31:19 +08:00
|
|
|
end
|
2013-05-22 23:47:30 +02:00
|
|
|
alias_method :get, :find_by_id
|
2012-02-28 15:31:19 +08:00
|
|
|
|
|
|
|
def public
|
2012-12-22 23:24:36 +00:00
|
|
|
images = load(service.list_public_images_detailed.body['images'])
|
2012-02-28 15:31:19 +08:00
|
|
|
images.delete_if{|image| image.is_public == false}
|
|
|
|
end
|
|
|
|
|
|
|
|
def private
|
2012-12-22 23:24:36 +00:00
|
|
|
images = load(service.list_public_images_detailed.body['images'])
|
2012-02-28 15:31:19 +08:00
|
|
|
images.delete_if{|image| image.is_public}
|
2012-02-27 20:12:52 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy(id)
|
|
|
|
image = self.find_by_id(id)
|
|
|
|
image.destroy
|
2012-02-23 18:57:48 +08:00
|
|
|
end
|
2012-02-23 18:57:48 +08:00
|
|
|
|
2012-02-28 15:31:19 +08:00
|
|
|
def method_missing(method_sym, *arguments, &block)
|
|
|
|
if method_sym.to_s =~ /^find_by_(.*)$/
|
2012-12-22 23:24:36 +00:00
|
|
|
load(service.list_public_images_detailed($1 ,arguments.first).body['images'])
|
2012-02-28 15:31:19 +08:00
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-29 13:48:12 +08:00
|
|
|
def find_by_size_min(size)
|
|
|
|
find_attribute(__method__, size)
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_by_size_max(size)
|
|
|
|
find_attribute(__method__, size)
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_attribute(attribute,value)
|
|
|
|
attribute = attribute.to_s.gsub("find_by_", "")
|
2012-12-22 23:24:36 +00:00
|
|
|
load(service.list_public_images_detailed(attribute , value).body['images'])
|
2012-02-29 13:48:12 +08:00
|
|
|
end
|
2012-02-23 18:57:48 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|