mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Add implementation for #create_image service.
This commit is contained in:
parent
b5d397ee8a
commit
417eba912c
1 changed files with 62 additions and 0 deletions
62
lib/fog/compute/requests/hp/create_image.rb
Normal file
62
lib/fog/compute/requests/hp/create_image.rb
Normal file
|
@ -0,0 +1,62 @@
|
|||
module Fog
|
||||
module HP
|
||||
class Compute
|
||||
class Real
|
||||
|
||||
# Create an image from a running server
|
||||
#
|
||||
# ==== Parameters
|
||||
# * server_id<~Integer> - Id of server to create image from
|
||||
# * options<~Hash> - Name
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * 'image'<~Hash>:
|
||||
# * 'id'<~Integer> - Id of image
|
||||
# * 'name'<~String> - Name of image
|
||||
# * 'serverRef'<~Integer> - Id of server
|
||||
def create_image(server_id, options = {})
|
||||
data = {
|
||||
'image' => {
|
||||
'serverRef' => server_id
|
||||
}
|
||||
}
|
||||
if options['name']
|
||||
data['image']['name'] = options['name']
|
||||
end
|
||||
request(
|
||||
:body => data.to_json,
|
||||
:expects => 200,
|
||||
:method => 'POST',
|
||||
:path => "images"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def create_image(server_id, options = {})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
now = Time.now
|
||||
data = {
|
||||
'created' => now,
|
||||
'id' => Fog::Mock.random_numbers(6).to_i,
|
||||
'name' => options['name'] || '',
|
||||
'serverRef' => server_id,
|
||||
'status' => 'SAVING',
|
||||
'updated' => now.to_s,
|
||||
}
|
||||
|
||||
self.data[:last_modified][:images][data['id']] = now
|
||||
self.data[:images][data['id']] = data
|
||||
response.body = { 'image' => data.reject {|key, value| !['id', 'name', 'serverRef', 'status', 'updated'].include?(key)} }
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue