2010-03-19 21:29:42 -04:00
|
|
|
module Fog
|
|
|
|
module Rackspace
|
2010-09-08 16:50:23 -04:00
|
|
|
class Compute
|
2010-03-19 21:29:42 -04:00
|
|
|
class Real
|
2009-10-16 01:22:27 -04:00
|
|
|
|
|
|
|
# Create an image from a running server
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
|
|
|
# * server_id<~Integer> - Id of server to create image from
|
|
|
|
# * options<~Hash> - Name
|
|
|
|
#
|
2009-11-02 21:47:24 -05:00
|
|
|
# ==== Returns
|
2009-11-02 21:48:49 -05:00
|
|
|
# * response<~Excon::Response>:
|
2009-11-02 21:47:24 -05:00
|
|
|
# * 'image'<~Hash>:
|
|
|
|
# * 'id'<~Integer> - Id of image
|
|
|
|
# * 'name'<~String> - Name of image
|
|
|
|
# * 'serverId'<~Integer> - Id of server
|
2009-10-16 01:22:27 -04:00
|
|
|
def create_image(server_id, options = {})
|
|
|
|
data = {
|
|
|
|
'image' => {
|
2009-10-16 13:26:15 -04:00
|
|
|
'serverId' => server_id
|
2009-10-16 01:22:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if options['name']
|
|
|
|
data['image']['name'] = options['name']
|
|
|
|
end
|
|
|
|
request(
|
|
|
|
:body => data.to_json,
|
|
|
|
:expects => 202,
|
|
|
|
:method => 'POST',
|
|
|
|
:path => "images"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2010-03-19 21:29:42 -04:00
|
|
|
class Mock
|
2009-10-16 01:22:27 -04:00
|
|
|
|
2009-11-20 15:46:44 -05:00
|
|
|
def create_image(server_id, options = {})
|
|
|
|
response = Excon::Response.new
|
|
|
|
response.status = 202
|
|
|
|
|
|
|
|
now = Time.now
|
|
|
|
data = {
|
|
|
|
'created' => now,
|
|
|
|
'id' => 123456,
|
|
|
|
'name' => options['name'] || '',
|
|
|
|
'serverId' => server_id,
|
|
|
|
'status' => 'SAVING',
|
|
|
|
'updated' => now,
|
|
|
|
}
|
|
|
|
|
2010-03-19 21:29:42 -04:00
|
|
|
@data[:last_modified][:images][data['id']] = now
|
|
|
|
@data[:images][data['id']] = data
|
2009-11-20 15:46:44 -05:00
|
|
|
response.body = { 'image' => data.reject {|key, value| !['id', 'name', 'serverId'].include?(key)} }
|
|
|
|
response
|
2009-10-16 01:22:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|