Class: HammerCLIForemanDiscovery::DiscoveredHost::RebootCommand

Inherits:
HammerCLIForeman::SingleResourceCommand
  • Object
show all
Defined in:
lib/hammer_cli_foreman_discovery/discovery.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/hammer_cli_foreman_discovery/discovery.rb', line 174

def execute
  if option_all?
    begin
      resource.call(:reboot_all, {})
      print_message _("Rebooting hosts")
      HammerCLI::EX_OK
    rescue RestClient::UnprocessableEntity => e
      response = JSON.parse(e.response)
      response = HammerCLIForeman.record_to_common_format(response) unless response.key?('message')
      output.print_error(response['host_details'].map { |i| "#{i['name']}: #{i['error']}" }.join("\n"))
      HammerCLI::EX_DATAERR
    end
  else
    super
  end
end