deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject git commit: CIMI: Added database support for MachineImage
Date Mon, 14 Jan 2013 10:57:51 GMT
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 <mfojtik@redhat.com>
Authored: Thu Jan 3 11:58:26 2013 +0100
Committer: Michal fojtik <mfojtik@redhat.com>
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 @@
+<MachineImageCreate>
+  <name>myMachineImage1</name>
+  <description>Description of my new Machine</description>
+  <type>IMAGE</type>
+  <imageLocation>http://localhost:3001/cimi/machines/inst1</imageLocation>
+  <property key="test_image">image_value</property>
+</MachineImageCreate>


Mime
View raw message