mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[openstack|image] Image Model Updates
-added dynamic finders -added queries for public and private images -added function to show image metadata
This commit is contained in:
parent
1db7605986
commit
be19ce2073
4 changed files with 37 additions and 5 deletions
|
@ -73,6 +73,11 @@ module Fog
|
|||
connection.get_image_members(self.id).body['members']
|
||||
end
|
||||
|
||||
def metadata
|
||||
requires :id
|
||||
connection.get_image(self.id).headers
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,9 +16,17 @@ module Fog
|
|||
end
|
||||
|
||||
def find_by_id(id)
|
||||
self.find {|image| image.id == id} ||
|
||||
Fog::Image::OpenStack::Image.new(
|
||||
connection.get_image(id).body['image'])
|
||||
self.find {|image| image.id == id}
|
||||
end
|
||||
|
||||
def public
|
||||
images = load(connection.list_public_images_detailed.body['images'])
|
||||
images.delete_if{|image| image.is_public == false}
|
||||
end
|
||||
|
||||
def private
|
||||
images = load(connection.list_public_images_detailed.body['images'])
|
||||
images.delete_if{|image| image.is_public}
|
||||
end
|
||||
|
||||
def destroy(id)
|
||||
|
@ -26,6 +34,14 @@ module Fog
|
|||
image.destroy
|
||||
end
|
||||
|
||||
def method_missing(method_sym, *arguments, &block)
|
||||
if method_sym.to_s =~ /^find_by_(.*)$/
|
||||
load(connection.list_public_images_detailed($1 ,arguments.first).body['images'])
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,11 +2,18 @@ module Fog
|
|||
module Image
|
||||
class OpenStack
|
||||
class Real
|
||||
def list_public_images_detailed
|
||||
def list_public_images_detailed(attribute=nil, query=nil)
|
||||
|
||||
if attribute
|
||||
path = "images/detail?#{attribute}=#{query}"
|
||||
else
|
||||
path = 'images/detail'
|
||||
end
|
||||
|
||||
request(
|
||||
:expects => [200, 204],
|
||||
:method => 'GET',
|
||||
:path => 'images/detail'
|
||||
:path => path
|
||||
)
|
||||
end
|
||||
end # class Real
|
||||
|
|
|
@ -12,6 +12,10 @@ Shindo.tests("Fog::Image[:openstack] | image", ['openstack']) do
|
|||
@instance.name == 'edit test image'
|
||||
end
|
||||
|
||||
tests('#get image metadata').succeeds do
|
||||
@instance.metadata
|
||||
end
|
||||
|
||||
tests('#add member').succeeds do
|
||||
@instance.add_member(@instance.owner)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue