You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by tc...@redhat.com on 2010/12/16 00:04:38 UTC

[PATCH 0/4] Fixes for EC2 driver rev 5

From: Tobias Crawley <tc...@redhat.com>

These patches include the fixes I had to implement to get rev 5 working
with SteamCannon, and a slight reimplementation of the provider (now
endpoint) code.

Tobias Crawley (4):
  Rework endpoint selection for new ec2 driver.
  Don't convert in_use to in-use, because the client will kindly
    convert it back.
  Show the realm_id for the storage volume.
  Fix failing storage_volume test.

 client/lib/deltacloud.rb                        |   12 +++---
 server/bin/deltacloudd                          |    6 +-
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb |   52 +++++++++++++++-------
 server/lib/sinatra/rack_driver_select.rb        |    2 +-
 server/views/storage_volumes/show.html.haml     |    4 ++
 server/views/storage_volumes/show.xml.haml      |    2 +
 tests/mock/storage_volumes.feature              |    3 +-
 7 files changed, 53 insertions(+), 28 deletions(-)

-- 
1.7.3.2


[PATCH 3/4] Show the realm_id for the storage volume.

Posted by tc...@redhat.com.
From: Tobias Crawley <tc...@redhat.com>

---
 server/views/storage_volumes/show.html.haml |    4 ++++
 server/views/storage_volumes/show.xml.haml  |    2 ++
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/server/views/storage_volumes/show.html.haml b/server/views/storage_volumes/show.html.haml
index 7cbe172..fb1ce90 100644
--- a/server/views/storage_volumes/show.html.haml
+++ b/server/views/storage_volumes/show.html.haml
@@ -11,6 +11,10 @@
     %dd
       = "#{@storage_volume.capacity} GB"
   %di
+    %dt Realm
+    %dd
+      = @storage_volume.realm_id
+  %di
     %dt State
     %dd
       = @storage_volume.state
diff --git a/server/views/storage_volumes/show.xml.haml b/server/views/storage_volumes/show.xml.haml
index 0a89192..5275b78 100644
--- a/server/views/storage_volumes/show.xml.haml
+++ b/server/views/storage_volumes/show.xml.haml
@@ -5,6 +5,8 @@
     =@storage_volume.created
   %capacity{ :unit => "GB" }<
     = @storage_volume.capacity
+  %realm_id<
+    = @storage_volume.realm_id
   %state<
     = @storage_volume.state
   - unless @storage_volume.instance_id.nil?
-- 
1.7.3.2


[PATCH 2/4] Don't convert in_use to in-use, because the client will kindly convert it back.

Posted by tc...@redhat.com.
From: Tobias Crawley <tc...@redhat.com>

See client/lib/deltacloud.rb:144
---
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index a019fa4..779a2d4 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -561,8 +561,7 @@ module Deltacloud
           StorageVolume.new(
             :id => volume[:aws_id],
             :created => volume[:aws_created_at],
-            # Fix IN_USE to be IN-USE 
-            :state => volume[:aws_status] ? volume[:aws_status].tr('_', '-').upcase : 'unknown',
+            :state => volume[:aws_status] ? volume[:aws_status].upcase : 'unknown',
             :capacity => volume[:aws_size],
             :instance_id => volume[:aws_instance_id],
             :realm_id => volume[:zone],
-- 
1.7.3.2


[PATCH 1/4] Rework endpoint selection for new ec2 driver.

Posted by tc...@redhat.com.
From: Tobias Crawley <tc...@redhat.com>

This renames provider => endpoint, replaces url generation with a lookup
table, and allows passing through a full hostname as the endpoint instead
of just the region name.
---
 client/lib/deltacloud.rb                        |   12 +++---
 server/bin/deltacloudd                          |    6 +-
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb |   49 ++++++++++++++++-------
 server/lib/sinatra/rack_driver_select.rb        |    2 +-
 4 files changed, 44 insertions(+), 25 deletions(-)

diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb
index 114b013..c81380a 100644
--- a/client/lib/deltacloud.rb
+++ b/client/lib/deltacloud.rb
@@ -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)
@@ -64,11 +64,11 @@ module DeltaCloud
 
   class API
     attr_reader :api_uri, :driver_name, :api_version, :features, :entry_points
