deltacloud-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=1207878&view=rev
Log:
Adds CIMI::Volume create operation from xml/json body POST

(implements the pass-by-reference of MachineConfiguration)

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=1207878&r1=1207877&r2=1207878&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/volume.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/volume.rb Tue Nov 29 13:34:15 2011
@@ -43,6 +43,13 @@ class CIMI::Model::Volume < CIMI::Model:
 
   def self.all(context); find(:all, context); end
 
+  def self.create(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)
@@ -55,7 +62,7 @@ class CIMI::Model::Volume < CIMI::Model:
                 :supports_snapshots => "true", #fixme, will vary (true for ec2)
                 :snapshots => [], #fixme...
                 :guest_interface => "",
-                :eventlog => {:href=> "http://eventlogs"},
+                :eventlog => {:href=> "http://eventlogs"},#FIXME
                 :meters => []
             } )
   end

Modified: deltacloud/trunk/server/lib/cimi/server.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/server.rb?rev=1207878&r1=1207877&r2=1207878&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/server.rb (original)
+++ deltacloud/trunk/server/lib/cimi/server.rb Tue Nov 29 13:34:15 2011
@@ -223,6 +223,36 @@ global_collection :volumes do
     end
   end
 
+
+  operation :create do
+    description "Create a new Volume."
+    control do
+      content_type = (request.content_type.end_with?("+json") ? :json  : :xml)
+          #((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)
+        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)
+      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 }
+      end
+    end
+  end
+
+
+
+
 end
 
 global_collection :volume_configurations do



Mime
View raw message