lib/testlab/container/io.rb in testlab-0.9.0 vs lib/testlab/container/io.rb in testlab-0.9.1

- old
+ new

@@ -28,23 +28,27 @@ self.node.ssh.bootstrap(<<-EOF) set -x set -e du -sh #{self.lxc.container_root} + cd #{self.lxc.container_root} find #{root_fs_path} -depth -print0 | cpio -o0 | pbzip2 -#{compression} -vfczm#{PBZIP2_MEMORY} > #{remote_file} chown ${SUDO_USER}:${SUDO_USER} #{remote_file} + ls -lah #{remote_file} EOF end please_wait(:ui => @ui, :message => format_object_action(self, 'Export', :cyan)) do File.exists?(local_file) and FileUtils.rm_f(local_file) self.node.ssh.download(remote_file, local_file) end - puts("Your shipping container is now exported and available at '#{local_file}'!") + @ui.stdout.puts + @ui.stdout.puts("Your shipping container is now exported and available at '#{local_file}'!".green.bold) + @ui.stdout.puts true end # Import the container @@ -74,17 +78,43 @@ self.node.ssh.bootstrap(<<-EOF) set -x set -e ls -lah #{remote_file} + +rm -rf #{self.lxc.fs_root} cd #{self.lxc.container_root} -rm -rf #{root_fs_path} pbzip2 -vdcm#{PBZIP2_MEMORY} #{remote_file} | cpio -uid && rm -fv #{remote_file} + du -sh #{self.lxc.container_root} EOF end - puts("Your shipping container is now imported and available for use!") + @ui.stdout.puts + @ui.stdout.puts("Your shipping container is now imported and available for use!".green.bold) + @ui.stdout.puts + + true + end + + # Copy the container + # + # Duplicates this container under another container definition. + # + # @return [Boolean] True if successful. + def copy(to_name) + @ui.logger.debug { "Container Copy: #{self.id}" } + + to_container = self.node.containers.select{ |c| c.id.to_sym == to_name.to_sym }.first + to_container.nil? and raise ContainerError, "We could not locate the target container!" + + to_container.demolish + to_container.create + + please_wait(:ui => @ui, :message => format_object_action(self, 'Copy', :yellow)) do + self.node.ssh.exec(%(sudo rm -rf #{to_container.lxc.fs_root})) + self.node.ssh.exec(%(sudo rsync -a #{self.lxc.fs_root} #{to_container.lxc.container_root})) + end true end end