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:
parent
465b8362c5
commit
2ecb406c08
3 changed files with 26 additions and 55 deletions
|
@ -13,13 +13,11 @@ module Fog
|
||||||
attribute :updated_at, :aliases => 'updated'
|
attribute :updated_at, :aliases => 'updated'
|
||||||
attribute :progress
|
attribute :progress
|
||||||
attribute :status
|
attribute :status
|
||||||
attribute :server_id, :aliases => 'serverId'
|
attribute :minDisk, :aliases => 'min_disk'
|
||||||
|
attribute :minRam, :aliases => 'min_ram'
|
||||||
def server=(new_server)
|
attribute :server, :aliases => 'server'
|
||||||
requires :id
|
#attribute :metadata #TODO: Need to add it back when Metadata API is done
|
||||||
|
attribute :links
|
||||||
self.server_id = new_server.id
|
|
||||||
end
|
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
requires :id
|
requires :id
|
||||||
|
@ -32,15 +30,6 @@ module Fog
|
||||||
status == 'ACTIVE'
|
status == 'ACTIVE'
|
||||||
end
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,7 @@ module Fog
|
||||||
data = connection.list_images_detail.body['images']
|
data = connection.list_images_detail.body['images']
|
||||||
load(data)
|
load(data)
|
||||||
if server
|
if server
|
||||||
self.replace(self.select {|image| image.server_id == server.id})
|
self.replace(self.select {|image| image.server.id == server.id})
|
||||||
end
|
end
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,56 +3,37 @@ module Fog
|
||||||
class HP
|
class HP
|
||||||
class Real
|
class Real
|
||||||
|
|
||||||
# Create an image from a running server
|
# Create an image from an existing server
|
||||||
#
|
#
|
||||||
# ==== Parameters
|
# ==== Parameters
|
||||||
# * server_id<~Integer> - Id of server to create image from
|
# * 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
|
# ==== Returns
|
||||||
# * response<~Excon::Response>:
|
# Does not return a response body.
|
||||||
# * 'image'<~Hash>:
|
|
||||||
# * 'id'<~Integer> - Id of image
|
def create_image(server_id, name, options = {})
|
||||||
# * 'name'<~String> - Name of image
|
body = { 'createImage' =>
|
||||||
# * 'serverRef'<~Integer> - Id of server
|
{ 'name' => name,
|
||||||
def create_image(server_id, options = {})
|
'metadata' =>
|
||||||
data = {
|
{ 'ImageType' => options[:image_type],
|
||||||
'image' => {
|
'ImageVersion' => options[:image_version]
|
||||||
'serverId' => server_id
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if options['name']
|
server_action(server_id, body)
|
||||||
data['image']['name'] = options['name']
|
|
||||||
end
|
|
||||||
request(
|
|
||||||
:body => MultiJson.encode(data),
|
|
||||||
:expects => 200,
|
|
||||||
:method => 'POST',
|
|
||||||
:path => "images"
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
|
|
||||||
def create_image(server_id, options = {})
|
def create_image(server_id, name, options = {})
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
response.status = 200
|
response.status = 202
|
||||||
|
|
||||||
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
|
response
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -60,3 +41,4 @@ module Fog
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue