Class: HammerCLIForemanBootdisk::DownloadCommand

Inherits:
HammerCLIForeman::Command
  • Object
show all
Defined in:
lib/hammer_cli_foreman_bootdisk/commands.rb

Instance Method Summary collapse

Instance Method Details

rubocop:disable Layout/LineLength

Raises:

  • (HammerCLIForeman::OperationNotSupportedError)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/hammer_cli_foreman_bootdisk/commands.rb', line 13

def print_data(record)
  server_filename = ::Regexp.last_match(1) if record.headers[:content_disposition].match?(/filename=["']?([^\s,;"']+)/)
  file = options[HammerCLI.option_accessor_name('file')] || server_filename || 'bootdisk.iso'
  raise(HammerCLIForeman::OperationNotSupportedError, _("Destination %s already exists and isn't a regular file, use '--force' if you are sure you wish to write to it") % file) if !options[HammerCLI.option_accessor_name('force')] && File.exist?(file) && !File.file?(file)

  if options[HammerCLI.option_accessor_name('sudo')]
    temp_file = Tempfile.new('bootdisk')
    begin
      File.write(temp_file, record)
      system('sudo', 'dd', "if=#{temp_file.path}", "of=#{file}", 'bs=1024')
    ensure
      temp_file.close
      temp_file.unlink
    end
  else
    File.write(file, record)
  end
  print_message(success_message % file) if success_message
end

#request_optionsObject

rubocop:enable Layout/LineLength



34
35
36
# File 'lib/hammer_cli_foreman_bootdisk/commands.rb', line 34

def request_options
  { response: :raw }
end