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']
|
connection.get_image_members(self.id).body['members']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def metadata
|
||||||
|
requires :id
|
||||||
|
connection.get_image(self.id).headers
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,9 +16,17 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_by_id(id)
|
def find_by_id(id)
|
||||||
self.find {|image| image.id == id} ||
|
self.find {|image| image.id == id}
|
||||||
Fog::Image::OpenStack::Image.new(
|
end
|
||||||
connection.get_image(id).body['image'])
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
def destroy(id)
|
def destroy(id)
|
||||||
|
@ -26,6 +34,14 @@ module Fog
|
||||||
image.destroy
|
image.destroy
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,11 +2,18 @@ module Fog
|
||||||
module Image
|
module Image
|
||||||
class OpenStack
|
class OpenStack
|
||||||
class Real
|
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(
|
request(
|
||||||
:expects => [200, 204],
|
:expects => [200, 204],
|
||||||
:method => 'GET',
|
:method => 'GET',
|
||||||
:path => 'images/detail'
|
:path => path
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end # class Real
|
end # class Real
|
||||||
|
|
|
@ -12,6 +12,10 @@ Shindo.tests("Fog::Image[:openstack] | image", ['openstack']) do
|
||||||
@instance.name == 'edit test image'
|
@instance.name == 'edit test image'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
tests('#get image metadata').succeeds do
|
||||||
|
@instance.metadata
|
||||||
|
end
|
||||||
|
|
||||||
tests('#add member').succeeds do
|
tests('#add member').succeeds do
|
||||||
@instance.add_member(@instance.owner)
|
@instance.add_member(@instance.owner)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue