incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 2/5] Added 'assign_instance' feature for EC2
Date Fri, 27 Aug 2010 12:55:30 GMT
---
 server/lib/deltacloud/base_driver/features.rb   |    6 ++++++
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb |   12 ++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/server/lib/deltacloud/base_driver/features.rb b/server/lib/deltacloud/base_driver/features.rb
index abc97b5..e4808c4 100644
--- a/server/lib/deltacloud/base_driver/features.rb
+++ b/server/lib/deltacloud/base_driver/features.rb
@@ -164,6 +164,12 @@ module Deltacloud
       end
     end
 
+    declare_feature :ip_addresses, :assign_instance do
+      operation :create do
+        param :instance_id, :string, :optional
+      end
+    end
+
     declare_feature :instances, :hardware_profiles do
       description "Size instances according to changes to a hardware profile"
       # The parameters are filled in from the hardware profiles
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index eea0c41..db48d40 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -40,6 +40,7 @@ class EC2Driver < Deltacloud::BaseDriver
   end
 
   feature :instances, :user_data
+  feature :ip_addresses, :assign_instance
   feature :instances, :authentication_key
   feature :images, :owner_id
 
@@ -175,6 +176,7 @@ class EC2Driver < Deltacloud::BaseDriver
   def create_instance(credentials, image_id, opts)
     ec2 = new_client( credentials )
     realm_id = opts[:realm_id]
+    ec2_instance = nil
     safely do
       image = image(credentials, :id => image_id )
       hwp = find_hardware_profile(credentials, opts[:hwp_id], image.id)
@@ -188,8 +190,9 @@ class EC2Driver < Deltacloud::BaseDriver
         :disable_api_termination => false,
         :instance_initiated_shutdown_behavior => 'terminate'
       )
-      return convert_instance( ec2_instances.instancesSet.item.first, 'pending' )
+      ec2_instance = convert_instance( ec2_instances.instancesSet.item.first, 'pending' )
     end
+    return ec2_instance
   end
 
   def generate_instance(ec2, id, backup)
@@ -330,10 +333,15 @@ class EC2Driver < Deltacloud::BaseDriver
 
   def create_ip_address(credentials, opts)
     ec2 = new_client( credentials )
+    ip = nil
     safely do
       ip = ec2.allocate_address().publicIp
-      return ip_addresses(credentials, :id => ip)
+      if opts and opts[:instance_id]
+        ec2.associate_address(:public_ip => ip,
+          :instance_id => opts[:instance_id])
+      end
     end
+    return ip_addresses(credentials, :id => ip)
   end
 
   def destroy_ip_address(credentials, opts)
-- 
1.7.2.2


Mime
View raw message