1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Add implementation for mocks.

This commit is contained in:
Rupak Ganguly 2012-04-04 19:16:04 -04:00
parent 49e4cd0cba
commit 4aae5af040

View file

@ -8,19 +8,19 @@ module Fog
# ==== Parameters # ==== Parameters
# * server_id<~Integer> - Id of server to create image from # * server_id<~Integer> - Id of server to create image from
# * name<~String> - Name of the image # * name<~String> - Name of the image
# * options<~Hash> - A hash of options # * metadata<~Hash> - A hash of metadata options
# * 'ImageType'<~String> - type of the image i.e. Gold # * 'ImageType'<~String> - type of the image i.e. Gold
# * 'ImageVersion'<~String> - version of the image i.e. 2.0 # * 'ImageVersion'<~String> - version of the image i.e. 2.0
# #
# ==== Returns # ==== Returns
# Does not return a response body. # Does not return a response body.
def create_image(server_id, name, options = {}) def create_image(server_id, name, metadata = {})
body = { 'createImage' => body = { 'createImage' =>
{ 'name' => name, { 'name' => name,
'metadata' => 'metadata' =>
{ 'ImageType' => options[:image_type], { 'ImageType' => metadata[:image_type],
'ImageVersion' => options[:image_version] 'ImageVersion' => metadata[:image_version]
} }
} }
} }
@ -31,9 +31,28 @@ module Fog
class Mock class Mock
def create_image(server_id, name, options = {}) def create_image(server_id, name, metadata = {})
response = Excon::Response.new response = Excon::Response.new
response.status = 202 response.status = 202
image_id = Fog::Mock.random_numbers(6).to_s
data = {
'id' => image_id,
'server' => {"id"=>"3", "links"=>[{"href"=>"http://nova1:8774/v1.1/servers/#{server_id}", "rel"=>"bookmark"}]},
'links' => [{"href"=>"http://nova1:8774/v1.1/tenantid/images/#{image_id}", "rel"=>"self"}, {"href"=>"http://nova1:8774/tenantid/images/#{image_id}", "rel"=>"bookmark"}],
'metadata' => metadata || {},
'name' => name || "image_#{rand(999)}",
'progress' => 0,
'status' => 'SAVING',
'updated' => "",
'created' => ""
}
self.data[:last_modified][:images][data['id']] = Time.now
self.data[:images][data['id']] = data
response.headers = {'Content-Length' => '0', 'Content-Type' => 'text/html; charset=UTF-8', 'Date' => Time.now, 'Location' => "http://nova1:8774/v1.1/images/#{@image_id}"}
response.body = "" # { 'image' => data } no data is sent
response response
end end