incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1044351 - in /incubator/deltacloud/trunk/server: bin/deltacloudd lib/deltacloud/drivers/ec2/ec2_driver.rb lib/sinatra/rack_driver_select.rb
Date Fri, 10 Dec 2010 13:26:46 GMT
Author: mfojtik
Date: Fri Dec 10 13:26:46 2010
New Revision: 1044351

URL: http://svn.apache.org/viewvc?rev=1044351&view=rev
Log:
Allow setting the provider on the server side, and implement region overriding in the ec2
driver based off of the provider (rev 2).

The provider can now be set on the commandline to deltacloudd via -P/--provider
(putting it in ENV['API_PROVIDER']), and also from the client via a header
(putting it in Thread.current[:provider]).

The ec2 driver is currently the only driver that understands providers, and
looks in Thread.current[:provider], then ENV['API_PROVIDER'], then falls back
to a default (currently 'us-east-1', the AWS default).

Modified:
    incubator/deltacloud/trunk/server/bin/deltacloudd
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
    incubator/deltacloud/trunk/server/lib/sinatra/rack_driver_select.rb

Modified: incubator/deltacloud/trunk/server/bin/deltacloudd
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/bin/deltacloudd?rev=1044351&r1=1044350&r2=1044351&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/bin/deltacloudd (original)
+++ incubator/deltacloud/trunk/server/bin/deltacloudd Fri Dec 10 13:26:46 2010
@@ -36,6 +36,9 @@ BANNER
   opts.on( '-p', '--port PORT', 'Use PORT (default: 3001)') do |port|
     ENV["API_PORT"] = port
   end
+  opts.on( '-P', '--provider PROVIDER', 'Use PROVIDER (default is set in the driver)') do
|provider|
+    ENV['API_PROVIDER'] = provider
+  end
   opts.on( '-e', '--env ENV', 'Environment (default: "development")') { |env| options[:env]
= env }
   opts.on( '-h', '--help', '') { options[:help] = true }
 end
@@ -55,7 +58,10 @@ end
 ENV["API_HOST"] = "localhost" unless ENV["API_HOST"]
 ENV["API_PORT"] = "3001" unless ENV["API_PORT"]
 
-puts "Starting Deltacloud API :: #{ENV["API_DRIVER"]} :: http://#{ENV["API_HOST"]}:#{ENV["API_PORT"]}/api"
+msg = "Starting Deltacloud API :: #{ENV["API_DRIVER"]} "
+msg << ":: #{ENV['API_PROVIDER']} " if ENV['API_PROVIDER']
+msg << ":: http://#{ENV["API_HOST"]}:#{ENV["API_PORT"]}/api"
+puts msg
 puts
 
 dirname="#{File.dirname(__FILE__)}/.."

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=1044351&r1=1044350&r2=1044351&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 Fri Dec 10
13:26:46 2010
@@ -30,7 +30,7 @@ class EC2Driver < Deltacloud::BaseDriver
   def supported_collections
     DEFAULT_COLLECTIONS + [ :keys, :buckets, :load_balancers ]
   end
-
+  
   feature :instances, :user_data
   feature :instances, :authentication_key
   feature :instances, :security_group
@@ -106,6 +106,8 @@ class EC2Driver < Deltacloud::BaseDriver
     stopped.to( :finish )         .automatically
   end
 
+  DEFAULT_REGION = 'us-east-1'
+  
   #
   # Images
   #
@@ -500,9 +502,9 @@ class EC2Driver < Deltacloud::BaseDriver
   def new_client(credentials, provider_type = :ec2)
     opts = {
       :access_key_id => credentials.user,
-      :secret_access_key => credentials.password
+      :secret_access_key => credentials.password,
+      :server => endpoint_for_service(provider_type)
     }
-    opts[:server] = ENV['DCLOUD_EC2_URL'] if ENV['DCLOUD_EC2_URL']
     safely do
       case provider_type
         when :ec2
@@ -513,6 +515,19 @@ class EC2Driver < Deltacloud::BaseDriver
     end
   end
 
+  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
+  end
+  
   def convert_load_balancer(credentials, loadbalancer)
     balancer_realms = loadbalancer.AvailabilityZones.member.collect do |m|
       realm(credentials, m)

Modified: incubator/deltacloud/trunk/server/lib/sinatra/rack_driver_select.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/sinatra/rack_driver_select.rb?rev=1044351&r1=1044350&r2=1044351&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/sinatra/rack_driver_select.rb (original)
+++ incubator/deltacloud/trunk/server/lib/sinatra/rack_driver_select.rb Fri Dec 10 13:26:46
2010
@@ -5,17 +5,25 @@ class RackDriverSelect
     @opts = opts
   end
 
+  HEADER_TO_ENV_MAP = {
+    'HTTP_X_DELTACLOUD_DRIVER' => :driver,
+    'HTTP_X_DELTACLOUD_PROVIDER' => :provider
+  }
+  
   def call(env)
-    original_driver = Thread.current[:driver]
-    new_driver = extract_driver(env)
-    Thread.current[:driver] = new_driver if new_driver
+    original_settings = { }
+    HEADER_TO_ENV_MAP.each do |header, name|
+      original_settings[name] = Thread.current[name]
+      new_setting = extract_header(env, header)
+      Thread.current[name] = new_setting if new_setting
+    end
     @app.call(env)
   ensure
-    Thread.current[:driver] = original_driver
+    original_settings.each { |name, value| Thread.current[name] = value }
   end
 
-  def extract_driver(env)
-    driver_name = env['HTTP_X_DELTACLOUD_DRIVER'].downcase if env['HTTP_X_DELTACLOUD_DRIVER']
+  def extract_header(env, header)
+    env[header].downcase if env[header]
   end
 
 end



Mime
View raw message