Class: Bosh::Cli::LogsDownloader
Instance Method Summary collapse
- #build_destination_path(job_name, job_index_or_id, directory) ⇒ Object
- #download(resource_id, logs_destination_path) ⇒ Object
-
#initialize(director, ui) ⇒ LogsDownloader
constructor
A new instance of LogsDownloader.
Constructor Details
#initialize(director, ui) ⇒ LogsDownloader
Returns a new instance of LogsDownloader.
3 4 5 6 |
# File 'lib/cli/logs_downloader.rb', line 3 def initialize(director, ui) @director = director @ui = ui end |
Instance Method Details
#build_destination_path(job_name, job_index_or_id, directory) ⇒ Object
8 9 10 11 |
# File 'lib/cli/logs_downloader.rb', line 8 def build_destination_path(job_name, job_index_or_id, directory) time = Time.now.strftime('%Y-%m-%d-%H-%M-%S') File.join(directory, "#{job_name}.#{job_index_or_id}.#{time}.tgz") end |
#download(resource_id, logs_destination_path) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cli/logs_downloader.rb', line 13 def download(resource_id, logs_destination_path) @ui.say("Downloading log bundle (#{resource_id.to_s.make_green})...") @ui.nl begin tmp_file = @director.download_resource(resource_id) FileUtils.mv(tmp_file, logs_destination_path) @ui.say("Logs saved in '#{logs_destination_path.make_green}'") @ui.nl rescue Bosh::Cli::DirectorError => e @ui.err("Unable to download logs from director: #{e}") ensure FileUtils.rm_rf(tmp_file) if tmp_file end end |