Class: Ogle::Image
- Inherits:
-
Object
- Object
- Ogle::Image
- Defined in:
- lib/ogle/image.rb
Instance Method Summary collapse
-
#all(details = false) ⇒ Object
Returns information about images.
-
#create(name, file, metadata) ⇒ Object
Upload (create) a new image.
-
#destroy(image_id) ⇒ Object
Delete an image.
-
#find(image_id) ⇒ Object
Returns information about the given ‘image_id’.
-
#initialize(connection) ⇒ Image
constructor
A new instance of Image.
-
#runable(details = false) ⇒ Object
Return only runable images.
-
#update(image_id, metadata) ⇒ Object
Update the metadata for an image.
Constructor Details
#initialize(connection) ⇒ Image
Returns a new instance of Image.
36 37 38 |
# File 'lib/ogle/image.rb', line 36 def initialize connection @connection = connection end |
Instance Method Details
#all(details = false) ⇒ Object
Returns information about images.
details
: A Boolean toggling the returning of detailed image information.
46 47 48 49 50 51 52 53 |
# File 'lib/ogle/image.rb', line 46 def all details = false path = details ? "/v1/images/detail" : "/v1/images" response = @connection.get path response.body['images'].collect do |r| ImageData.new r end end |
#create(name, file, metadata) ⇒ Object
Upload (create) a new image.
name
: The name of the file in glance (x-image-meta-name). file
: The file to upload. metadata
: A hash of custom defined metadata to be added to the image (x-image-meta-properties-*).
108 109 110 111 112 113 114 |
# File 'lib/ogle/image.rb', line 108 def create name, file, response = @connection.post "/v1/images", :upload => { :file => file, :headers => { "x-image-meta-name" => name }.merge() } ImageData.new response.body['image'] end |
#destroy(image_id) ⇒ Object
Delete an image.
image_id
: A String representing an image_id.
95 96 97 98 99 |
# File 'lib/ogle/image.rb', line 95 def destroy image_id response = @connection.delete "/v1/images/#{image_id}" Struct::ImageDestroy.new response.code == "200" end |
#find(image_id) ⇒ Object
Returns information about the given ‘image_id’.
image_id
: A String representing an image_id.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ogle/image.rb', line 60 def find image_id response = @connection.head "/v1/images/#{image_id}" ImageData.new( Hash.new.tap do |h| properties = h['properties'] = Hash.new response.each_header do |k, v| case k.downcase.tr '-', '_' when %r{^x_image_meta_property_([a-z_]+)$} properties[$1] = v when %r{^x_image_meta_([a-z_]+)$} h[$1] = v end end end ) end |
#runable(details = false) ⇒ Object
Return only runable images.
details
: A Boolean toggling the returning of detailed image information.
84 85 86 87 88 |
# File 'lib/ogle/image.rb', line 84 def runable details = false all(details).select do |image| runable? image end end |
#update(image_id, metadata) ⇒ Object
Update the metadata for an image
image_id
: A string representing an image_id. metadata
: A hash of custom defined metadata to updated in the image.
122 123 124 125 126 |
# File 'lib/ogle/image.rb', line 122 def update image_id, response = @connection.put "/v1/images/#{image_id}", :headers => ImageData.new response.body['image'] end |