deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject git commit: Fix for JIRA DTACLOUD_196 - Use correct endpoint when getting s3 buckets and blobs. Also nit from modular.
Date Thu, 14 Jun 2012 15:36:11 GMT
Updated Branches:
  refs/heads/master 20519d94f -> 8c89662e2


Fix for JIRA DTACLOUD_196 - Use correct endpoint when
getting s3 buckets and blobs. Also nit from modular.

https://issues.apache.org/jira/browse/DTACLOUD-196


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/8c89662e
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/8c89662e
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/8c89662e

Branch: refs/heads/master
Commit: 8c89662e2394e2188be04ae0fbaa17a49acc4163
Parents: 20519d9
Author: marios <marios@redhat.com>
Authored: Thu Jun 14 17:00:32 2012 +0300
Committer: marios <marios@redhat.com>
Committed: Thu Jun 14 18:09:58 2012 +0300

----------------------------------------------------------------------
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb |   25 +++++++++++++----
 server/views/buckets/new.html.haml              |    2 +-
 2 files changed, 20 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/8c89662e/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index 70c9189..318db1a 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -409,7 +409,7 @@ module Deltacloud
           safely do
             s3_client = new_client(credentials, :s3)
             unless (opts[:id].nil?)
-              bucket = s3_client.bucket(opts[:id])
+              bucket, s3_client = get_bucket_with_endpoint(s3_client, credentials, opts[:id])
               buckets << convert_bucket(bucket)
             else
               bucket_list = s3_client.buckets
@@ -447,7 +447,7 @@ module Deltacloud
           s3_client = new_client(credentials, :s3)
           blobs = []
           safely do
-            s3_bucket = s3_client.bucket(opts['bucket'])
+            s3_bucket, s3_client = get_bucket_with_endpoint(s3_client, credentials, opts['bucket'])
             if(opts[:id])
               blobs << convert_object(s3_bucket.key(opts[:id], true))
             else
@@ -504,7 +504,8 @@ module Deltacloud
           s3_client = new_client(credentials, :s3)
           blob_meta = {}
           safely do
-            the_blob = s3_client.bucket(opts['bucket']).key(opts[:id], true)
+            the_bucket, s3_client = get_bucket_with_endpoint(s3_client, credentials, opts['bucket'])
+            the_blob = the_bucket.key(opts[:id], true)
             blob_meta = the_blob.meta_headers
           end
         end
@@ -513,13 +514,15 @@ module Deltacloud
           s3_client = new_client(credentials, :s3)
           meta_hash = BlobHelper::rename_metadata_headers(opts['meta_hash'], '')
           safely do
-            the_blob = s3_client.bucket(opts['bucket']).key(opts[:id])
+            the_bucket, s3_client = get_bucket_with_endpoint(s3_client, credentials, opts['bucket'])
+            the_blob = the_bucket.key(opts[:id])
             the_blob.save_meta(meta_hash)
           end
         end
 
         def blob_data(credentials, bucket_id, blob_id, opts={})
           s3_client = new_client(credentials, :s3)
+          bucket, s3_client = get_bucket_with_endpoint(s3_client, credentials, bucket_id)
           safely do
             s3_client.interface.get(bucket_id, blob_id) do |chunk|
               yield chunk
@@ -772,7 +775,7 @@ module Deltacloud
         end
 
         private
-        def new_client(credentials, type = :ec2)
+        def new_client(credentials, type = :ec2, endpoint = nil)
           klass = case type
                     when :elb then Aws::Elb
                     when :ec2 then Aws::Ec2
@@ -780,7 +783,7 @@ module Deltacloud
                     when :mon then Aws::Mon
                   end
           klass.new(credentials.user, credentials.password, {
-            :server => endpoint_for_service(type),
+            :server => endpoint || endpoint_for_service(type),
             :connection_mode => :per_thread,
             :logger => ENV['RACK_ENV'] == 'test' ? Logger.new('/dev/null') : Logger.new(STDOUT)
           })
@@ -801,6 +804,16 @@ module Deltacloud
           Deltacloud::Drivers::driver_config[:ec2][:entrypoints][service.to_s][endpoint]
|| endpoint
         end
 
+        def get_bucket_with_endpoint(s3_client, credentials, s3_bucket_name)
+            s3_bucket = s3_client.bucket(s3_bucket_name)
+            endpoint_for_bucket = Deltacloud::Drivers::driver_config[:ec2][:entrypoints]["s3"]["#{s3_bucket.location}"]
+            if (s3_client.interface.params[:server] != endpoint_for_bucket)
+              s3_client = new_client(credentials, :s3, endpoint_for_bucket)
+              s3_bucket = s3_client.bucket(s3_bucket_name)
+            end
+            [s3_bucket, s3_client]
+        end
+
         def convert_bucket(s3_bucket)
           #get blob list:
           blob_list = []

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/8c89662e/server/views/buckets/new.html.haml
----------------------------------------------------------------------
diff --git a/server/views/buckets/new.html.haml b/server/views/buckets/new.html.haml
index bc0f0c3..45b9ae3 100644
--- a/server/views/buckets/new.html.haml
+++ b/server/views/buckets/new.html.haml
@@ -6,7 +6,7 @@
       Bucket Name:
       %input{ :name => 'name', :size => 250}/
       %br
-    -if driver.class.has_feature?(:bucket_location, :buckets)
+    -if driver.class.has_feature?(:buckets, :bucket_location)
       %p
         %label
           Location: (optional)


Mime
View raw message