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/25 13:07:50 UTC

[PATCH 2/2] Adds find and convert methods to CIMI::VolumeImage

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


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

diff --git a/server/lib/cimi/model/volume_image.rb b/server/lib/cimi/model/volume_image.rb
index ee35d16..0ebfb01 100644
--- a/server/lib/cimi/model/volume_image.rb
+++ b/server/lib/cimi/model/volume_image.rb
@@ -20,4 +20,29 @@ class CIMI::Model::VolumeImage < CIMI::Model::Base
   array :operations do
     scalar :rel, :href
   end
+
+  def self.find(id, _self)
+    storage_snapshots = []
+    opts = ( id==:all  ) ? {}  : { :id=>id }
+    storage_snapshots = self.driver.storage_snapshots(_self.credentials, opts)
+    storage_snapshots.collect!{ |snapshot| from_storage_snapshot(snapshot, _self) }
+    return storage_snapshots.first unless storage_snapshots.length > 1
+    return storage_snapshots
+  end
+
+  def self.all(_self); find(:all, _self); end
+
+  private
+
+  def self.from_storage_snapshot(snapshot, _self)
+    self.new( {
+               :name => snapshot.id,
+               :description => snapshot.id,
+               :created => snapshot.created,
+               :uri => _self.volume_image_url(snapshot.id),
+               :image_location => {:href=>_self.volume_url(snapshot.storage_volume_id)},
+               :bootable => "false"
+            } )
+  end
+
 end
-- 
1.7.6.4