deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1207912 - in /deltacloud/trunk/server/lib/cimi: model/machine.rb server.rb
Date Tue, 29 Nov 2011 15:31:15 GMT
Author: mfojtik
Date: Tue Nov 29 15:31:14 2011
New Revision: 1207912

URL: http://svn.apache.org/viewvc?rev=1207912&view=rev
Log:
CIMI: Added methods for accessing Machine entities

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

Modified: deltacloud/trunk/server/lib/cimi/model/machine.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/machine.rb?rev=1207912&r1=1207911&r2=1207912&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/machine.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/machine.rb Tue Nov 29 15:31:14 2011
@@ -54,4 +54,16 @@ class CIMI::Model::Machine < CIMI::Model
     scalar :rel, :href
   end
 
+  def self.find(id, _self)
+    instances = []
+    if id == :all
+      instances = _self.driver.instances(_self.credentials)
+      instances.map { |instance| from_instance(instance, _self) }.compact
+    else
+      instance = _self.driver.instance(_self.credentials, id)
+      from_instance(instance, _self)
+    end
+  end
+
+
 end

Modified: deltacloud/trunk/server/lib/cimi/server.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/server.rb?rev=1207912&r1=1207911&r2=1207912&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/server.rb (original)
+++ deltacloud/trunk/server/lib/cimi/server.rb Tue Nov 29 15:31:14 2011
@@ -159,16 +159,11 @@ global_collection :machines do
   operation :index do
     description "List all machines"
     control do
-      instances = driver.send(:instances, credentials, {})
-      @dmtf_col_items = []
-      if instances
-        instances.map do |instance|
-          new_item = { "name" => instance.name,
-            "href" => machine_url(instance.id) }
-          @dmtf_col_items.insert 0,  new_item
-        end
+      machines = Machine.all(self)
+      respond_to do |format|
+        format.xml { machines.to_xml_cimi_collection(self) }
+        format.json { machines.to_json_cimi_collection(self) }
       end
-      respond_to_collection "machine.col.xml"
     end
   end
 
@@ -177,20 +172,10 @@ global_collection :machines do
     with_capability :instance
     param :id,          :string,    :required
     control do
-      @machine = driver.send(:instance, credentials, { :id => params[:id]} )
-      if @machine
-        #setup the default values for a machine imageion
-        resource_default = get_resource_default "machine"
-        #get the actual values from image
-        resource_value = { "name" => @machine.name,
-          "status" => @machine.state, "uri" => @machine.id,
-          "href" => machine_url(@machine.id) }
-        #mixin actual values get from the specific image
-        @dmtfitem = resource_default["dmtfitem"].merge resource_value
-        show_resource "machines/show", "Machine",
-          {"property" => "properties", "disk" => "disks", "operation" => "operations"}
-      else
-        report_error(404)
+      machine = Machine.find(params[:id], self)
+      respond_to do |format|
+        format.xml { machine.to_xml }
+        format.json { machine.to_json }
       end
     end
   end



Mime
View raw message