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 <[email protected]>
---
 src/app/controllers/portal_pool_controller.rb |    4 ++++
 src/app/util/taskomatic.rb                    |   22 ++++++++++++++++++++++
 2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/src/app/controllers/portal_pool_controller.rb 
b/src/app/controllers/portal_pool_controller.rb
index d17eaac..366663c 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,8 @@ 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)
     @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
 
-- 
1.6.2.5

_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to