1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/openstack/models/image/images.rb
Ladislav Smola 00cd1524fa Fog::OpenStack::Collection base class for all openstack collections
Fog::OpenStack::Collection base class for all openstack collections,
also replacing load method with load_response method, which stores
the whole response on Collection object, in the case that we need
other medata e.g. for pagination.

Also removing :summary and :find_by_id aliases, since they are
defined in base method.
2015-07-15 13:30:56 +02:00

67 lines
2 KiB
Ruby

require 'fog/openstack/models/collection'
require 'fog/openstack/models/image/image'
module Fog
module Image
class OpenStack
class Images < Fog::OpenStack::Collection
model Fog::Image::OpenStack::Image
def all(options = {})
load_response(service.list_public_images_detailed(options), 'images')
end
def summary(options = {})
load_response(service.list_public_images(options), 'images')
end
def details(options = {}, deprecated_query = nil)
Fog::Logger.deprecation("Calling OpenStack[:glance].images.details will be removed, "\
" call .images.all for detailed list.")
load_response(service.list_public_images_detailed(options, deprecated_query), 'images')
end
def find_by_id(id)
all.find {|image| image.id == id}
end
alias_method :get, :find_by_id
def public
images = load(service.list_public_images_detailed.body['images'])
images.delete_if{|image| image.is_public == false}
end
def private
images = load(service.list_public_images_detailed.body['images'])
images.delete_if{|image| image.is_public}
end
def destroy(id)
image = self.find_by_id(id)
image.destroy
end
def method_missing(method_sym, *arguments, &block)
if method_sym.to_s =~ /^find_by_(.*)$/
load(service.list_public_images_detailed($1 ,arguments.first).body['images'])
else
super
end
end
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_", "")
load(service.list_public_images_detailed(attribute , value).body['images'])
end
end
end
end
end