lib/testlab/container/io.rb in testlab-1.11.2 vs lib/testlab/container/io.rb in testlab-1.11.3

- old
+ new

@@ -6,13 +6,13 @@ require 'net/https' if RUBY_VERSION < '1.9' require 'tempfile' PBZIP2_MEMORY = 1024 READ_SIZE = ((64 * 1024) - 1) - TRANSFER_MESSAGE = "transferring '%s' at %0.2fMB/s -- %0.2fMB of %0.2fMB -- %d%% (%01d:%02dT-%01d:%02d) \r" + TRANSFER_MESSAGE = "%s '%s' at %0.2fMB/s -- %0.2fMB of %0.2fMB -- %d%% (%01d:%02dT-%01d:%02d) \r" - def transfer_message(filename, current_size, total_size, elapsed) + def transfer_message(what, filename, current_size, total_size, elapsed) total_size_mb = (total_size.to_f / (1024 * 1024).to_f) current_size_mb = (current_size.to_f / (1024 * 1024).to_f) speed = (current_size.to_f / elapsed.to_f) speed = total_size.to_f if (speed == 0.0) @@ -25,11 +25,11 @@ est_minutes = estimated.div(60) est_seconds = estimated.modulo(60) percentage_done = ((current_size * 100) / total_size) - @ui.stdout.print(format_message(TRANSFER_MESSAGE.yellow % [File.basename(filename), speed_mb, current_size_mb, total_size_mb, percentage_done, minutes, seconds, est_minutes, est_seconds])) + @ui.stdout.print(format_message(TRANSFER_MESSAGE.yellow % [what, File.basename(filename), speed_mb, current_size_mb, total_size_mb, percentage_done, minutes, seconds, est_minutes, est_seconds])) end def progress_callback(action, args) @total_size ||= 0 @@ -42,11 +42,11 @@ when :get, :put then elapsed = (Time.now - @start_time) current_size = (args[1] + args[2].length) - transfer_message(args[0].local, current_size, @total_size, elapsed) + transfer_message(%(uploading to node:), args[0].local, current_size, @total_size, elapsed) when :finish @ui.stdout.puts @total_size = 0 @@ -57,10 +57,13 @@ # # @return [Boolean] True if successful. def export(compression=9, local_file=nil) @ui.logger.debug { "Container Export: #{self.id} " } + self.node.alive? or return false + self.node.ok? + (self.state == :not_created) and raise ContainerError, 'You must create a container before you can export it!' # Throw an exception if we are attempting to export a container in a # ephemeral state. self.lxc_clone.exists? and raise ContainerError, 'You can not export ephemeral containers!' @@ -117,10 +120,13 @@ # # @return [Boolean] True if successful. def import(local_file) @ui.logger.debug { "Container Import: #{self.id}" } + self.node.alive? or return false + self.node.ok? + import_tempfile = Tempfile.new('import') remote_filename = File.basename(import_tempfile.path.dup) import_tempfile.close! remote_file = File.join("", "tmp", remote_filename) @@ -252,10 +258,10 @@ tempfile << chunk elapsed = (Time.now - start_time) current_size += chunk.size - transfer_message(local_file, current_size, total_size, elapsed) + transfer_message(%(downloading locally:), local_file, current_size, total_size, elapsed) end @ui.stdout.puts tempfile.close