You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by ma...@redhat.com on 2011/11/24 17:37:22 UTC

[PATCH 1/2] CIMI::Volume to cimi/server.rb

From: marios <ma...@redhat.com>


Signed-off-by: marios <ma...@redhat.com>
---
 server/lib/cimi/server.rb |   39 +++++++++++----------------------------
 1 files changed, 11 insertions(+), 28 deletions(-)

diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
index 2bd3a39..85fa2f6 100644
--- a/server/lib/cimi/server.rb
+++ b/server/lib/cimi/server.rb
@@ -213,44 +213,27 @@ global_collection :machines do
 end
 
 global_collection :volumes do
-  description 'List all volumes'
+  description "Volume represents storage at either the block or file-system level. Volumes can be attached to Machines. Once attached, Volumes can be accessed by processes on that Machine"
 
   operation :index do
     description "List all volumes"
     control do
-      instances = driver.send(:storage_volumes, credentials, {})
-      @dmtf_col_items = []
-      if instances
-        instances.map do |instance|
-          new_item = { "name" => instance.id,
-            "href" => volume_url(instance.id) }
-          @dmtf_col_items.insert 0,  new_item
-        end
+      volumes = Volume.all(self)
+      respond_to do |format|
+        format.xml { volumes.to_xml_cimi_collection(self) }
+        format.json { volumes.to_json_cimi_collection(self) }
       end
-      respond_to_collection "volume.col.xml"
     end
   end
 
   operation :show do
-    description "Show specific machine."
-    with_capability :storage_volume
-    param :id,          :string,    :required
+    description "Show specific Volume."
+    param :id, :string, :required
     control do
-      @volume = driver.send(:storage_volume, credentials, { :id => params[:id]} )
-      if @volume
-        #setup the default values for a machine imageion
-        resource_default = get_resource_default "volume"
-        #get the actual values from image
-        resource_value = { "name" => @volume.id,
-          "status" => @volume.state, "uri" => @volume.id,
-          "href" => volume_url(@volume.id),
-          "capacity" => { "quantity" => @volume.capacity, "units" => "gigabyte"} }
-        #mixin actual values get from the specific image
-        @dmtfitem = resource_default["dmtfitem"].merge resource_value
-        show_resource "volumes/show", "Volume",
-          {"property" => "properties", "operation" => "operations"}
-      else
-        report_error(404)
+      volume = Volume.find(params[:id], self)
+      respond_to do |format|
+        format.xml  { volume.to_xml  }
+        format.json { volume.to_json }
       end
     end
   end
-- 
1.7.6.4


[PATCH 2/2] Adds find&conversion methods to CIMI::Volume model

Posted by ma...@redhat.com.
From: marios <ma...@redhat.com>


Signed-off-by: marios <ma...@redhat.com>
---
 server/lib/cimi/model/volume.rb |   31 ++++++++++++++++++++++++++++++-
 1 files changed, 30 insertions(+), 1 deletions(-)

diff --git a/server/lib/cimi/model/volume.rb b/server/lib/cimi/model/volume.rb
index ed80903..4bdd6ca 100644
--- a/server/lib/cimi/model/volume.rb
+++ b/server/lib/cimi/model/volume.rb
@@ -27,8 +27,37 @@ class CIMI::Model::Volume < CIMI::Model::Base
   array :meters do
     scalar :ref
   end
-  scalar :eventlog
+  href :eventlog
   array :operations do
     scalar :rel, :href
   end
+
+  def self.find(id, _self)
+    volumes = []
+    opts = ( id == :all ) ? {} : { :id => id }
+    volumes = self.driver.storage_volumes(_self.credentials, opts)
+    volumes.collect!{ |volume| from_storage_volume(volume, _self) }
+    return volumes.first unless volumes.length > 1
+    return volumes
+  end
+
+  def self.all(_self); find(:all, _self); end
+
+  private
+
+  def self.from_storage_volume(volume, _self)
+    self.new( { :name => volume.id,
+                :description => volume.id,
+                :created => volume.created,
+                :uri => _self.volume_url(volume.id),
+                :capacity => { :quantity=>volume.capacity, :units=>"gibibyte"  }, #FIXME... units will vary
+                :bootable => "false", #fixme ... will vary... ec2 doesn't expose this
+                :supports_snapshots => "true", #fixme, will vary (true for ec2)
+                :snapshots => [], #fixme...
+                :guest_interface => "",
+                :eventlog => {:href=> "http://eventlogs"},
+                :meters => []
+            } )
+  end
+
 end
-- 
1.7.6.4