incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1055011 - in /incubator/deltacloud/trunk: client/lib/deltacloud.rb server/lib/deltacloud/drivers/ec2/ec2_driver.rb
Date Tue, 04 Jan 2011 12:49:19 GMT
Author: mfojtik
Date: Tue Jan  4 12:49:19 2011
New Revision: 1055011

URL: http://svn.apache.org/viewvc?rev=1055011&view=rev
Log:
Rework endpoint selection for new ec2 driver.

This replaces url generation with a lookup table and allows passing
through a full hostname as the endpoint instead of just the region name.

Modified:
    incubator/deltacloud/trunk/client/lib/deltacloud.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_driver.rb

Modified: incubator/deltacloud/trunk/client/lib/deltacloud.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client/lib/deltacloud.rb?rev=1055011&r1=1055010&r2=1055011&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client/lib/deltacloud.rb (original)
+++ incubator/deltacloud/trunk/client/lib/deltacloud.rb Tue Jan  4 12:49:19 2011
@@ -46,8 +46,8 @@ module DeltaCloud
   # @param [String, password] API password
   # @param [String, user_name] API URL (eg. http://localhost:3001/api)
   # @return [true|false]
-  def self.valid_credentials?(user_name, password, api_url)
-    api=API.new(user_name, password, api_url)
+  def self.valid_credentials?(user_name, password, api_url, opts={})
+    api=API.new(user_name, password, api_url, opts)
     result = false
     api.request(:get, '', :force_auth => '1') do |response|
       result = true if response.code.eql?(200)

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_driver.rb?rev=1055011&r1=1055010&r2=1055011&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_driver.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_driver.rb Tue Jan  4
12:49:19 2011
@@ -418,23 +418,42 @@ module Deltacloud
         private
 
         def new_client(credentials, type = :ec2)
-          case type
-            when :ec2 then Aws::Ec2.new(credentials.user, credentials.password, :endpoint_url
=> endpoint_for_service(:ec2))
-            when :s3 then Aws::S3.new(credentials.user, credentials.password, :endpoint_url
=> endpoint_for_service(:s3))
-          end
-        end
+          klass = case type
+                    when :elb then Aws::Elb
+                    when :ec2 then Aws::Ec2
+                    when :s3 then Aws::S3
+                  end
+          klass.new(credentials.user, credentials.password, :server => endpoint_for_service(type))
+        end
+
+        DEFAULT_SERVICE_ENDPOINTS = {
+          'ec2' => {
+            'ap-southeast-1' => 'ec2.ap-southeast-1.amazonaws.com',
+            'eu-west-1' => 'ec2.eu-west-1.amazonaws.com',
+            'us-east-1' => 'ec2.us-east-1.amazonaws.com',
+            'us-west-1' => 'ec2.us-west-1.amazonaws.com'
+          },
+          
+          'elb' => {
+            'ap-southeast-1' => 'elasticloadbalancing.ap-southeast-1.amazonaws.com',
+            'eu-west-1' => 'elasticloadbalancing.eu-west-1.amazonaws.com',
+            'us-east-1' => 'elasticloadbalancing.us-east-1.amazonaws.com',
+            'us-west-1' => 'elasticloadbalancing.us-west-1.amazonaws.com'
+          },
+          
+          's3' => {
+            'ap-southeast-1' => 's3.amazonaws.com',
+            'eu-west-1' => 's3.amazonaws.com',
+            'us-east-1' => 's3.amazonaws.com',
+            'us-west-1' => 's3.amazonaws.com'
+          }
+        }
 
         def endpoint_for_service(service)
-          url = ""
-          url << case service
-            when :ec2
-              'ec2.'
-            when :elb
-              'elasticloadbalancing.'
-            end 
-          url << (Thread.current[:provider] || ENV['API_PROVIDER'] || DEFAULT_REGION)
-          url << '.amazonaws.com'
-          url
+          endpoint = (Thread.current[:provider] || ENV['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.
+          DEFAULT_SERVICE_ENDPOINTS[service.to_s][endpoint] || endpoint
         end
 
         def tag_instance(credentials, instance, name)



Mime
View raw message