incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michal Fojtik <mfoj...@redhat.com>
Subject Re: [PATCH 1/2] Adds (ruby) client methods for working with buckets+blobs - create/destroy and get blob content.
Date Thu, 31 Mar 2011 14:21:26 GMT
On Mar 29, 2011, at 9:39 PM, marios@redhat.com wrote:

ACK, just small inline Ruby comment below.

  -- Michal

> From: marios <marios@redhat.com>
> 
> ---
> client/lib/client_bucket_methods.rb |   52 +++++++++++++++++++++++++++++++++++
> client/lib/deltacloud.rb            |    5 +++-
> server/server.rb                    |   12 ++++----
> 3 files changed, 62 insertions(+), 7 deletions(-)
> create mode 100644 client/lib/client_bucket_methods.rb
> 
> diff --git a/client/lib/client_bucket_methods.rb b/client/lib/client_bucket_methods.rb
> new file mode 100644
> index 0000000..3a2e12b
> --- /dev/null
> +++ b/client/lib/client_bucket_methods.rb
> @@ -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)

You can also use:

headers.merge!(metadate_headers) here.

> +    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
> diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb
> index 7f9ec9c..1095163 100644
> --- a/client/lib/deltacloud.rb
> +++ b/client/lib/deltacloud.rb
> @@ -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
> 
> diff --git a/server/server.rb b/server/server.rb
> index 3c4273c..dcc2260 100644
> --- a/server/server.rb
> +++ b/server/server.rb
> @@ -698,9 +698,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
> 
> @@ -811,9 +811,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
> -- 
> 1.7.3.4
> 

------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org


Mime
View raw message