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 18:27:19 UTC

[PATCH 5/5] Adds create operation to CIMI::Volume model

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


Signed-off-by: marios <ma...@redhat.com>
---
 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


Re: [PATCH 5/5] Adds create operation to CIMI::Volume model

Posted by Michal Fojtik <mf...@redhat.com>.
On Nov 25, 2011, at 6:27 PM, marios@redhat.com wrote:

> From: marios <ma...@redhat.com>
> 
> 
> Signed-off-by: marios <ma...@redhat.com>
> ---
> 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)

I think it would be better to split this method to:

def self.create_from_json(params, _self)
def self.create_from_xml(params, _self)

This two could return an array so:

data, volume_config_id, volume_image_id = create_from_json

def self.create(params, _self)

What do you think?


------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org