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 :min_ram
|
||||||
attribute :owner
|
attribute :owner
|
||||||
attribute :properties
|
attribute :properties
|
||||||
|
attribute :location
|
||||||
|
|
||||||
|
|
||||||
def initialize(attributes)
|
def initialize(attributes)
|
||||||
@connection = attributes[:connection]
|
@connection = attributes[:connection]
|
||||||
attributes[:size] ||= 0
|
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,18 @@ module Fog
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,6 +7,7 @@ module Fog
|
||||||
|
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
|
"Content-Type"=>"application/octet-stream",
|
||||||
"x-image-meta-name" => attributes[:name],
|
"x-image-meta-name" => attributes[:name],
|
||||||
"x-image-meta-disk-format" => attributes[:disk_format],
|
"x-image-meta-disk-format" => attributes[:disk_format],
|
||||||
"x-image-meta-container-format" => attributes[:container_format],
|
"x-image-meta-container-format" => attributes[:container_format],
|
||||||
|
@ -15,6 +16,12 @@ module Fog
|
||||||
"x-image-meta-owner" => attributes[:owner]
|
"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?
|
unless attributes[:properties].nil?
|
||||||
attributes[:properties].each do |key,value|
|
attributes[:properties].each do |key,value|
|
||||||
data["x-image-meta-property-#{key}"] = value
|
data["x-image-meta-property-#{key}"] = value
|
||||||
|
@ -25,6 +32,7 @@ module Fog
|
||||||
|
|
||||||
request(
|
request(
|
||||||
:headers => data,
|
:headers => data,
|
||||||
|
:body => body,
|
||||||
:expects => 201,
|
:expects => 201,
|
||||||
:method => 'POST',
|
:method => 'POST',
|
||||||
:path => "images"
|
:path => "images"
|
||||||
|
|
|
@ -5,7 +5,7 @@ module Fog
|
||||||
def list_public_images_detailed(attribute=nil, query=nil)
|
def list_public_images_detailed(attribute=nil, query=nil)
|
||||||
|
|
||||||
if attribute
|
if attribute
|
||||||
path = "images/detail?#{attribute}=#{query}"
|
path = "images/detail?#{attribute}=#{URI::encode(query)}"
|
||||||
else
|
else
|
||||||
path = 'images/detail'
|
path = 'images/detail'
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ Shindo.tests('Fog::Image[:openstack] | image requests', ['openstack']) do
|
||||||
@image_format = {
|
@image_format = {
|
||||||
'id' => String,
|
'id' => String,
|
||||||
'name' => String,
|
'name' => String,
|
||||||
'size' => Integer,
|
'size' => Fog::Nullable::Integer,
|
||||||
'disk_format' => Fog::Nullable::String,
|
'disk_format' => Fog::Nullable::String,
|
||||||
'container_format' => Fog::Nullable::String,
|
'container_format' => Fog::Nullable::String,
|
||||||
'checksum' => Fog::Nullable::String,
|
'checksum' => Fog::Nullable::String,
|
||||||
|
|
Loading…
Reference in a new issue