From: marios <[email protected]>

Signed-off-by: marios <[email protected]>
---
 server/lib/cimi/model/volume.rb |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/server/lib/cimi/model/volume.rb b/server/lib/cimi/model/volume.rb
index 4bdd6ca..695546d 100644
--- a/server/lib/cimi/model/volume.rb
+++ b/server/lib/cimi/model/volume.rb
@@ -43,6 +43,23 @@ class CIMI::Model::Volume < CIMI::Model::Base
 
   def self.all(_self); find(:all, _self); end
 
+  def self.create(params, _self)
+    case params[:content_type]
+      when :json
+        json = JSON.parse(_self.request.body.read)
+        volume_config_id = 
json["volumeTemplate"]["volumeConfig"]["href"].split("/").last
+        volume_image_id = (json["volumeTemplate"].has_key?("volumeImage") ? 
json["volumeTemplate"]["volumeImage"]["href"].split("/").last  : nil)
+      when :xml
+        xml = XmlSimple.xml_in(_self.request.body.read)
+        volume_config_id = 
xml["volumeTemplate"][0]["volumeConfig"][0]["href"].split("/").last
+        volume_image_id = (xml["volumeTemplate"][0].has_key?("volumeImage") ? 
xml["volumeTemplate"][0]["volumeImage"][0]["href"].split("/").last  : nil)
+    end
+    volume_config = VolumeConfiguration.find(volume_config_id, _self)
+    opts = {:capacity=>volume_config.capacity[:quantity], 
:snapshot_id=>volume_image_id }
+    storage_volume = self.driver.create_storage_volume(_self.credentials, opts)
+    from_storage_volume(storage_volume, _self)
+  end
+
   private
 
   def self.from_storage_volume(volume, _self)
-- 
1.7.6.4

Reply via email to