incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@redhat.com
Subject [PATCH 2/4] Unify access to the selected provider with an api_provider helper method
Date Wed, 08 Jun 2011 15:32:48 GMT
From: David Lutterkort <lutter@redhat.com>


Signed-off-by: David Lutterkort <lutter@redhat.com>
---
 server/lib/deltacloud/base_driver/base_driver.rb   |    4 ++++
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb    |    2 +-
 .../drivers/eucalyptus/eucalyptus_driver.rb        |    2 +-
 server/lib/deltacloud/drivers/mock/mock_driver.rb  |    3 +--
 .../lib/deltacloud/drivers/rhevm/rhevm_driver.rb   |    2 +-
 5 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/server/lib/deltacloud/base_driver/base_driver.rb b/server/lib/deltacloud/base_driver/base_driver.rb
index 2c780d9..70e6ab6 100644
--- a/server/lib/deltacloud/base_driver/base_driver.rb
+++ b/server/lib/deltacloud/base_driver/base_driver.rb
@@ -218,6 +218,10 @@ module Deltacloud
       { :error => [], :auth => [], :glob => [] }
     end
 
+    def api_provider
+      Thread.current[:provider] || ENV['API_PROVIDER']
+    end
+
   end
 
 end
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index 4edd989..7040549 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -605,7 +605,7 @@ module Deltacloud
         end
 
         def endpoint_for_service(service)
-          endpoint = (Thread.current[:provider] || ENV['API_PROVIDER'] || DEFAULT_REGION)
+          endpoint = (api_provider || DEFAULT_REGION)
           # return the endpoint if it does not map to a default endpoint, allowing
           # the endpoint to be a full hostname instead of a region.
           Deltacloud::Drivers::driver_config[:ec2][:entrypoints][service.to_s][endpoint]
|| endpoint
diff --git a/server/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb b/server/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb
index a78ee63..a811df0 100644
--- a/server/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb
+++ b/server/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb
@@ -147,7 +147,7 @@ module Deltacloud
 
         def endpoint_for_service(service)
           service = service.to_s
-          endpoint = (Thread.current[:provider] || ENV['API_PROVIDER'])
+          endpoint = api_provider
           if endpoint && endpoint.include?(service)
             # example endpoint: 'ec2=192.168.1.1; s3=192.168.1.2'
             addr = Hash[endpoint.split(";").map { |svc| svc.strip.split("=") }][service]
diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index 9697e5b..3fab678 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -26,8 +26,7 @@ class MockDriver < Deltacloud::BaseDriver
   # If the provider is set to storage, pretend to be a storage-only
   # driver
   def supported_collections
-    endpoint = Thread.current[:provider] || ENV['API_PROVIDER']
-    if endpoint == 'storage'
+    if api_provider == 'storage'
       [:buckets]
     else
       DEFAULT_COLLECTIONS + [:buckets, :keys]
diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
index 2970ca4..d160240 100644
--- a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
+++ b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
@@ -202,7 +202,7 @@ class RHEVMDriver < Deltacloud::BaseDriver
   private
 
   def new_client(credentials)
-    url = (Thread.current[:provider] || ENV['API_PROVIDER'] || provider_uri)
+    url = api_provider || provider_uri
     safely do
       ::RHEVM::Client.new(credentials.user, credentials.password, url)
     end
-- 
1.7.4.4


Mime
View raw message