Skip to content

Commit

Permalink
Merge pull request #31 from stbenjam/tasks
Browse files Browse the repository at this point in the history
Make foreman-tasks a hard requirement
  • Loading branch information
stbenjam committed Mar 17, 2015
2 parents c36ebf4 + b87fe18 commit 5e33c6f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 30 deletions.
10 changes: 2 additions & 8 deletions app/controllers/foreman_salt/api/v2/jobs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@ 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
task = ForemanTasks.async_task(::Actions::ForemanSalt::ReportImport, params[:job], detected_proxy.try(:id))
render :json => { :task_id => task.id }
else
render :json => { :message => 'Unsupported function' }, :status => :unprocessable_entity
end
Expand Down
32 changes: 15 additions & 17 deletions app/lib/actions/foreman_salt/report_import.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
module Actions
module ForemanSalt
if defined? ForemanTasks
class ReportImport < Actions::EntryAction
def resource_locks
:report_import
end
class ReportImport < Actions::EntryAction
def resource_locks
:report_import
end

def plan(job, proxy_id)
plan_self(:job_id => job[:job_id], :report => job[:result], :proxy_id => proxy_id)
end
def plan(job, proxy_id)
plan_self(:job_id => job[:job_id], :report => job[:result], :proxy_id => proxy_id)
end

def run
::User.as_anonymous_admin do
reports = ::ForemanSalt::ReportImporter.import(input[:report], input[:proxy_id])
def run
::User.as_anonymous_admin do
reports = ::ForemanSalt::ReportImporter.import(input[:report], input[:proxy_id])

output[:state] = { :message => "Imported #{reports.count} new reports" }
output[:hosts] = reports.map { |report| report.host.name }
end
output[:state] = { :message => "Imported #{reports.count} new reports" }
output[:hosts] = reports.map { |report| report.host.name }
end
end

def humanized_name
_("Process Highstate Report: #{input[:job_id]}")
end
def humanized_name
_("Process Highstate Report: #{input[:job_id]}")
end
end
end
Expand Down
1 change: 1 addition & 0 deletions foreman_salt.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ Gem::Specification.new do |s|
s.test_files = Dir['test/**/*']

s.add_dependency 'deface', '< 1.0'
s.add_dependency "foreman-tasks", '~> 0.6.9'
end
6 changes: 2 additions & 4 deletions lib/foreman_salt/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ class Engine < ::Rails::Engine
config.autoload_paths += Dir["#{config.root}/app/services"]
config.autoload_paths += Dir["#{config.root}/app/lib"]

if defined? ForemanTasks
initializer 'foreman_salt.require_dynflow', :before => 'foreman_tasks.initialize_dynflow' do |_app|
ForemanTasks.dynflow.require!
end
initializer 'foreman_salt.require_dynflow', :before => 'foreman_tasks.initialize_dynflow' do |_app|
ForemanTasks.dynflow.require!
end

initializer 'foreman_salt.load_default_settings', :before => :load_config_initializers do
Expand Down
2 changes: 1 addition & 1 deletion lib/foreman_salt/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ForemanSalt
VERSION = '2.0.1'
VERSION = '2.0.2'
end

0 comments on commit 5e33c6f

Please sign in to comment.