Class: Actions::ForemanPatch::Host::Reschedule

Inherits:
Base
  • Object
show all
Defined in:
app/lib/actions/foreman_patch/host/reschedule.rb

Instance Method Summary collapse

Instance Method Details

#plan(*hosts, **options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/lib/actions/foreman_patch/host/reschedule.rb', line 6

def plan(*hosts, **options)
  hosts = hosts.flatten
  input.update(**options, hosts: hosts.map(&:to_action_input))

  statuses = ['planned']
  statuses << 'scheduled' if options.fetch(:include_active, false)

  # this query must be converted to array otherwise changes will alter the results
  windows = ::ForemanPatch::Window.with_hosts(hosts).with_status(statuses).to_a

  sequence do
    ::ForemanPatch::Invocation.in_windows(windows).where(host: hosts).each do |invocation|
      plan_action(Actions::ForemanPatch::Invocation::Reschedule, invocation)
    end
    ::ForemanPatch::Round.in_windows(windows).missing_hosts(hosts).each do |round|
      plan_action(Actions::ForemanPatch::Round::AddMissingHosts, round, hosts)
    end

    plan_action(Actions::BulkAction, Actions::ForemanPatch::Window::Publish, windows) unless windows.empty?
  end
end