On Nov 25, 2011, at 6:27 PM, [email protected] wrote:

> 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)

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, [email protected]
Deltacloud API: http://deltacloud.org

Reply via email to