You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by lu...@apache.org on 2010/07/09 01:21:54 UTC
svn commit: r962085 -
/incubator/deltacloud/trunk/drivers/ec2/lib/ec2_driver.rb
Author: lutter
Date: Thu Jul 8 23:21:54 2010
New Revision: 962085
URL: http://svn.apache.org/viewvc?rev=962085&view=rev
Log:
Rework instance-state SPI and action interrogation.
Modified:
incubator/deltacloud/trunk/drivers/ec2/lib/ec2_driver.rb
Modified: incubator/deltacloud/trunk/drivers/ec2/lib/ec2_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/drivers/ec2/lib/ec2_driver.rb?rev=962085&r1=962084&r2=962085&view=diff
==============================================================================
--- incubator/deltacloud/trunk/drivers/ec2/lib/ec2_driver.rb (original)
+++ incubator/deltacloud/trunk/drivers/ec2/lib/ec2_driver.rb Thu Jul 8 23:21:54 2010
@@ -40,12 +40,21 @@ class Ec2Driver < DeltaCloud::BaseDriver
} ),
]
- INSTANCE_STATES = {
- :pending=>[ :stop ],
- :running=>[ :reboot, :stop ],
- :shutting_down=>[],
- :terminated=>[]
- }
+ INSTANCE_STATES = [
+ [ :pending, {
+ :terminated=>:stop,
+ :running=>:_auto_ } ],
+ [ :running, {
+ :running=>:reboot,
+ :terminated=>:stop } ],
+ [ :shutting_down, {
+ :terminated=>:_auto_ } ],
+ [ :terminated, {} ],
+ ]
+
+ def instance_states()
+ INSTANCE_STATES
+ end
def flavors(credentials, opts=nil)
return FLAVORS if ( opts.nil? )
@@ -124,6 +133,13 @@ class Ec2Driver < DeltaCloud::BaseDriver
def create_instance(credentials, image_id, opts)
ec2 = new_client( credentials )
realm_id = opts[:realm_id]
+ flavor_id = opts[:flavor_id]
+ unless ( flavor_id )
+ image = image(credentials, :id=>image_id )
+ flavor = flavor( credentials, :architecture=>image.architecture )
+ ( flavor_id = flavor.id ) if ( flavor )
+ end
+ flavor_id.gsub!( /-/, '.' ) if flavor_id
ec2_instances = ec2.run_instances(
image_id,
1,1,
@@ -131,7 +147,7 @@ class Ec2Driver < DeltaCloud::BaseDriver
nil,
'',
'public',
- opts[:flavor_id].gsub( /-/, '.' ),
+ flavor_id,
nil,
nil,
realm_id )
@@ -243,7 +259,7 @@ class Ec2Driver < DeltaCloud::BaseDriver
:public_addresses=>( ec2_instance[:dns_name] == '' ? [] : [ec2_instance[:dns_name]] ),
:private_addresses=>( ec2_instance[:private_dns_name] == '' ? [] : [ec2_instance[:private_dns_name]] ),
:flavor_id=>ec2_instance[:aws_instance_type].gsub( /\./, '-'),
- :actions=>INSTANCE_STATES[ state_key ]
+ :actions=>instance_actions_for( ec2_instance[:aws_state].upcase ),
} )
end