deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 21/51] Core: Fixed couple errors and typos in buckets/blobs code
Date Mon, 21 May 2012 10:07:02 GMT
From: Michal Fojtik <mfojtik@redhat.com>


Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/lib/deltacloud/collections/buckets.rb       |   84 +++++++++++---------
 server/lib/deltacloud/drivers/mock/mock_driver.rb  |    6 +-
 server/lib/deltacloud/helpers/deltacloud_helper.rb |    2 +
 server/lib/deltacloud/helpers/url_helper.rb        |    7 +-
 server/lib/deltacloud/models/bucket.rb             |    4 +
 server/views/buckets/new.html.haml                 |    2 +-
 6 files changed, 60 insertions(+), 45 deletions(-)

diff --git a/server/lib/deltacloud/collections/buckets.rb b/server/lib/deltacloud/collections/buckets.rb
index 044bd6a..3a5591d 100644
--- a/server/lib/deltacloud/collections/buckets.rb
+++ b/server/lib/deltacloud/collections/buckets.rb
@@ -18,8 +18,53 @@ module Deltacloud::Collections
     check_capability :for => lambda { |m| driver.respond_to? m }
     check_features :for => lambda { |c, f| driver.class.has_feature?(c, f) }
 
+    get route_for('/buckets/new') do
+      respond_to do |format|
+        format.html { haml :"buckets/new" }
+      end
+    end
+
+    get route_for('/buckets/:bucket/%s' % NEW_BLOB_FORM_ID) do
+      @bucket_id = params[:bucket]
+      respond_to do |format|
+        format.html {haml :"blobs/new"}
+      end
+    end
+
     collection :buckets do
 
+      standard_show_operation
+      standard_index_operation
+
+      operation :create, :with_capability => :create_bucket do
+        param :name,      :string,    :required
+        control do
+          @bucket = driver.create_bucket(credentials, params[:name], params)
+          status 201
+          response['Location'] = bucket_url(@bucket.id)
+          respond_to do |format|
+            format.xml  { haml :"buckets/show" }
+            format.json { convert_to_json(:bucket, @bucket) }
+            format.html do
+              redirect bucket_url(@bucket.id) if @bucket and @bucket.id
+              redirect buckets_url
+            end
+          end
+        end
+      end
+
+      operation :destroy, :with_capability => :delete_bucket do
+        control do
+          driver.delete_bucket(credentials, params[:id], params)
+          status 204
+          respond_to do |format|
+            format.xml
+            format.json
+            format.html {  redirect(buckets_url) }
+          end
+        end
+      end
+
       collection :blobs, :with_id => :blob_id, :no_member => true do
 
         operation :show, :with_capability => :blob do
@@ -115,7 +160,6 @@ module Deltacloud::Collections
             end
           end
         end
-
         action :metadata, :http_method => :head, :with_capability => :blob_metadata
do
           control do
             @blob_id = params[:blob]
@@ -168,46 +212,8 @@ module Deltacloud::Collections
             end
           end
         end
-
-      end
-
-      get route_for('/buckets/new') do
-        respond_to do |format|
-          format.html { haml :"buckets/new" }
-        end
       end
 
-      standard_show_operation
-      standard_index_operation
-
-      operation :create, :with_capability => :create_bucket do
-        param :name,      :string,    :required
-        control do
-          @bucket = driver.create_bucket(credentials, params[:name], params)
-          status 201
-          response['Location'] = bucket_url(@bucket.id)
-          respond_to do |format|
-            format.xml  { haml :"buckets/show" }
-            format.json { convert_to_json(:bucket, @bucket) }
-            format.html do
-              redirect bucket_url(@bucket.id) if @bucket and @bucket.id
-              redirect buckets_url
-            end
-          end
-        end
-      end
-
-      operation :destroy, :with_capability => :delete_bucket do
-        control do
-          driver.delete_bucket(credentials, params[:id], params)
-          status 204
-          respond_to do |format|
-            format.xml
-            format.json
-            format.html {  redirect(buckets_url) }
-          end
-        end
-      end
 
     end
 
diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index cd7534b..ba817c6 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -367,7 +367,7 @@ module Deltacloud::Drivers::Mock
       check_credentials(credentials)
       bucket = bucket(credentials, {:id => name})
       raise 'BucketNotExist' if bucket.nil?
-      raise "BucketNotEmpty" unless (bucket and bucket.size == "0")
+      raise "BucketNotEmpty" unless bucket.blob_list.empty?
       @client.destroy(:buckets, bucket.id)
     end
 
@@ -427,7 +427,7 @@ module Deltacloud::Drivers::Mock
     #--
     def blob_metadata(credentials, opts={})
       check_credentials(credentials)
-      if blob = @client.load(:blobs, params[:id])
+      if blob = @client.load(:blobs, opts[:id])
         blob[:user_metadata]
       else
         nil
@@ -440,7 +440,7 @@ module Deltacloud::Drivers::Mock
     def update_blob_metadata(credentials, opts={})
       check_credentials(credentials)
       safely do
-        blob = @client.load(:blobs, params[:id])
+        blob = @client.load(:blobs, opts[:id])
         return false unless blob
         blob[:user_metadata] = BlobHelper::rename_metadata_headers(opts['meta_hash'], '')
         @client.store(:blobs, blob)
diff --git a/server/lib/deltacloud/helpers/deltacloud_helper.rb b/server/lib/deltacloud/helpers/deltacloud_helper.rb
index 83741f9..ee9decc 100644
--- a/server/lib/deltacloud/helpers/deltacloud_helper.rb
+++ b/server/lib/deltacloud/helpers/deltacloud_helper.rb
@@ -230,6 +230,8 @@ module Deltacloud::Helpers
       end
     end
 
+    NEW_BLOB_FORM_ID = 'new_blob_form_d15cfd90'
+
     def new_blob_form_url(bucket)
       bucket_url(@bucket.name) + "/" + NEW_BLOB_FORM_ID
     end
diff --git a/server/lib/deltacloud/helpers/url_helper.rb b/server/lib/deltacloud/helpers/url_helper.rb
index 87bc93e..fd71f43 100644
--- a/server/lib/deltacloud/helpers/url_helper.rb
+++ b/server/lib/deltacloud/helpers/url_helper.rb
@@ -33,8 +33,11 @@ module Sinatra
       if name.to_s =~ /^([\w\_]+)_url$/
         if args.size > 0
           t = $1
-          if t =~ /^(stop|reboot|destroy|start|attach|detach)_/
-            api_url_for(t.pluralize.split('_').last + '/' + args.first + '/' + $1, :full)
+          if t.match(/^(stop|reboot|start|attach|detach)_/)
+            action = $1
+            api_url_for(t.pluralize.split('_').last + '/' + args.first + '/' + action, :full)
+          elsif t.match(/^(destroy|update)_/)
+            api_url_for(t.pluralize.split('_').last + '/' + args.first, :full)
           else
             api_url_for(t.pluralize, :full) + '/' + "#{args.first}"
           end
diff --git a/server/lib/deltacloud/models/bucket.rb b/server/lib/deltacloud/models/bucket.rb
index b1551b7..0c21c21 100644
--- a/server/lib/deltacloud/models/bucket.rb
+++ b/server/lib/deltacloud/models/bucket.rb
@@ -22,6 +22,10 @@ class Bucket < BaseModel
 
   alias :to_hash_original :to_hash
 
+  def blob_list
+    @blob_list || []
+  end
+
   def to_hash
     h = self.to_hash_original
     unless blob_list.nil?
diff --git a/server/views/buckets/new.html.haml b/server/views/buckets/new.html.haml
index 2abaa96..bc0f0c3 100644
--- a/server/views/buckets/new.html.haml
+++ b/server/views/buckets/new.html.haml
@@ -6,7 +6,7 @@
       Bucket Name:
       %input{ :name => 'name', :size => 250}/
       %br
-    -if driver_has_feature?(:bucket_location, :buckets)
+    -if driver.class.has_feature?(:bucket_location, :buckets)
       %p
         %label
           Location: (optional)
-- 
1.7.10.1


Mime
View raw message