[PATCH conductor] BZ 788558 - instance termination for single instance

jprovazn at redhat.com jprovazn at redhat.com
Tue Feb 28 10:20:50 UTC 2012


From: Jan Provaznik <jprovazn at redhat.com>

This patch extends previous patch for 788558 to cover also single
instance stop which is available on deployments show pretty view.
---
 src/app/controllers/deployments_controller.rb      |    2 +-
 src/app/controllers/instances_controller.rb        |   13 +++++++++----
 src/app/models/instance.rb                         |    4 ++--
 .../views/instances/confirm_terminate.html.haml    |    8 ++++++--
 4 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/src/app/controllers/deployments_controller.rb b/src/app/controllers/deployments_controller.rb
index 7b5e4c0..d65dea3 100644
--- a/src/app/controllers/deployments_controller.rb
+++ b/src/app/controllers/deployments_controller.rb
@@ -305,7 +305,7 @@ class DeploymentsController < ApplicationController
         begin
           require_privilege(Privilege::USE, instance)
           if @inaccessible_instances.include?(instance)
-            instance.force_stop(current_user)
+            instance.forced_stop(current_user)
             notices << "#{log_prefix}: #{t('instances.flash.notice.forced_stop')}"
           else
             instance.stop(current_user)
diff --git a/src/app/controllers/instances_controller.rb b/src/app/controllers/instances_controller.rb
index ef04cd7..eb696e2 100644
--- a/src/app/controllers/instances_controller.rb
+++ b/src/app/controllers/instances_controller.rb
@@ -18,7 +18,7 @@ class InstancesController < ApplicationController
   before_filter :require_user
   before_filter :load_instance, :only => [:show, :key, :edit, :update, :stop, :reboot]
   before_filter :set_view_vars, :only => [:show, :index, :export_events]
-  before_filter :check_inaccessible_instances, :only => :multi_stop
+  before_filter :check_inaccessible_instances, :only => [:stop, :multi_stop]
 
   def index
     @params = params
@@ -148,7 +148,7 @@ class InstancesController < ApplicationController
         require_privilege(Privilege::USE,instance)
 
         if @inaccessible_instances.include?(instance)
-          instance.force_stop(current_user)
+          instance.forced_stop(current_user)
           notices << "#{instance.name}: #{t('instances.flash.notice.forced_stop')}"
         else
           instance.stop(current_user)
@@ -176,7 +176,11 @@ class InstancesController < ApplicationController
   end
 
   def stop
-    do_operation(:stop)
+    if @inaccessible_instances.include?(@instance)
+      do_operation(:forced_stop)
+    else
+      do_operation(:stop)
+    end
   end
 
   def reboot
@@ -251,7 +255,8 @@ class InstancesController < ApplicationController
   end
 
   def check_inaccessible_instances
-    @instances_to_stop = Instance.find(params[:instance_selected] || [])
+    # @instance is set only on stop action
+    @instances_to_stop = @instance ? @instance.to_a : Instance.find(params[:instance_selected].to_a)
     @inaccessible_instances = Instance.stoppable_inaccessible_instances(@instances_to_stop)
     if params[:terminate].blank? and @inaccessible_instances.any?
       respond_to do |format|
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb
index 9027e24..21739f9 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -447,12 +447,12 @@ class Instance < ActiveRecord::Base
     do_operation(user, 'reboot')
   end
 
-  def force_stop(user)
+  def forced_stop(user)
     self.state = STATE_STOPPED
     save!
     event = Event.create!(:source => self, :event_time => Time.now,
                           :summary => "Instance is not accessible, state changed to stopped",
-                          :status_code => "force_stop")
+                          :status_code => "forced_stop")
   end
 
   def deployed?
diff --git a/src/app/views/instances/confirm_terminate.html.haml b/src/app/views/instances/confirm_terminate.html.haml
index ea680f2..64709eb 100644
--- a/src/app/views/instances/confirm_terminate.html.haml
+++ b/src/app/views/instances/confirm_terminate.html.haml
@@ -6,11 +6,15 @@
   .content.confirm_instances_termination
     .align-center
       %strong= t('.terminate_instances_description')
-    = form_tag multi_stop_instances_path, :method => :post do
+    - url = @instance ? stop_instance_path(@instance) : multi_stop_instances_path
+    = form_tag url, :method => :post do
       - @instances_to_stop.each do |i|
         = hidden_field_tag 'instance_selected[]', i.id
       %ul
         - @inaccessible_instances.each do |i|
           %li= i.name
-      = link_to t('cancel'), pools_path(:view => 'filter', :details_tab => 'instances'), :class => 'button'
+      - if @instance
+        = link_to t('cancel'), deployment_path(@instance.deployment, :details_tab => 'instances'), :class => 'button'
+      - else
+        = link_to t('cancel'), pools_path(:view => 'filter', :details_tab => 'instances'), :class => 'button'
       = submit_tag t('.terminate'), :name => 'terminate', :class => 'button', :id => 'terminate_button'
-- 
1.7.7.6




More information about the aeolus-devel mailing list