deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1207787 - in /deltacloud/trunk/server/lib/cimi: model/machine_image.rb server.rb
Date Tue, 29 Nov 2011 08:39:12 GMT
Author: mfojtik
Date: Tue Nov 29 08:39:11 2011
New Revision: 1207787

URL: http://svn.apache.org/viewvc?rev=1207787&view=rev
Log:
CIMI: Added MachineImage model

Modified:
    deltacloud/trunk/server/lib/cimi/model/machine_image.rb
    deltacloud/trunk/server/lib/cimi/server.rb

Modified: deltacloud/trunk/server/lib/cimi/model/machine_image.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/machine_image.rb?rev=1207787&r1=1207786&r2=1207787&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/machine_image.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/machine_image.rb Tue Nov 29 08:39:11 2011
@@ -21,4 +21,25 @@ class CIMI::Model::MachineImage < CIMI::
   array :operations do
     scalar :rel, :href
   end
+
+  def self.find(id, _self)
+    images = []
+    if id == :all
+      images = _self.driver.images(_self.credentials)
+      images.map { |image| from_image(image, _self) }
+    else
+      image = _self.driver.image(_self.credentials, id)
+      from_image(image, _self)
+    end
+  end
+
+  def self.from_image(image, _self)
+    self.new(
+      :name => image.id,
+      :uri => _self.machine_image_url(image.id),
+      :description => image.description,
+      :image_location => { :href => "#{_self.driver.name}://#{image.id}" } # FIXME
+    )
+  end
+
 end

Modified: deltacloud/trunk/server/lib/cimi/server.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/server.rb?rev=1207787&r1=1207786&r2=1207787&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/server.rb (original)
+++ deltacloud/trunk/server/lib/cimi/server.rb Tue Nov 29 08:39:11 2011
@@ -130,16 +130,11 @@ global_collection :machine_images do
   operation :index do
     description "List all machine configurations"
     control do
-      images = driver.send(:images, credentials, {})
-      @dmtf_col_items = []
-      if images
-        images.map do |image|
-          new_item = { "name" => image.name,
-            "href" => machine_image_url(image.id) }
-          @dmtf_col_items.insert 0,  new_item
-        end
+      machine_images = MachineImage.all(self)
+      respond_to do |format|
+        format.xml { machine_images.to_xml_cimi_collection(self) }
+        format.json { machine_images.to_json_cimi_collection(self) }
       end
-      respond_to_collection "machine_image.col.xml"
     end
   end
 
@@ -148,20 +143,10 @@ global_collection :machine_images do
     with_capability :image
     param :id,          :string,    :required
     control do
-      @image = driver.send(:image, credentials, { :id => params[:id]} )
-      if @image
-        #setup the default values for a machine imageion
-        resource_default = get_resource_default "machine_image"
-        #get the actual values from image
-        resource_value = { "name" => @image.name,
-          "description" => @image.description,
-          "uri" => @image.id,"href" => machine_image_url(@image.id) }
-        #mixin actual values get from the specific image
-        @dmtfitem = resource_default["dmtfitem"].merge resource_value
-        show_resource "machine_images/show", "MachineImage",
-          {"property" => "properties", "operation" => "operations"}
-      else
-        report_error(404)
+      machine_image = MachineImage.find(params[:id], self)
+      respond_to do |format|
+        format.xml { machine_image.to_xml }
+        format.json { machine_image.to_json }
       end
     end
   end



Mime
View raw message