deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject svn commit: r1213671 - in /deltacloud/trunk/server/lib/cimi: model/volume.rb server.rb
Date Tue, 13 Dec 2011 13:15:06 GMT
Author: marios
Date: Tue Dec 13 13:15:06 2011
New Revision: 1213671

URL: http://svn.apache.org/viewvc?rev=1213671&view=rev
Log:
Tidy up CIMI::Volume creation code

Modified:
    deltacloud/trunk/server/lib/cimi/model/volume.rb
    deltacloud/trunk/server/lib/cimi/server.rb

Modified: deltacloud/trunk/server/lib/cimi/model/volume.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/volume.rb?rev=1213671&r1=1213670&r2=1213671&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/volume.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/volume.rb Tue Dec 13 13:15:06 2011
@@ -44,15 +44,31 @@ class CIMI::Model::Volume < CIMI::Model:
 
   def self.all(context); find(:all, context); end
 
-  def self.create(params, context)
+  def self.create_from_json(json_in, context)
+    json = JSON.parse(json_in)
+    volume_config_id = json["volumeTemplate"]["volumeConfig"]["href"].split("/").last
+    volume_image_id = (json["volumeTemplate"].has_key?("volumeImage") ?
+                json["volumeTemplate"]["volumeImage"]["href"].split("/").last  : nil)
+    create_volume({:volume_config_id=>volume_config_id, :volume_image_id=>volume_image_id},
context)
+  end
+
+  def self.create_from_xml(xml_in, context)
+    xml = XmlSimple.xml_in(xml_in)
+    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)
+    create_volume({:volume_config_id=>volume_config_id, :volume_image_id=>volume_image_id},
context)
+  end
+
+  private
+
+  def self.create_volume(params, context)
     volume_config = VolumeConfiguration.find(params[:volume_config_id], context)
     opts = {:capacity=>volume_config.capacity[:quantity], :snapshot_id=>params[:volume_image_id]
}
     storage_volume = self.driver.create_storage_volume(context.credentials, opts)
     from_storage_volume(storage_volume, context)
   end
 
-  private
-
   def self.from_storage_volume(volume, context)
     self.new( { :name => volume.id,
                 :description => volume.id,

Modified: deltacloud/trunk/server/lib/cimi/server.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/server.rb?rev=1213671&r1=1213670&r2=1213671&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/server.rb (original)
+++ deltacloud/trunk/server/lib/cimi/server.rb Tue Dec 13 13:15:06 2011
@@ -345,18 +345,10 @@ global_collection :volumes do
           #((request.content_type.end_with?("+xml")) ? :xml : report_error(415) ) FIXME
       case content_type
         when :json
-          json = JSON.parse(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)
+          new_volume = Volume.create_from_json(request.body.read, self)
         when :xml
-          xml = XmlSimple.xml_in(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)
+          new_volume = Volume.create_from_xml(request.body.read, self)
       end
-      params.merge!( {:volume_config_id => volume_config_id, :volume_image_id => volume_image_id}
)
-      new_volume = Volume.create(params, self)
       respond_to do |format|
         format.json { new_volume.to_json }
         format.xml { new_volume.to_xml }



Mime
View raw message