Class: ForemanSalt::Api::V2::JobsController

Inherits:
Api::V2::BaseController
  • Object
show all
Includes:
Api::Version2, Foreman::Controller::SmartProxyAuth, Concerns::SmartProxyAuthExtensions
Defined in:
app/controllers/foreman_salt/api/v2/jobs_controller.rb

Instance Method Summary collapse

Methods included from Concerns::SmartProxyAuthExtensions

#require_puppetmaster_or_login_with_salt

Instance Method Details

#resource_classObject



47
48
49
# File 'app/controllers/foreman_salt/api/v2/jobs_controller.rb', line 47

def resource_class
  ::Report
end

#uploadObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/foreman_salt/api/v2/jobs_controller.rb', line 28

def upload
  Rails.logger.info("Processing job #{params[:job][:job_id]} from Salt.")
  case params[:job][:function]
  when 'state.highstate'
    # Dynflowize the action if we can, otherwise we'll do it live
    if defined? ForemanTasks
      task = ForemanTasks.async_task(::Actions::ForemanSalt::ReportImport, params[:job], detected_proxy.try(:id))
      render :json => {:task_id => task.id}
    else
      reports = ForemanSalt::ReportImporter.import(params[:job][:result], detected_proxy.try(:id))
      render :json => {:message => "Imported #{reports.count} new reports."}
    end
  else
    render :json => {:message => 'Unsupported function'}, :status => :unprocessable_entity
  end
rescue ::Foreman::Exception => e
  render :json => {:message => e.to_s}, :status => :unprocessable_entity
end