This is necessary for ec2 instances now or they'll never leave the 'pending' state. I've tested this with ec2 and both starting and stopping. Eventually this needs a more robust auto-updating infrastructure once we have the scheduler in place.
Signed-off-by: Scott Seago sseago@redhat.com --- src/app/controllers/portal_pool_controller.rb | 5 +++++ src/app/util/taskomatic.rb | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/src/app/controllers/portal_pool_controller.rb b/src/app/controllers/portal_pool_controller.rb index d17eaac..90df8a5 100644 --- a/src/app/controllers/portal_pool_controller.rb +++ b/src/app/controllers/portal_pool_controller.rb @@ -19,6 +19,8 @@ # Filters added to this controller apply to all controllers in the application. # Likewise, all the methods added will be available for all controllers.
+require 'util/taskomatic' + class PortalPoolController < ApplicationController before_filter :require_user
@@ -30,6 +32,9 @@ class PortalPoolController < ApplicationController #FIXME: clean this up, many error cases here @pool = PortalPool.find(params[:id]) require_privilege(Privilege::INSTANCE_VIEW,@pool) + # pass nil into Taskomatic as we're not working off a task here + Taskomatic.new(nil,logger).pool_refresh(@pool) + @pool.reload @instances = @pool.instances end
diff --git a/src/app/util/taskomatic.rb b/src/app/util/taskomatic.rb index 127c8e0..c0dcbef 100644 --- a/src/app/util/taskomatic.rb +++ b/src/app/util/taskomatic.rb @@ -26,6 +26,8 @@ def dcloud_to_instance_state(state_str) return Instance::STATE_RUNNING when 'STOPPED' return Instance::STATE_STOPPED + when 'TERMINATED' + return Instance::STATE_STOPPED when 'SHUTTING_DOWN' return Instance::STATE_SHUTTING_DOWN else @@ -123,5 +125,25 @@ class Taskomatic @task.time_ended = Time.now @task.save! end + + # FIXME: this should probably eventually enforce a max refresh rate to prevent + # too many refreshes causing scalability problems. In addition this will need + # to be handled by the scheduler + def pool_refresh(pool) + account_clients = {} + pool.instances.each do |instance| + if instance.cloud_account and instance.state != Instance::STATE_NEW + account_clients[instance.cloud_account_id] ||= instance.cloud_account.connect + api_instance = account_clients[instance.cloud_account_id].instance(instance.external_key) + if api_instance + @logger.debug("updating instance state for #{instance.name}: #{instance.external_key}. #{api_instance}") + instance.state = dcloud_to_instance_state(api_instance.state) + instance.save! + else + instance.destroy + end + end + end + end end
On Mon, 2010-03-15 at 17:50 -0400, Scott Seago wrote:
This is necessary for ec2 instances now or they'll never leave the 'pending' state. I've tested this with ec2 and both starting and stopping. Eventually this needs a more robust auto-updating infrastructure once we have the scheduler in place.
Signed-off-by: Scott Seago sseago@redhat.com
ACK! Looks good and works.
Ian
deltacloud-devel@lists.fedorahosted.org