deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@redhat.com
Subject [PATCH 2/2] Adds find and convert methods to CIMI::VolumeImage
Date Fri, 25 Nov 2011 12:07:50 GMT
From: marios <marios@redhat.com>


Signed-off-by: marios <marios@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


Mime
View raw message