Return-Path: Delivered-To: apmail-incubator-deltacloud-dev-archive@minotaur.apache.org Received: (qmail 99933 invoked from network); 25 Nov 2010 14:56:07 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 25 Nov 2010 14:56:07 -0000 Received: (qmail 33010 invoked by uid 500); 25 Nov 2010 14:56:07 -0000 Delivered-To: apmail-incubator-deltacloud-dev-archive@incubator.apache.org Received: (qmail 32999 invoked by uid 500); 25 Nov 2010 14:56:07 -0000 Mailing-List: contact deltacloud-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: deltacloud-dev@incubator.apache.org Delivered-To: mailing list deltacloud-dev@incubator.apache.org Received: (qmail 32991 invoked by uid 99); 25 Nov 2010 14:56:07 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 Nov 2010 14:56:06 +0000 X-ASF-Spam-Status: No, hits=-5.0 required=10.0 tests=RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of mandreou@redhat.com designates 209.132.183.28 as permitted sender) Received: from [209.132.183.28] (HELO mx1.redhat.com) (209.132.183.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 Nov 2010 14:55:59 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oAPEtbWR027935 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 25 Nov 2010 09:55:37 -0500 Received: from marios.redhat.com (vpn2-11-222.ams2.redhat.com [10.36.11.222]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oAPEtRwI009463 for ; Thu, 25 Nov 2010 09:55:33 -0500 From: mandreou@redhat.com To: deltacloud-dev@incubator.apache.org Subject: [PATCH] Adds create blob and delete blob operations for blobstore API: Date: Thu, 25 Nov 2010 16:54:42 +0200 Message-Id: <1290696882-4711-2-git-send-email-mandreou@redhat.com> In-Reply-To: <1290696882-4711-1-git-send-email-mandreou@redhat.com> References: <1290696882-4711-1-git-send-email-mandreou@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Virus-Checked: Checked by ClamAV on apache.org From: marios * 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). --- 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