Return-Path: X-Original-To: apmail-deltacloud-commits-archive@www.apache.org Delivered-To: apmail-deltacloud-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9C8F3E51B for ; Mon, 14 Jan 2013 10:57:52 +0000 (UTC) Received: (qmail 90288 invoked by uid 500); 14 Jan 2013 10:57:52 -0000 Delivered-To: apmail-deltacloud-commits-archive@deltacloud.apache.org Received: (qmail 90264 invoked by uid 500); 14 Jan 2013 10:57:52 -0000 Mailing-List: contact commits-help@deltacloud.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@deltacloud.apache.org Delivered-To: mailing list commits@deltacloud.apache.org Received: (qmail 90252 invoked by uid 99); 14 Jan 2013 10:57:52 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Jan 2013 10:57:52 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 76B1019F7D; Mon, 14 Jan 2013 10:57:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mfojtik@apache.org To: commits@deltacloud.apache.org X-Mailer: ASF-Git Admin Mailer Subject: git commit: CIMI: Added database support for MachineImage Message-Id: <20130114105751.76B1019F7D@tyr.zones.apache.org> Date: Mon, 14 Jan 2013 10:57:51 +0000 (UTC) Updated Branches: refs/heads/master 3ebe770fd -> d3e5972a7 CIMI: Added database support for MachineImage * Properties and description are now stored in database * ImageLocation is now reported correctly * Creation time is now reported correctly Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/d3e5972a Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/d3e5972a Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/d3e5972a Branch: refs/heads/master Commit: d3e5972a744d6e52ee566d4648bc970f5eef8e79 Parents: 3ebe770 Author: Michal Fojtik Authored: Thu Jan 3 11:58:26 2013 +0100 Committer: Michal fojtik Committed: Mon Jan 14 11:47:59 2013 +0100 ---------------------------------------------------------------------- server/lib/cimi/models/machine_image.rb | 31 +++++++++++++++++++++----- server/support/cimi/machine_image.xml | 7 ++++++ 2 files changed, 32 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/deltacloud/blob/d3e5972a/server/lib/cimi/models/machine_image.rb ---------------------------------------------------------------------- diff --git a/server/lib/cimi/models/machine_image.rb b/server/lib/cimi/models/machine_image.rb index b10ef7e..b521b49 100644 --- a/server/lib/cimi/models/machine_image.rb +++ b/server/lib/cimi/models/machine_image.rb @@ -38,27 +38,46 @@ class CIMI::Model::MachineImage < CIMI::Model::Base end def self.from_image(image, context) + stored_attributes = load_attributes_for(image) self.new( - :name => image.id, :id => context.machine_image_url(image.id), + :name => stored_attributes[:name] || image.id, + :description => stored_attributes[:description] || image.description, :state => image.state || 'UNKNOWN', :type => "IMAGE", - :description => image.description, - :created => Time.now.xmlschema, - :image_location => "#{context.driver.name}://#{image.id}" # FIXME + :created => image.creation_time.nil? ? Time.now.xmlschema : Time.parse(image.creation_time.to_s).xmlschema, + :image_location => (stored_attributes[:property] && stored_attributes[:property]['image_location']) ? + stored_attributes[:property].delete('image_location') : 'unknown', + :property => stored_attributes[:property] ) end def self.create(request_body, context) - type = context.grab_content_type(context.request.content_type, request_body) - input = (type == :xml)? XmlSimple.xml_in(request_body.read, {"ForceArray"=>false,"NormaliseSpace"=>2}) : JSON.parse(request_body.read) + # The 'imageLocation' attribute is mandatory in CIMI, however in Deltacloud + # there is no way how to figure out from what Machine the MachineImage was + # created from. For that we need to store this attribute in properties. + # + if context.grab_content_type(context.request.content_type, request_body) == :xml + input = XmlSimple.xml_in(request_body.read, {"ForceArray"=>false,"NormaliseSpace"=>2}) + raise 'imageLocation attribute is mandatory' unless input['imageLocation'] + input['property'] ||= {} + input['property'].kind_of?(Array) ? + input['property'] << { 'image_location' => input['imageLocation'] } : input['property'].merge!('image_location' => input['imageLocation']) + else + input = JSON.parse(request_body.read) + raise 'imageLocation attribute is mandatory' unless input['imageLocation'] + input['properties'] ||= [] + input['properties'] << { 'image_location' => input['imageLocation'] } + end params = {:id => context.href_id(input["imageLocation"], :machines), :name=>input["name"], :description=>input["description"]} image = context.driver.create_image(context.credentials, params) + store_attributes_for(image, input) from_image(image, context) end def self.delete!(image_id, context) context.driver.destroy_image(context.credentials, image_id) + delete_attributes_for(::Image.new(:id => image_id)) end end http://git-wip-us.apache.org/repos/asf/deltacloud/blob/d3e5972a/server/support/cimi/machine_image.xml ---------------------------------------------------------------------- diff --git a/server/support/cimi/machine_image.xml b/server/support/cimi/machine_image.xml new file mode 100644 index 0000000..8ec28a6 --- /dev/null +++ b/server/support/cimi/machine_image.xml @@ -0,0 +1,7 @@ + + myMachineImage1 + Description of my new Machine + IMAGE + http://localhost:3001/cimi/machines/inst1 + image_value +