[PATCH] Added compatibility check for different dc-api versions
Jan Provaznik
jprovazn at redhat.com
Wed Sep 5 12:55:04 UTC 2012
On 09/05/2012 02:24 PM, Tomáš Hrčka wrote:
> 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.
> ---
> 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..dee62ae 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_version_compatible_state(con,state))
s/con/conn/:
it should be "dc_version_compatible_state(conn, 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_version_compatible_state(con,state)
> + if state == Instance::STATE_SHUTTING_DOWN && con.api_version.to_i >= 1
> + 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
>
COndictional ACK, one note inline
More information about the aeolus-devel
mailing list