-    attr_reader :api_driver, :api_provider
+    attr_reader :api_driver, :api_endpoint
 
     def initialize(user_name, password, api_url, opts={}, &block)
       opts[:version] = true
-      @api_driver, @api_provider = opts[:driver], opts[:provider]
+      @api_driver, @api_endpoint = opts[:driver], opts[:endpoint]
       @username, @password = opts[:username] || user_name, opts[:password] || password
       @api_uri = URI.parse(api_url)
       @features, @entry_points = {}, {}
@@ -252,14 +252,14 @@ module DeltaCloud
       end
       @username = opts[:username] if opts[:username]
       @password = opts[:password] if opts[:password]
-      @api_provider = opts[:provider] if opts[:provider]
+      @api_endpoint = opts[:endpoint] if opts[:endpoint]
       return self
     end
 
     def extended_headers
       headers = {}
       headers["X-Deltacloud-Driver"] = @api_driver.to_s if @api_driver
-      headers["X-Deltacloud-Provider"] = @api_provider.to_s if @api_provider
+      headers["X-Deltacloud-Endpoint"] = @api_endpoint.to_s if @api_endpoint
       headers
     end
 
diff --git a/server/bin/deltacloudd b/server/bin/deltacloudd
index 70be6ca..64fb9cd 100755
--- a/server/bin/deltacloudd
+++ b/server/bin/deltacloudd
@@ -36,8 +36,8 @@ 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
+  opts.on( '-E', '--endpoint ENDPOINT', 'Use ENDPOINT (default is set in the driver)') do |endpoint|
+    ENV['API_ENDPOINT'] = endpoint
   end
   opts.on( '-e', '--env ENV', 'Environment (default: "development")') { |env| options[:env] = env }
   opts.on( '-h', '--help', '') { options[:help] = true }
@@ -59,7 +59,7 @@ ENV["API_HOST"] = "localhost" unless ENV["API_HOST"]
 ENV["API_PORT"] = "3001" unless ENV["API_PORT"]
 
 msg = "Starting Deltacloud API :: #{ENV["API_DRIVER"]} "
-msg << ":: #{ENV['API_PROVIDER']} " if ENV['API_PROVIDER']
+msg << ":: #{ENV['API_ENDPOINT']} " if ENV['API_ENDPOINT']
 msg << ":: http://#{ENV["API_HOST"]}:#{ENV["API_PORT"]}/api"
 puts msg
 puts
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index c547d5c..a019fa4 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -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-ap-southeast-1.amazonaws.com',
+            'eu-west-1' => 's3.amazonaws.com',
+            'us-east-1' => 's3.amazonaws.com',
+            'us-west-1' => 's3-us-west-1.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[:endpoint] || ENV['API_ENDPOINT'] || 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)
diff --git a/server/lib/sinatra/rack_driver_select.rb b/server/lib/sinatra/rack_driver_select.rb
index 3e7d038..6fef677 100644
--- a/server/lib/sinatra/rack_driver_select.rb
+++ b/server/lib/sinatra/rack_driver_select.rb
@@ -7,7 +7,7 @@ class RackDriverSelect
 
   HEADER_TO_ENV_MAP = {
     'HTTP_X_DELTACLOUD_DRIVER' => :driver,
-    'HTTP_X_DELTACLOUD_PROVIDER' => :provider
+    'HTTP_X_DELTACLOUD_ENDPOINT' => :endpoint
   }
   
   def call(env)
-- 
1.7.3.2


[PATCH 4/4] Fix failing storage_volume test.

Posted by tc...@redhat.com.
From: Tobias Crawley <tc...@redhat.com>

---
 tests/mock/storage_volumes.feature |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/tests/mock/storage_volumes.feature b/tests/mock/storage_volumes.feature
index 1d622d5..6c2206e 100644
--- a/tests/mock/storage_volumes.feature
+++ b/tests/mock/storage_volumes.feature
@@ -38,5 +38,6 @@ Feature: Accessing storage volumes
     Then client should get this storage_volume
     And this storage_volume should have:
     | created |
-    | mount |
     | capacity |
+    | realm_id |
+    | state |
-- 
1.7.3.2