incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 10/10] Imported endpoint patches from Tobi from previous EC2 gem
Date Wed, 15 Dec 2010 20:15:08 GMT
From: Michal Fojtik <mfojtik@redhat.com>

---
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb |   36 +++++++++++++++-------
 tests/ec2/api.feature                           |    1 -
 2 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index bf99a84..c547d5c 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -44,6 +44,8 @@ module Deltacloud
         feature :images, :owner_id
         feature :buckets, :bucket_location
 
+        DEFAULT_REGION = 'us-east-1'
+
         define_hardware_profile('t1.micro') do
           cpu                1
           memory             0.63 * 1024
@@ -183,9 +185,6 @@ module Deltacloud
           instance_options.merge!(:group_ids => opts[:security_group]) if opts[:security_group]
           safely do
             new_instance = convert_instance(ec2.launch_instances(image_id, instance_options).first)
-            if opts[:public_ip]
-              ec2.associate_address(new_instance.id, opts[:public_ip])
-            end
             if opts[:name]
               tag_instance(credentials, new_instance, opts[:name])
             end
@@ -226,10 +225,6 @@ module Deltacloud
           end
         end
 
-        def key(credentials, opts={})
-          keys(credentials, :id => opts[:id]).first
-        end
-
         def create_key(credentials, opts={})
           ec2 = new_client(credentials)
           safely do
@@ -324,14 +319,18 @@ module Deltacloud
         #--  
         def delete_blob(credentials, bucket_id, blob_id, opts=nil)
           s3_client = new_client(credentials, :s3)
-          s3_client.interface.delete(bucket_id, blob_id)
+          safely do
+            s3_client.interface.delete(bucket_id, blob_id)
+          end
         end
 
 
         def blob_data(credentials, bucket_id, blob_id, opts)
           s3_client = new_client(credentials, :s3)
-          s3_client.interface.get(bucket_id, blob_id) do |chunk|
-            yield chunk
+          safely do
+            s3_client.interface.get(bucket_id, blob_id) do |chunk|
+              yield chunk
+            end
           end
         end
 
@@ -420,11 +419,24 @@ module Deltacloud
 
         def new_client(credentials, type = :ec2)
           case type
-            when :ec2 then Aws::Ec2.new(credentials.user, credentials.password)
-            when :s3 then Aws::S3.new(credentials.user, credentials.password)
+            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
 
+        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 tag_instance(credentials, instance, name)
           ec2 = new_client(credentials)
           safely do
diff --git a/tests/ec2/api.feature b/tests/ec2/api.feature
index bf0e1a0..8b16cfd 100644
--- a/tests/ec2/api.feature
+++ b/tests/ec2/api.feature
@@ -50,5 +50,4 @@ Feature: Accessing API entry points
     Then client should get list of features inside 'instances':
     | authentication_key |
     | user_data |
-    | public_ip |
     | security_group |
-- 
1.7.3.2


Mime
View raw message