Class: Fog::Image::OpenStack::V2::Images

Inherits:
OpenStack::Collection show all
Defined in:
lib/fog/openstack/models/image_v2/images.rb

Instance Attribute Summary

Attributes inherited from OpenStack::Collection

#response

Instance Method Summary collapse

Methods inherited from OpenStack::Collection

#load_response

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *arguments, &block) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/fog/openstack/models/image_v2/images.rb', line 43

def method_missing(method_sym, *arguments, &block)
  if method_sym.to_s =~ /^find_by_(.*)$/
    load(service.list_images_detailed($1, arguments.first).body['images'])
  else
    super
  end
end

Instance Method Details

#all(options = {}) ⇒ Object



12
13
14
# File 'lib/fog/openstack/models/image_v2/images.rb', line 12

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

#destroy(id) ⇒ Object



38
39
40
41
# File 'lib/fog/openstack/models/image_v2/images.rb', line 38

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

#find_attribute(attribute, value) ⇒ Object



59
60
61
62
# File 'lib/fog/openstack/models/image_v2/images.rb', line 59

def find_attribute(attribute, value)
  attribute = attribute.to_s.gsub("find_by_", "")
  load(service.list_images_detailed(attribute, value).body['images'])
end

#find_by_id(id) ⇒ Object Also known as: get



20
21
22
23
24
# File 'lib/fog/openstack/models/image_v2/images.rb', line 20

def find_by_id(id)
  image_hash = service.get_image_by_id(id).body
  Fog::Image::OpenStack::V2::Image.new(
      image_hash.merge(:service => service))
end

#find_by_size_max(size) ⇒ Object



55
56
57
# File 'lib/fog/openstack/models/image_v2/images.rb', line 55

def find_by_size_max(size)
  find_attribute(__method__, size)
end

#find_by_size_min(size) ⇒ Object



51
52
53
# File 'lib/fog/openstack/models/image_v2/images.rb', line 51

def find_by_size_min(size)
  find_attribute(__method__, size)
end

#privateObject



33
34
35
36
# File 'lib/fog/openstack/models/image_v2/images.rb', line 33

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

#publicObject



28
29
30
31
# File 'lib/fog/openstack/models/image_v2/images.rb', line 28

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

#summary(options = {}) ⇒ Object



16
17
18
# File 'lib/fog/openstack/models/image_v2/images.rb', line 16

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