Sha256: 5a27b3e875a5a8a4529b9745349a99688f61eea9d2fa7d1b678f6d898f6d0a57

Contents?: true

Size: 1.74 KB

Versions: 20

Compression:

Stored size: 1.74 KB

Contents

require 'fog/openstack/models/collection'
require 'fog/openstack/image/v2/models/image'

module Fog
  module OpenStack
    class Image
      class V2
        class Images < Fog::OpenStack::Collection
          model Fog::OpenStack::Image::V2::Image

          def all(options = {})
            load_response(service.list_images(options), 'images')
          end

          def summary(options = {})
            load_response(service.list_images(options), 'images')
          end

          def find_by_id(id)
            new(service.get_image_by_id(id).body)
          rescue Fog::OpenStack::Image::NotFound
            nil
          end

          alias get find_by_id

          def public
            images = load(service.list_images.body['images'])
            images.delete_if { |image| image.is_public == false }
          end

          def private
            images = load(service.list_images.body['images'])
            images.delete_if(&:is_public)
          end

          def destroy(id)
            image = find_by_id(id)
            image.destroy
          end

          def method_missing(method_sym, *arguments, &block)
            if method_sym.to_s =~ /^find_by_(.*)$/
              load(service.list_images($1.to_sym => 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_images(attribute.to_sym => value).body['images'])
          end
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 3 rubygems

Version Path
fog-openstack-1.1.3 lib/fog/openstack/image/v2/models/images.rb
fog-openstack-1.1.2 lib/fog/openstack/image/v2/models/images.rb
fog-openstack-fork-99 lib/fog/openstack/image/v2/models/images.rb
fog-openstack-1.1.0 lib/fog/openstack/image/v2/models/images.rb
fog-openstack-1.1.0.pre lib/fog/openstack/image/v2/models/images.rb
fog-openstack-apibank-1.0.102 lib/fog/openstack/image/v2/models/images.rb
fog-openstack-1.0.11 lib/fog/openstack/image/v2/models/images.rb
fog-openstack-apibank-1.0.101 lib/fog/openstack/image/v2/models/images.rb
fog-openstack-1.0.10 lib/fog/openstack/image/v2/models/images.rb
fog-openstack-1.0.9 lib/fog/openstack/image/v2/models/images.rb
fog-openstack-1.0.8 lib/fog/openstack/image/v2/models/images.rb
fog-openstack-1.0.7 lib/fog/openstack/image/v2/models/images.rb
fog-openstack-1.0.6 lib/fog/openstack/image/v2/models/images.rb
fog-openstack-1.0.5 lib/fog/openstack/image/v2/models/images.rb
fog-openstack-1.0.4 lib/fog/openstack/image/v2/models/images.rb
fog-openstack-1.0.3 lib/fog/openstack/image/v2/models/images.rb
fog-openstack-1.0.2 lib/fog/openstack/image/v2/models/images.rb
fog-openstack-1.0.1 lib/fog/openstack/image/v2/models/images.rb
fog-openstack-1.0.0 lib/fog/openstack/image/v2/models/images.rb
fog-openstack-0.3.1 lib/fog/openstack/image/v2/models/images.rb