incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r980053 - /incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
Date Wed, 28 Jul 2010 13:48:27 GMT
Author: mfojtik
Date: Wed Jul 28 13:48:27 2010
New Revision: 980053

URL: http://svn.apache.org/viewvc?rev=980053&view=rev
Log:
Make sure the ec2 *_instance methods return an instance.

Signed-off-by: Chris Lalancette <clalance@redhat.com>

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

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=980053&r1=980052&r2=980053&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 Wed Jul 28
13:48:27 2010
@@ -182,28 +182,46 @@ class EC2Driver < Deltacloud::BaseDriver
       :disable_api_termination => false,
       :instance_initiated_shutdown_behavior => 'terminate'
     )
-    convert_instance( ec2_instances.instancesSet.item.first, 'pending' )
+    convert_instance( ec2_instances.instancesSet.item.first, credentials.user )
+  end
+
+  def generate_instance(ec2, id, backup)
+    begin
+      this_instance = ec2.describe_instances( :instance_id => id ).reservationSet.item.first.instancesSet.item.first
+      convert_instance(this_instance, this_instance.ownerId)
+    rescue Exception => e
+      puts "WARNING: ignored error during instance refresh: #{e.message}"
+      # at this point, the action has succeeded but our follow-up
+      # "describe_instances" failed for some reason.  Create a simple Instance
+      # object with only the ID and new state in place
+      state = backup.instancesSet.item.first.currentState.name
+      Instance.new( {
+        :id => id,
+        :state => state,
+        :actions => instance_actions_for( state ),
+      } )
+    end
   end
 
   def reboot_instance(credentials, id)
     ec2 = new_client(credentials)
-    safely do
-      ec2.reboot_instances( :instance_id => id )
-    end
+    backup = ec2.reboot_instances( :instance_id => id )
+
+    generate_instance(ec2, id, backup)
   end
 
   def stop_instance(credentials, id)
     ec2 = new_client(credentials)
-    safely do
-      ec2.terminate_instances( :instance_id => id )
-    end
+    backup = ec2.terminate_instances( :instance_id => id )
+
+    generate_instance(ec2, id, backup)
   end
 
   def destroy_instance(credentials, id)
     ec2 = new_client(credentials)
-    safely do
-      ec2.terminate_instances( :instance_id => id )
-    end
+    backup = ec2.terminate_instances( :instance_id => id )
+
+    generate_instance(ec2, id, backup)
   end
 
   #



Mime
View raw message