incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject svn commit: r1087831 - in /incubator/deltacloud/trunk: client/lib/client_bucket_methods.rb client/lib/deltacloud.rb server/server.rb
Date Fri, 01 Apr 2011 17:48:57 GMT
Author: marios
Date: Fri Apr  1 17:48:57 2011
New Revision: 1087831

URL: http://svn.apache.org/viewvc?rev=1087831&view=rev
Log:
Adds (ruby) client methods for working with buckets+blobs - create/destroy and get blob content.

Added:
    incubator/deltacloud/trunk/client/lib/client_bucket_methods.rb
Modified:
    incubator/deltacloud/trunk/client/lib/deltacloud.rb
    incubator/deltacloud/trunk/server/server.rb

Added: incubator/deltacloud/trunk/client/lib/client_bucket_methods.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client/lib/client_bucket_methods.rb?rev=1087831&view=auto
==============================================================================
--- incubator/deltacloud/trunk/client/lib/client_bucket_methods.rb (added)
+++ incubator/deltacloud/trunk/client/lib/client_bucket_methods.rb Fri Apr  1 17:48:57 2011
@@ -0,0 +1,52 @@
+module ClientBucketMethods
+
+  def create_bucket(params)
+    obj = nil
+    request(:post, "#{api_uri.to_s}/buckets", {:name => params['id'] }) do |response|
+      handle_backend_error(response) if response.code!=201
+      obj = base_object(:bucket, response)
+    end
+  end
+
+  def destroy_bucket(params)
+    #actually response here is 204 - no content - so nothing returned to client?
+    request(:delete, "#{api_uri.to_s}/buckets/#{params['id']}") do |response|
+      response
+    end
+  end
+
+  def create_blob(params)
+    blob = nil
+    resource = RestClient::Resource.new("#{api_uri.to_s}/buckets/#{params[:bucket]}", :open_timeout
=> 10, :timeout => 45)
+    headers = default_headers.merge(extended_headers)
+    unless params['metadata'].nil?
+      metadata_headers = {}
+      params['metadata'].each   do |k,v|
+        metadata_headers["X-Deltacloud-Blobmeta-#{k}"] = v
+      end
+      headers = headers.merge(metadata_headers)
+    end
+    resource.send(:post, {:blob_data => File.new(params['file_path'], 'rb'), :blob_id
=> params[:id]}, headers) do |response, request, block|
+      handle_backend_error(response) if response.code.eql?(500)
+      blob = base_object(:blob, response)
+      yield blob if block_given?
+    end
+    return blob
+  end
+
+  def destroy_blob(params)
+    request(:delete, "#{api_uri.to_s}/buckets/#{params['bucket']}/#{params[:id]}") do |response|
+      response
+    end
+  end
+
+  #RestClient doesn't do streaming 'get' yet - we already opened a pull request on this see
+  #https://github.com/archiloque/rest-client/issues/closed#issue/62 - apparently its going
to
+  #be in the next version - unknown when. For now get full response. FIXME
+  def blob_data(params)
+    request(:get, "#{api_uri.to_s}/buckets/#{params['bucket']}/#{params[:id]}/content") do
|response|
+      response
+    end
+  end
+
+end
\ No newline at end of file

Modified: incubator/deltacloud/trunk/client/lib/deltacloud.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client/lib/deltacloud.rb?rev=1087831&r1=1087830&r2=1087831&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client/lib/deltacloud.rb (original)
+++ incubator/deltacloud/trunk/client/lib/deltacloud.rb Fri Apr  1 17:48:57 2011
@@ -20,11 +20,11 @@ require 'nokogiri'
 require 'rest_client'
 require 'base64'
 require 'logger'
-
 require 'hwp_properties'
 require 'instance_state'
 require 'documentation'
 require 'base_object'
+require 'client_bucket_methods'
 
 module DeltaCloud
 
@@ -95,6 +95,9 @@ module DeltaCloud
       @features, @entry_points = {}, {}
       @verbose = opts[:verbose] || false
       discover_entry_points
+      if entry_points.include?(:buckets)
+        extend(ClientBucketMethods)
+      end
       yield self if block_given?
     end
 

Modified: incubator/deltacloud/trunk/server/server.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/server.rb?rev=1087831&r1=1087830&r2=1087831&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/server.rb (original)
+++ incubator/deltacloud/trunk/server/server.rb Fri Apr  1 17:48:57 2011
@@ -728,9 +728,9 @@ delete '/api/buckets/:bucket/:blob' do
   blob_id = params[:blob]
   driver.delete_blob(credentials, bucket_id, blob_id)
   respond_to do |format|
-    format.xml { return 204 }
-    format.json { return 204 }
-    format.html { return bucket_url(bucket_id) }
+    format.xml {  204 }
+    format.json {  204 }
+    format.html { bucket_url(bucket_id) }
   end
 end
 
@@ -841,9 +841,9 @@ collection :buckets do
     control do
       driver.delete_bucket(credentials, params[:id], params)
       respond_to do |format|
-        format.xml { return 204 }
-        format.json { return 204 }
-        format.html { return redirect(buckets_url) }
+        format.xml { 204 }
+        format.json {  204 }
+        format.html {  redirect(buckets_url) }
       end
     end
   end



Mime
View raw message