incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject svn commit: r999133 - in /incubator/deltacloud/trunk/server/lib/deltacloud/drivers: ec2/ec2_driver.rb gogrid/gogrid_driver.rb opennebula/opennebula_driver.rb rackspace/rackspace_driver.rb rhevm/rhevm_driver.rb
Date Mon, 20 Sep 2010 22:02:32 GMT
Author: lutter
Date: Mon Sep 20 22:02:31 2010
New Revision: 999133

URL: http://svn.apache.org/viewvc?rev=999133&view=rev
Log:
Canonicalize instance states.

For some drivers, we were passing the raw string we got from
the cloud provider through as the instance state.  However,
that doesn't fit in with trying to make the drivers act consistent,
so make sure all of the drivers have a translation layer between
the cloud provider's states and the deltcloud API states.  After
this series, there are only 3 valid deltacloud states: "RUNNING",
"STOPPED", and "PENDING".  We may want to think about adding
additional states in the future, but these cover most of the
current use-cases.

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

Modified:
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_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=999133&r1=999132&r2=999133&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 Mon Sep 20
22:02:31 2010
@@ -201,7 +201,7 @@ class EC2Driver < Deltacloud::BaseDriver
       # 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
+      state = convert_state(backup.instancesSet.item.first.currentState.name)
       Instance.new( {
         :id => id,
         :state => state,
@@ -360,9 +360,23 @@ class EC2Driver < Deltacloud::BaseDriver
     } )
   end
 
+  def convert_state(ec2_state)
+    case ec2_state
+    when "terminated"
+      "STOPPED"
+    when "stopped"
+      "STOPPED"
+    when "running"
+      "RUNNING"
+    when "pending"
+      "PENDING"
+    when "shutting-down"
+      "STOPPED"
+    end
+  end
+
   def convert_instance(ec2_instance, owner_id)
-    state = ec2_instance['instanceState']['name'].upcase
-    state_key = state.downcase.underscore.to_sym
+    state = convert_state(ec2_instance['instanceState']['name'])
     realm_id = ec2_instance['placement']['availabilityZone']
     (realm_id = nil ) if ( realm_id == '' )
     hwp_name = ec2_instance['instanceType']

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb?rev=999133&r1=999132&r2=999133&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb Mon Sep
20 22:02:31 2010
@@ -285,6 +285,9 @@ class GogridDriver < Deltacloud::BaseDri
     end
     prof = InstanceProfile.new("server", opts)
 
+    hwp_name = instance['image']['name']
+    state = convert_server_state(instance['state']['name'], instance['id'])
+
     Instance.new(
        # note that we use 'name' as the id here, because newly created instances
        # don't get a real ID until later on.  The name is good enough; from
@@ -296,8 +299,8 @@ class GogridDriver < Deltacloud::BaseDri
       :instance_profile => prof,
       :name => instance['name'],
       :realm_id => instance['ip']['datacenter']['id'],
-      :state => convert_server_state(instance['state']['name'], instance['id']),
-      :actions => instance_actions_for(convert_server_state(instance['state']['name'],
instance['id'])),
+      :state => state,
+      :actions => instance_actions_for(state),
       :public_addresses => [ instance['ip']['ip'] ],
       :private_addresses => [],
       :username => instance['username'],

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb?rev=999133&r1=999132&r2=999133&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb
(original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb
Mon Sep 20 22:02:31 2010
@@ -180,7 +180,7 @@ class OpennebulaDriver < Deltacloud::Bas
 
 	imageid = computehash['STORAGE/DISK[@type="disk"]'].attributes['href'].split("/").last
 
-	state = (computehash['STATE'].text == 'ACTIVE') ? 'RUNNING' : computehash['STATE'].text
+	state = (computehash['STATE'].text == "ACTIVE") ? "RUNNING" : "STOPPED"
 
 	hwp_name = computehash['INSTANCE_TYPE'] || 'small'
 

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb?rev=999133&r1=999132&r2=999133&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
(original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
Mon Sep 20 22:02:31 2010
@@ -75,8 +75,8 @@ class RackspaceDriver < Deltacloud::Base
     end
     Instance.new( {
       :id => id,
-      :state => "REBOOT",
-      :actions => instance_actions_for( state ),
+      :state => "RUNNING",
+      :actions => instance_actions_for( "RUNNING" ),
     } )
   end
 

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb?rev=999133&r1=999132&r2=999133&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb Mon Sep
20 22:02:31 2010
@@ -78,10 +78,13 @@ class RHEVMDriver < Deltacloud::BaseDriv
 
   def statify(state)
     st = state.nil? ? "" : state.upcase()
-    return "running" if st == "UP"
-    return "stopped" if st == "DOWN"
-    return "pending" if st == "POWERING UP"
-    st
+    case st
+    when "UP"
+      "RUNNING"
+    when "DOWN"
+      "STOPPED"
+    when "POWERING UP"
+      "PENDING"
   end
 
   define_hardware_profile 'rhevm'



Mime
View raw message