15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'app/controllers/concerns/foreman_expire_hosts/host_controller_extensions.rb', line 15
def update_multiple_expiration
failed_hosts = {}
@hosts.each do |host|
begin
host.expired_on = expiration_date
host.save!
rescue StandardError => e
failed_hosts[host.name] = e
message = if expiration_date.present?
_('Failed to set expiration date for %{host} to %{expiration_date}.') % { :host => host, :expiration_date => l(expiration_date) }
else
_('Failed to clear expiration date for %s.') % host
end
Foreman::Logging.exception(message, e)
end
end
if failed_hosts.empty?
if expiration_date.present?
success _('The expiration date of the selected hosts was set to %s.') % l(expiration_date)
else
success _('The expiration date of the selected hosts was cleared.')
end
else
error n_('The expiration date could not be set for host: %s.',
'The expiration date could not be set for hosts: %s.',
failed_hosts.count) % failed_hosts.map { |h, err| "#{h} (#{err})" }.to_sentence
end
redirect_back_or_to hosts_path
end
|