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

Update image and images model, and create_image call now uses server_action. Behavior change in Diablo 4.

This commit is contained in:
Rupak Ganguly 2011-11-02 15:13:18 -04:00
parent 465b8362c5
commit 2ecb406c08
3 changed files with 26 additions and 55 deletions

View file

@ -13,13 +13,11 @@ module Fog
attribute :updated_at, :aliases => 'updated'
attribute :progress
attribute :status
attribute :server_id, :aliases => 'serverId'
def server=(new_server)
requires :id
self.server_id = new_server.id
end
attribute :minDisk, :aliases => 'min_disk'
attribute :minRam, :aliases => 'min_ram'
attribute :server, :aliases => 'server'
#attribute :metadata #TODO: Need to add it back when Metadata API is done
attribute :links
def destroy
requires :id
@ -32,15 +30,6 @@ module Fog
status == 'ACTIVE'
end
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
requires :server_id
data = connection.create_image(server_id, 'name' => name)
merge_attributes(data.body['image'])
true
end
end
end

View file

@ -15,7 +15,7 @@ module Fog
data = connection.list_images_detail.body['images']
load(data)
if server
self.replace(self.select {|image| image.server_id == server.id})
self.replace(self.select {|image| image.server.id == server.id})
end
self
end

View file

@ -3,56 +3,37 @@ module Fog
class HP
class Real
# Create an image from a running server
# Create an image from an existing server
#
# ==== Parameters
# * server_id<~Integer> - Id of server to create image from
# * options<~Hash> - Name
# * name<~String> - Name of the image
# * options<~Hash> - A hash of options
# * 'ImageType'<~String> - type of the image i.e. Gold
# * 'ImageVersion'<~String> - version of the image i.e. 2.0
#
# ==== 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' => {
'serverId' => server_id
}
}
if options['name']
data['image']['name'] = options['name']
end
request(
:body => MultiJson.encode(data),
:expects => 200,
:method => 'POST',
:path => "images"
)
# Does not return a response body.
def create_image(server_id, name, options = {})
body = { 'createImage' =>
{ 'name' => name,
'metadata' =>
{ 'ImageType' => options[:image_type],
'ImageVersion' => options[:image_version]
}
}
}
server_action(server_id, body)
end
end
class Mock
def create_image(server_id, options = {})
def create_image(server_id, name, 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'] || '',
'serverId' => 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', 'serverId', 'status', 'updated'].include?(key)} }
response.status = 202
response
end
@ -60,3 +41,4 @@ module Fog
end
end
end