mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[openstack|image] Refactor Dynamic Methods on Image Model
-removed method missing, added location attr for image upload
This commit is contained in:
parent
be19ce2073
commit
f67a186902
5 changed files with 23 additions and 3 deletions
|
@ -27,11 +27,11 @@ module Fog
|
|||
attribute :min_ram
|
||||
attribute :owner
|
||||
attribute :properties
|
||||
attribute :location
|
||||
|
||||
|
||||
def initialize(attributes)
|
||||
@connection = attributes[:connection]
|
||||
attributes[:size] ||= 0
|
||||
super
|
||||
end
|
||||
|
||||
|
|
|
@ -42,6 +42,18 @@ module Fog
|
|||
end
|
||||
end
|
||||
|
||||
def find_by_size_min(size)
|
||||
find_attribute(__method__, size)
|
||||
end
|
||||
|
||||
def find_by_size_max(size)
|
||||
find_attribute(__method__, size)
|
||||
end
|
||||
|
||||
def find_attribute(attribute,value)
|
||||
attribute = attribute.to_s.gsub("find_by_", "")
|
||||
load(connection.list_public_images_detailed(attribute , value).body['images'])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,6 +7,7 @@ module Fog
|
|||
|
||||
|
||||
data = {
|
||||
"Content-Type"=>"application/octet-stream",
|
||||
"x-image-meta-name" => attributes[:name],
|
||||
"x-image-meta-disk-format" => attributes[:disk_format],
|
||||
"x-image-meta-container-format" => attributes[:container_format],
|
||||
|
@ -15,6 +16,12 @@ module Fog
|
|||
"x-image-meta-owner" => attributes[:owner]
|
||||
}
|
||||
|
||||
body = String.new
|
||||
if attributes[:location]
|
||||
file = File.open(attributes[:location], "rb")
|
||||
body = file.read
|
||||
end
|
||||
|
||||
unless attributes[:properties].nil?
|
||||
attributes[:properties].each do |key,value|
|
||||
data["x-image-meta-property-#{key}"] = value
|
||||
|
@ -25,6 +32,7 @@ module Fog
|
|||
|
||||
request(
|
||||
:headers => data,
|
||||
:body => body,
|
||||
:expects => 201,
|
||||
:method => 'POST',
|
||||
:path => "images"
|
||||
|
|
|
@ -5,7 +5,7 @@ module Fog
|
|||
def list_public_images_detailed(attribute=nil, query=nil)
|
||||
|
||||
if attribute
|
||||
path = "images/detail?#{attribute}=#{query}"
|
||||
path = "images/detail?#{attribute}=#{URI::encode(query)}"
|
||||
else
|
||||
path = 'images/detail'
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ Shindo.tests('Fog::Image[:openstack] | image requests', ['openstack']) do
|
|||
@image_format = {
|
||||
'id' => String,
|
||||
'name' => String,
|
||||
'size' => Integer,
|
||||
'size' => Fog::Nullable::Integer,
|
||||
'disk_format' => Fog::Nullable::String,
|
||||
'container_format' => Fog::Nullable::String,
|
||||
'checksum' => Fog::Nullable::String,
|
||||
|
|
Loading…
Reference in a new issue