incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1124262 - in /incubator/deltacloud/trunk/server: lib/deltacloud/helpers/conversion_helper.rb lib/deltacloud/models/bucket.rb server.rb
Date Wed, 18 May 2011 13:37:52 GMT
Author: mfojtik
Date: Wed May 18 13:37:51 2011
New Revision: 1124262

URL: http://svn.apache.org/viewvc?rev=1124262&view=rev
Log:
Fixed DTACLOUD-40: Missing JSON response after create calls

Modified:
    incubator/deltacloud/trunk/server/lib/deltacloud/helpers/conversion_helper.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/models/bucket.rb
    incubator/deltacloud/trunk/server/server.rb

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/helpers/conversion_helper.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/helpers/conversion_helper.rb?rev=1124262&r1=1124261&r2=1124262&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/helpers/conversion_helper.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/helpers/conversion_helper.rb Wed May
18 13:37:51 2011
@@ -19,7 +19,7 @@ require 'deltacloud/base_driver'
 module ConversionHelper
 
   def convert_to_json(type, obj)
-    if ( [ :image, :realm, :instance, :storage_volume, :storage_snapshot, :hardware_profile
].include?( type ) )
+    if ( [ :image, :realm, :instance, :storage_volume, :storage_snapshot, :hardware_profile,
:key, :bucket, :address ].include?( type ) )
       if Array.eql?(obj.class)
         data = obj.collect do |o|
           o.to_hash.merge({ :href => self.send(:"#{type}_url", type.eql?(:hardware_profile)
? o.name : o.id ) })

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/models/bucket.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/models/bucket.rb?rev=1124262&r1=1124261&r2=1124262&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/models/bucket.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/models/bucket.rb Wed May 18 13:37:51
2011
@@ -20,4 +20,11 @@ class Bucket < BaseModel
   attr_accessor :size
   attr_accessor :blob_list
 
+  alias :to_hash_original :to_hash
+
+  def to_hash
+    h = self.to_hash_original
+    h[:blob_list] = self.blob_list.collect { |blob| { :id => blob, :href => "/api/buckets/#{self.id}/#{blob.id}"}}
+    return h
+  end
 end

Modified: incubator/deltacloud/trunk/server/server.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/server.rb?rev=1124262&r1=1124261&r2=1124262&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/server.rb (original)
+++ incubator/deltacloud/trunk/server/server.rb Wed May 18 13:37:51 2011
@@ -205,6 +205,7 @@ END
           response.status = 201 # Created
           haml :"images/show"
         end
+        format.json { convert_to_json(:image, @image) }
         format.html { haml :"images/show" }
       end
     end
@@ -314,6 +315,7 @@ collection :load_balancers do
           response.status = 201  # Created
           haml :"load_balancers/show"
         end
+        format.json { convert_to_json(:load_balancer, @load_balancer) }
         format.html { haml :"load_balancers/show" }
       end
     end
@@ -390,6 +392,7 @@ END
           response['Location'] = instance_url(@instance.id)
           haml :"instances/show"
         end
+        format.json { convert_to_json(:instance, @instance) }
         format.html do
           redirect instance_url(@instance.id) if @instance and @instance.id
           redirect instances_url
@@ -579,6 +582,7 @@ collection :storage_volumes do
       @storage_volume = driver.create_storage_volume(credentials, params)
       respond_to do |format|
         format.html { haml :"storage_volumes/show" }
+        format.json { convert_to_json(:storage_volume, @storage_volume) }
         format.xml do
           response.status = 201  # Created
           haml :"storage_volumes/show"
@@ -663,6 +667,7 @@ collection :keys do
           response.status = 201  # Created
           haml :"keys/show", :ugly => true
         end
+        format.json { convert_to_json(:key, @key)}
       end
     end
   end
@@ -816,14 +821,17 @@ collection :buckets do
     control do
       @bucket = driver.create_bucket(credentials, params[:name], params)
       respond_to do |format|
+        format.html do
+          redirect bucket_url(@bucket.id) if @bucket and @bucket.id
+          redirect buckets_url
+        end
         format.xml do
           response.status = 201  # Created
           response['Location'] = bucket_url(@bucket.id)
           haml :"buckets/show"
         end
-        format.html do
-          redirect bucket_url(@bucket.id) if @bucket and @bucket.id
-          redirect buckets_url
+        format.json do
+          convert_to_json(:bucket, @bucket)
         end
       end
     end
@@ -878,6 +886,7 @@ collection :addresses do
       @address = driver.create_address(credentials, {})
       respond_to do |format|
         format.html { haml :"addresses/show" }
+        format.json { convert_to_json(:address, @address) }
         format.xml do
           response.status = 201  # Created
           response['Location'] = address_url(@address.id)



Mime
View raw message