Sha256: c3c75af05856c0439b10c738256675e9befe67491e0a0f0e5ede770d08ca8d5d

Contents?: true

Size: 1.48 KB

Versions: 4

Compression:

Stored size: 1.48 KB

Contents

require "log4r"
require "json"
require "fileutils"

module VagrantPlugins
  module XHYVE
    module Action
      # This terminates the running instance.
      class Import
        def initialize(app, env)
          @app    = app
          @logger = Log4r::Logger.new("vagrant_xhyve::action::import")
        end

        def call(env)

          #TODO: Progress bar
          env[:ui].info("Importing box...")
          # something like:
          # # tempfile is a File instance
          # File.open( new_file, 'wb' ) do |f|
          #   # Read in small 65k chunks to limit memory usage
          #     f.write(tempfile.read(2**16)) until tempfile.eof?
          #     end

          image_dir = File.join(env[:machine].data_dir, "image")
          box_dir = env[:machine].box.directory

          box_files = [File.join(box_dir, "vmlinuz"), File.join(box_dir, "initrd.gz")]

          0.upto(10).each do |blockidx|
            block_file = File.join(box_dir, "block#{blockidx}.img")
            if (File.exist? block_file) then
              box_files.push(block_file)
            else
              break
            end
          end

          FileUtils.mkdir_p(image_dir)
          FileUtils.cp(box_files, image_dir)

          env[:ui].info("Done importing box.")

          @app.call(env)
        end

        def process_alive(pid)
          begin
            Process.getpgid(pid)
            true
          rescue Errno::ESRCH
            false
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vagrant-xhyve-0.2.0 lib/vagrant-xhyve/action/import.rb
vagrant-xhyve-0.1.1 lib/vagrant-xhyve/action/import.rb
vagrant-xhyve-0.1.1.pre lib/vagrant-xhyve/action/import.rb
vagrant-xhyve-0.1.0.pre lib/vagrant-xhyve/action/import.rb