Class: ForemanMco::CommandsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ForemanMco::CommandsController
- Defined in:
- app/controllers/foreman_mco/commands_controller.rb
Constant Summary collapse
- COMMANDS =
[:install_package, :uninstall_package, :service_status, :start_service, :stop_service, :install_package, :uninstall_package, :puppet_runonce, :puppet_enable, :puppet_disable, :ping]
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
Instance Method Summary collapse
- #filter_by_hosts ⇒ Object
- #find_command ⇒ Object
-
#submit_command ⇒ Object
TODO: a possible race condition here – proxy can process remote job before we get to CommandStatus creation.
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
10 11 12 |
# File 'app/controllers/foreman_mco/commands_controller.rb', line 10 def command @command end |
Instance Method Details
#filter_by_hosts ⇒ Object
43 44 45 46 |
# File 'app/controllers/foreman_mco/commands_controller.rb', line 43 def filter_by_hosts @hosts = params[:host_ids].nil? ? [] : Host.select(:name).where(:id => params[:host_ids]) @filters = @hosts.collect(&:name).collect {|n| ::ForemanMco::Command::Filter.identity_filter(n)}.to_json end |
#find_command ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/foreman_mco/commands_controller.rb', line 29 def find_command return process_error :redirect => :back, :error_msg => _("No command to execute") unless params[:command] command_hash = params[:command] clazz = ("ForemanMco::Command::" + command_hash[:command].camelize).constantize @command = clazz.new(command_hash) return process_error(:redirect => :back, :object => @command, :error_msg => _("Invalid command parametres: %s") % command.errors.) unless @command.valid? @command rescue NameError => e return process_error(:redirect => :back, :object => @command, :error_msg => _("Invalid command '%s'") % params[:command]) end |
#submit_command ⇒ Object
TODO: a possible race condition here – proxy can process remote job before we get to CommandStatus creation
19 20 21 22 23 24 25 26 27 |
# File 'app/controllers/foreman_mco/commands_controller.rb', line 19 def submit_command if @command.execute process_success :success_redirect => :back, :success_msg => _("'%s' command has been queued up for execution") % command else process_error :redirect => :back, :error_msg => _("'%s' command has not been queued up: %s") % [command, 'fail!'] end rescue => e process_error :redirect => :back, :error_msg => _("'%s' command has not been queued up: %s") % [command, e] end |