[PATCH] Added compatibility check for different dc-api versions. DC-api returns state 'stopping' instead of 'shutting_down' since version 1.0. This patch adds new state mapping and method to check api version.

Tomáš Hrčka thrcka at redhat.com
Wed Sep 5 11:34:01 UTC 2012


---
 src/app/models/instance.rb      |  1 +
 src/app/models/instance_task.rb | 12 +++++++++++-
 src/app/util/taskomatic.rb      |  2 ++
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb
index d354f23..0b20183 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -113,6 +113,7 @@ class Instance < ActiveRecord::Base
   STATE_RUNNING        = "running"
   STATE_SHUTTING_DOWN  = "shutting_down"
   STATE_STOPPED        = "stopped"
+  STATE_STOPPING       = "stopping"
   STATE_CREATE_FAILED  = "create_failed"
   STATE_ERROR          = "error"
   STATE_VANISHED       = "vanished"
diff --git a/src/app/models/instance_task.rb b/src/app/models/instance_task.rb
index d28e0e6..aaef421 100644
--- a/src/app/models/instance_task.rb
+++ b/src/app/models/instance_task.rb
@@ -67,7 +67,7 @@ class InstanceTask < Task
     # FIXME: cloud_account won't always be set here, but we're requiring
     #        front end realm for now.
     if cloud_account = instance.provider_account and
-      conn = cloud_account.connect and c_state = conn.instance_state(state)
+      conn = cloud_account.connect and c_state = conn.instance_state(dc_compatibility_states(state))
         transitions = c_state.transitions
         transitions.each do |transition|
           # FIXME if we allow actions based on the expected state after
@@ -81,6 +81,16 @@ class InstanceTask < Task
     actions
   end
 
+  #this method translate states so they are compatible with 0.5.x and 1.x version of dc-core
+  #v0.5.x use state shutting_down, v1.x changed the state to stopping
+  def self.dc_compatibility_states(state)
+    if connection.api_version.to_i >= 1 && state == Instance::STATE_SHUTTING_DOWN
+      Instance::STATE_STOPPING
+    else
+      state
+    end
+  end
+
   def self.action_label(action)
     return ACTIONS[action][:label]
   end
diff --git a/src/app/util/taskomatic.rb b/src/app/util/taskomatic.rb
index 1708970..44f6707 100644
--- a/src/app/util/taskomatic.rb
+++ b/src/app/util/taskomatic.rb
@@ -116,6 +116,8 @@ module Taskomatic
       return Instance::STATE_STOPPED
     when 'SHUTTING_DOWN'
       return Instance::STATE_SHUTTING_DOWN
+    when 'STOPPING'
+      return Instance::STATE_SHUTTING_DOWN
     else
       return Instance::STATE_PENDING
     end
-- 
1.7.11.4




More information about the aeolus-devel mailing list