You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by ma...@redhat.com on 2010/08/16 18:44:48 UTC

['PATCH'] Basic BlobStore functions - update ec2 driver methods to use right_aws s3 gem instead of aws s3 gem

From: marios <ma...@redhat.com>

---
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb |   33 ++++++++++++-----------
 1 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index 5ad745b..313872c 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -19,8 +19,8 @@
 
 require 'deltacloud/base_driver'
 require 'AWS'
-require 'aws/s3' #FIXME NEED A NEW S3 GEM  Amazon gem has issues with European buckets (some kind of naming/addressing problem)... 
-
+#require 'aws/s3' #FIXME NEED A NEW S3 GEM  Amazon gem has issues with European buckets (some kind of naming/addressing problem)... 
+require 'right_aws'
 class Instance
   attr_accessor :keyname
   attr_accessor :authn_error
@@ -283,8 +283,8 @@ class EC2Driver < Deltacloud::BaseDriver
 #-- get back a list of your buckets from the s3 service
   def containers(credentials, opts)
     container_list = []
-    s3_connect(credentials) #establish a connection with the S3 service
-    bucket_list = AWS::S3::Service.buckets
+    s3_client = s3_client(credentials)
+    bucket_list = s3_client.buckets
     bucket_list.each do |current|
       container_list << convert_storage_container(current)
     end
@@ -299,10 +299,10 @@ class EC2Driver < Deltacloud::BaseDriver
     unless opts['container'] then
       raise Deltacloud::Validation::Failure.new(Deltacloud::Validation::Param.new(["container"]), "Error - need container name to retrieve the blob list. You said bucket->#{opts['container']}.")
     end
-    s3_connect(credentials)
-    s3_bucket = AWS::S3::Bucket.find(opts['container'])
+    s3_client = s3_client(credentials)
+    s3_bucket = s3_client.bucket(opts['container'])
     blobs = []
-    s3_bucket.objects.each do |s3_object|
+    s3_bucket.keys({}, true).each do |s3_object|
       blobs << convert_storage_object(s3_object)
     end
     blobs = filter_on(blobs, :id, opts)
@@ -427,31 +427,32 @@ class EC2Driver < Deltacloud::BaseDriver
     } )
   end
 
-  def s3_connect(credentials)
-    AWS::S3::Base.establish_connection!(:access_key_id => credentials.user, :secret_access_key => credentials.password)
+  def s3_client(credentials)
+     s3_client = RightAws::S3.new(credentials.user, credentials.password)
+     s3_client
   end
 
   def convert_storage_container(s3_bucket)
     #get blob list:
     blob_list = []
-    s3_bucket.objects.each do |s3_object|
-      blob_list << s3_object.key
+    s3_bucket.keys.each do |s3_object|
+      blob_list << s3_object.name
     end
     #can use AWS::S3::Owner.current.display_name or current.id
     Container.new(  { :id => s3_bucket.name, 
                       :name => s3_bucket.name,
-                      :size => s3_bucket.size,
+                      :size => s3_bucket.keys.length,
                       :blob_list => blob_list
                     }
                  )
   end
 
   def convert_storage_object(s3_object)
-    Blob.new({   :id => s3_object.key,
+    Blob.new({   :id => s3_object.name,
                  :container => s3_object.bucket.name.to_s,
-                 :content_length => s3_object.about['content-length'],
-                 :content_type => s3_object.about['content-type'],
-                 :last_modified => s3_object.about['last-modified']
+                 :content_length => s3_object.size,
+                 :content_type => s3_object.content_type,
+                 :last_modified => s3_object.last_modified
               })
   end
 
-- 
1.7.2.1