diff --git a/lib/fog/hp/models/compute/image.rb b/lib/fog/hp/models/compute/image.rb index f79867c74..18a4277c5 100644 --- a/lib/fog/hp/models/compute/image.rb +++ b/lib/fog/hp/models/compute/image.rb @@ -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 diff --git a/lib/fog/hp/models/compute/images.rb b/lib/fog/hp/models/compute/images.rb index 84e235f88..941ed958a 100644 --- a/lib/fog/hp/models/compute/images.rb +++ b/lib/fog/hp/models/compute/images.rb @@ -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 diff --git a/lib/fog/hp/requests/compute/create_image.rb b/lib/fog/hp/requests/compute/create_image.rb index 358adda2e..7765e9fe2 100644 --- a/lib/fog/hp/requests/compute/create_image.rb +++ b/lib/fog/hp/requests/compute/create_image.rb @@ -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 +