incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Lalancette <clala...@redhat.com>
Subject [PATCH] Canonicalize instance states.
Date Thu, 09 Sep 2010 19:30:20 GMT
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>
---
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb    |   20 +++++++++++++++++---
 .../lib/deltacloud/drivers/gogrid/gogrid_driver.rb |    7 +++++--
 .../drivers/opennebula/opennebula_driver.rb        |    2 +-
 .../drivers/rackspace/rackspace_driver.rb          |    4 ++--
 .../lib/deltacloud/drivers/rhevm/rhevm_driver.rb   |   11 +++++++----
 5 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index 909eca3..9d13b65 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -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,
@@ -351,9 +351,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']
diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
index a883af4..7a3f983 100644
--- a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
+++ b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
@@ -280,6 +280,9 @@ class GogridDriver < Deltacloud::BaseDriver
     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
@@ -291,8 +294,8 @@ class GogridDriver < Deltacloud::BaseDriver
       :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'],
diff --git a/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb b/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb
index c5e1408..52ab756 100644
--- a/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb
+++ b/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb
@@ -180,7 +180,7 @@ class OpennebulaDriver < Deltacloud::BaseDriver
 
 	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'
 
diff --git a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
index 6d6ba0b..b971af5 100644
--- a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
+++ b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
@@ -75,8 +75,8 @@ class RackspaceDriver < Deltacloud::BaseDriver
     end
     Instance.new( {
       :id => id,
-      :state => "REBOOT",
-      :actions => instance_actions_for( state ),
+      :state => "RUNNING",
+      :actions => instance_actions_for( "RUNNING" ),
     } )
   end
 
diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
index 18ba0fa..23a20b7 100644
--- a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
+++ b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
@@ -78,10 +78,13 @@ class RHEVMDriver < Deltacloud::BaseDriver
 
   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'
-- 
1.7.2.2


Mime
View raw message