wraps instance_action in begin/rescue block to handle
and gracefully output errors.
Also throw an ArgumentError if instance_action is called
without an id
---
src/app/controllers/instance_controller.rb | 77 +++++++++++++++------------
src/app/views/instance/instance_action.haml | 2 +
2 files changed, 45 insertions(+), 34 deletions(-)
create mode 100644 src/app/views/instance/instance_action.haml
diff --git a/src/app/controllers/instance_controller.rb
b/src/app/controllers/instance_controller.rb
index e0aaf3b..5c3452d 100644
--- a/src/app/controllers/instance_controller.rb
+++ b/src/app/controllers/instance_controller.rb
@@ -125,45 +125,54 @@ class InstanceController < ApplicationController
end
end
- @instance = Instance.find((params[:id] || []).first)
- require_privilege(Privilege::INSTANCE_CONTROL,@instance.pool)
-
- if params[:instance_details]
- render :action => 'show'
- return
- end
-
- if params[:remove_failed]
- action = remove_failed
- else
- # action list will be longer (restart, start, stop..)
- action = if params[:shutdown]
- 'stop'
- #elsif params[:restart]
- # 'restart'
- end
-
- unless @instance.valid_action?(action)
- raise ActionError.new("'#{action}' is an invalid action.")
+ begin
+ if params[:id].nil? || params[:id].blank?
+ raise ArgumentError.new("You must select an instance to perform this
action")
end
- # not sure if task is used as everything goes through condor
- #permissons check here
- @task = @instance.queue_action(@current_user, action)
- unless @task
- raise ActionError.new("#{action} cannot be performed on this
instance.")
+ @instance = Instance.find((params[:id] || []).first)
+ require_privilege(Privilege::INSTANCE_CONTROL,@instance.pool)
+
+ if params[:instance_details]
+ render :action => 'show'
+ return
end
- case action
- when 'stop'
- condormatic_instance_stop(@task)
- when 'destroy'
- condormatic_instance_destroy(@task)
- when 'start'
- condormatic_instance_create(@task)
- else
- raise ActionError.new("Sorry, action '#{action}' is currently not
supported by condor backend.")
+ if params[:remove_failed]
+ action = remove_failed
+ else
+ # action list will be longer (restart, start, stop..)
+ action = if params[:shutdown]
+ 'stop'
+ #elsif params[:restart]
+ # 'restart'
+ end
+
+ unless @instance.valid_action?(action)
+ raise ActionError.new("'#{action}' is an invalid action.")
+ end
+
+ # not sure if task is used as everything goes through condor
+ #permissons check here
+ @task = @instance.queue_action(@current_user, action)
+ unless @task
+ raise ActionError.new("#{action} cannot be performed on this
instance.")
+ end
+
+ case action
+ when 'stop'
+ condormatic_instance_stop(@task)
+ when 'destroy'
+ condormatic_instance_destroy(@task)
+ when 'start'
+ condormatic_instance_create(@task)
+ else
+ raise ActionError.new("Sorry, action '#{action}' is currently not
supported by condor backend.")
+ end
end
+ rescue Exception => e
+ @error = e.to_s
+ return
end
flash[:notice] = "#[email protected]}: #{action} was successfully queued."
diff --git a/src/app/views/instance/instance_action.haml
b/src/app/views/instance/instance_action.haml
new file mode 100644
index 0000000..509163b
--- /dev/null
+++ b/src/app/views/instance/instance_action.haml
@@ -0,0 +1,2 @@
+- # will only be rendered if there is an error
+= @error
--
1.7.2.3
_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel