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

Inherits:
OpenStack::Collection show all
Defined in:
lib/fog/image/openstack/v2/models/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


40
41
42
43
44
45
46
# File 'lib/fog/image/openstack/v2/models/images.rb', line 40

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

Instance Method Details

#all(options = {}) ⇒ Object


11
12
13
# File 'lib/fog/image/openstack/v2/models/images.rb', line 11

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

#destroy(id) ⇒ Object


35
36
37
38
# File 'lib/fog/image/openstack/v2/models/images.rb', line 35

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

#find_attribute(attribute, value) ⇒ Object


56
57
58
59
# File 'lib/fog/image/openstack/v2/models/images.rb', line 56

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

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


19
20
21
# File 'lib/fog/image/openstack/v2/models/images.rb', line 19

def find_by_id(id)
  new(service.get_image_by_id(id).body)
end

#find_by_size_max(size) ⇒ Object


52
53
54
# File 'lib/fog/image/openstack/v2/models/images.rb', line 52

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

#find_by_size_min(size) ⇒ Object


48
49
50
# File 'lib/fog/image/openstack/v2/models/images.rb', line 48

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

#privateObject


30
31
32
33
# File 'lib/fog/image/openstack/v2/models/images.rb', line 30

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

#publicObject


25
26
27
28
# File 'lib/fog/image/openstack/v2/models/images.rb', line 25

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

#summary(options = {}) ⇒ Object


15
16
17
# File 'lib/fog/image/openstack/v2/models/images.rb', line 15

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