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] Adds create blob and delete blob operations for blobstore API:
Date Thu, 25 Nov 2010 15:05:05 GMT
On 25/11/10 16:54 +0200, mandreou@redhat.com wrote:
>From: marios <marios@redhat.com>
>
> * Functionality is added only for Amazon driver (ie S3) for now - Rackspace, Azure to
follow.
> * Simple upload from client --> deltacloud for now (not stream) but streaming from
deltacloud --> s3
> * Adds appropriate haml for creating blob over html form
> * Uses the sinatra :method_override hack for Delete operation over HTML form (using post).

I tested this patch against S3 and it works perfectly.
I can create a new blob, get it using content and also delete it.
Also content_type is set correctly for me.

ACK && sorry for all inconviences caused by my reckless push.

  -- Michal


>---
> server/lib/deltacloud/base_driver/base_driver.rb |    6 +++
> server/lib/deltacloud/drivers/ec2/ec2_driver.rb  |   26 +++++++++++++
> server/server.rb                                 |   44 ++++++++++++++++++---
> server/views/blobs/new.html.haml                 |   10 +++++
> server/views/blobs/show.html.haml                |   36 ++++++++++-------
> server/views/buckets/show.html.haml              |    5 ++-
> 6 files changed, 104 insertions(+), 23 deletions(-)
> create mode 100644 server/views/blobs/new.html.haml
>
>diff --git a/server/lib/deltacloud/base_driver/base_driver.rb b/server/lib/deltacloud/base_driver/base_driver.rb
>index 61ebc21..4419359 100644
>--- a/server/lib/deltacloud/base_driver/base_driver.rb
>+++ b/server/lib/deltacloud/base_driver/base_driver.rb
>@@ -215,6 +215,12 @@ module Deltacloud
>     def blob_data(credentials, bucket_id, blob_id, opts)
>     end
>
>+    def create_blob(credentials, bucket_id, blob_id, blob_data, opts=nil)
>+    end
>+
>+    def delete_blob(credentials, bucket_id, blob_id, opts=nil)
>+    end
>+
>     def filter_on(collection, attribute, opts)
>       return collection if opts.nil?
>       return collection if opts[attribute].nil?
>diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
>index 723aad6..4800cf8 100644
>--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
>+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
>@@ -401,6 +401,32 @@ class EC2Driver < Deltacloud::BaseDriver
>     end
>   end
>
>+#--
>+# Create Blob
>+#--
>+  def create_blob(credentials, bucket_id, blob_id, data = nil, opts = nil)
>+    s3_client = s3_client(credentials)
>+    #data is a construct with the temporary file created by server @.tempfile
>+    #also file[:type] will give us the content-type
>+    res = s3_client.interface.put(bucket_id, blob_id, data.tempfile, {"Content-Type"
=> data[:type]})
>+    #create a new Blob object and return that
>+    Blob.new( { :id => blob_id,
>+                :bucket => bucket_id,
>+                :content_length => data.tempfile.length,
>+                :content_type => data[:type],
>+                :last_modified => ''
>+              }
>+            )
>+  end
>+
>+#--
>+# Delete Blob
>+#--
>+  def delete_blob(credentials, bucket_id, blob_id, opts=nil)
>+    s3_client = s3_client(credentials)
>+    s3_client.interface.delete(bucket_id, blob_id)
>+  end
>+
>   def load_balancer(credentials, opts={})
>     load_balancers(credentials, {
>       :load_balancer_names => [opts[:id]]
>diff --git a/server/server.rb b/server/server.rb
>index 5ccf9f6..d3f7d8a 100644
>--- a/server/server.rb
>+++ b/server/server.rb
>@@ -458,6 +458,35 @@ collection :keys do
>
> end
>
>+#get html form for creating a new blob
>+get '/api/buckets/:bucket/new_blob' do
>+  @bucket_id = params[:bucket]
>+  respond_to do |format|
>+    format.html {haml :"blobs/new"}
>+  end
>+end
>+
>+#create a new blob
>+post '/api/buckets/:bucket' do
>+  bucket_id = params[:bucket]
>+  blob_id = params['blob_id']
>+  blob_data = params['blob_data']
>+  @blob = driver.create_blob(credentials, bucket_id, blob_id, blob_data )
>+  respond_to do |format|
>+    format.html { haml :"blobs/show"}
>+    format.xml { haml :"blobs/show" }
>+  end
>+end
>+
>+#delete a blob
>+delete '/api/buckets/:bucket/:blob' do
>+  bucket_id = params[:bucket]
>+  blob_id = params[:blob]
>+  driver.delete_blob(credentials, bucket_id, blob_id)
>+  redirect(bucket_url(bucket_id))
>+end
>+
>+#Get a particular blob's particulars (not actual blob data)
> get '/api/buckets/:bucket/:blob' do
>   @blob = driver.blob(credentials, { :id => params[:blob], 'bucket' => params[:bucket]})
>   if @blob
>@@ -471,13 +500,7 @@ get '/api/buckets/:bucket/:blob' do
>   end
> end
>
>-get '/api/buckets/new' do
>-  respond_to do |format|
>-    format.html { haml :"buckets/new" }
>-  end
>-end
>-
>-
>+#get the content of a particular blob
> get '/api/buckets/:bucket/:blob/content' do
>   @blob = driver.blob(credentials, { :id => params[:blob], 'bucket' => params[:bucket]})
>   params['content_length'] = @blob.content_length
>@@ -485,6 +508,13 @@ get '/api/buckets/:bucket/:blob/content' do
>   BlobStream.call(env, credentials, params)
> end
>
>+#Get html form for creating a new bucket
>+get '/api/buckets/new' do
>+  respond_to do |format|
>+    format.html { haml :"buckets/new" }
>+  end
>+end
>+
> collection :buckets do
>   description "Cloud Storage buckets - aka buckets|directories|folders"
>
>diff --git a/server/views/blobs/new.html.haml b/server/views/blobs/new.html.haml
>new file mode 100644
>index 0000000..feb94e5
>--- /dev/null
>+++ b/server/views/blobs/new.html.haml
>@@ -0,0 +1,10 @@
>+%h1 New Blob
>+
>+%form{ :action => bucket_url(@bucket_id), :method => :post, :enctype => 'multipart/form-data'}
>+  %label
>+    Blob Name:
>+    %input{ :name => 'blob_id', :size => 512}/
>+    Blob Data:
>+    %input{ :type => "file", :name => 'blob_data',  :size => 50}/
>+    %br
>+  %input{ :type => :submit, :name => "commit", :value => "create"}/
>diff --git a/server/views/blobs/show.html.haml b/server/views/blobs/show.html.haml
>index 66c9fb1..e5c2cee 100644
>--- a/server/views/blobs/show.html.haml
>+++ b/server/views/blobs/show.html.haml
>@@ -3,18 +3,24 @@
>   = @blob.id
>
> %dl
>-  %dt bucket
>-  %dd
>-    = @blob.bucket
>-  %dt Content_Length
>-  %dd
>-    = @blob.content_length
>-  %dt Content_Type
>-  %dd
>-    = @blob.content_type
>-  %dt Last_Modified
>-  %dd
>-    = @blob.last_modified
>-  %dt Content
>-  %dd
>-    =link_to 'Blob content', bucket_url(@blob.bucket) + '/' + @blob.id + '/content'
>+  %di
>+    %dt Bucket
>+    %dd
>+      = @blob.bucket
>+    %dt Content_Length
>+    %dd
>+      = @blob.content_length
>+    %dt Content_Type
>+    %dd
>+      = @blob.content_type
>+    %dt Last_Modified
>+    %dd
>+      = @blob.last_modified
>+    %dt Content
>+    %dd
>+      =link_to 'Blob content', bucket_url(@blob.bucket) + '/' + @blob.id + '/content'
>+    %dt Delete this Blob
>+    %dd
>+      %form{ :action => bucket_url(@blob.bucket) + '/' + @blob.id , :method =>
:post }
>+        %input{ :type => "hidden", :name => "_method", :value => "delete"}
>+        %input{ :type => :submit, :value => "Delete"}/
>diff --git a/server/views/buckets/show.html.haml b/server/views/buckets/show.html.haml
>index d704867..5b5457a 100644
>--- a/server/views/buckets/show.html.haml
>+++ b/server/views/buckets/show.html.haml
>@@ -14,6 +14,9 @@
>     %dd
>       -@bucket.blob_list.each do |blob|
>         = link_to blob, bucket_url(@bucket.name) + '/' + blob
>-    %dt delete bucket (must be empty)
>+    %dt Delete bucket (must be empty)
>     %dd
>       =link_to 'Delete', destroy_bucket_url(@bucket.name), :class => 'delete'
>+    %dt Create a new blob
>+    %dd
>+      =link_to 'Create Blob', bucket_url(@bucket.name) + '/new_blob'
>\ No newline at end of file
>--
>1.7.2.3
>

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

Mime
View raw message