Sha256: 75b85a5f468202e086d1e6a9616615b760036461ae2ac83c5289e1755f9149ca

Contents?: true

Size: 1.4 KB

Versions: 19

Compression:

Stored size: 1.4 KB

Contents

require "fileutils"

module VagrantPlugins
  module ProviderVirtualBox
    module Action
      class Export
        attr_reader :temp_dir

        def initialize(app, env)
          @app = app
        end

        def call(env)
          @env = env

          raise Vagrant::Errors::VMPowerOffToPackage if \
            @env[:machine].provider.state.id != :poweroff

          setup_temp_dir
          export

          @app.call(env)

          recover(env) # called to cleanup temp directory
        end

        def recover(env)
          if temp_dir && File.exist?(temp_dir)
            FileUtils.rm_rf(temp_dir)
          end
        end

        def setup_temp_dir
          @env[:ui].info I18n.t("vagrant.actions.vm.export.create_dir")
          @temp_dir = @env["export.temp_dir"] = @env[:tmp_path].join(Time.now.to_i.to_s)
          FileUtils.mkpath(@env["export.temp_dir"])
        end

        def export
          @env[:ui].info I18n.t("vagrant.actions.vm.export.exporting")
          @env[:machine].provider.driver.export(ovf_path) do |progress|
            @env[:ui].clear_line
            @env[:ui].report_progress(progress.percent, 100, false)
          end

          # Clear the line a final time so the next data can appear
          # alone on the line.
          @env[:ui].clear_line
        end

        def ovf_path
          File.join(@env["export.temp_dir"], "box.ovf")
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 6 rubygems

Version Path
tamtam-vagrant-reload-1.1.3 vendor/cache/vagrant-0ac2a8738841/plugins/providers/virtualbox/action/export.rb
tamtam-vagrant-reload-1.1.2 vendor/cache/vagrant-0ac2a8738841/plugins/providers/virtualbox/action/export.rb
tamtam-vagrant-reload-1.1.1 vendor/cache/vagrant-0ac2a8738841/plugins/providers/virtualbox/action/export.rb
tamtam-vagrant-reload-1.1 vendor/cache/vagrant-0ac2a8738841/plugins/providers/virtualbox/action/export.rb
tnargav-1.3.6 plugins/providers/virtualbox/action/export.rb
tnargav-1.3.3 plugins/providers/virtualbox/action/export.rb
vagrant-shell-0.2.9 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/plugins/providers/virtualbox/action/export.rb
tnargav-1.2.3 plugins/providers/virtualbox/action/export.rb
vagrant-shell-0.2.8 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/plugins/providers/virtualbox/action/export.rb
vagrant-shell-0.2.6 vendor/bundle/gems/tnargav-1.2.2/plugins/providers/virtualbox/action/export.rb
vagrant-shell-0.2.5 vendor/bundle/gems/tnargav-1.2.2/plugins/providers/virtualbox/action/export.rb
tnargav-1.2.2 plugins/providers/virtualbox/action/export.rb
vagrantup-1.1.3 plugins/providers/virtualbox/action/export.rb
vagrantup-1.1.2 plugins/providers/virtualbox/action/export.rb
vagrantup-1.1.1 plugins/providers/virtualbox/action/export.rb
vagrantup-1.1.0 plugins/providers/virtualbox/action/export.rb
vagrantup-1.1.4 plugins/providers/virtualbox/action/export.rb
vagrant-actionio-0.0.9 vendor/bundle/bundler/gems/vagrant-c74251a1d9c0/plugins/providers/virtualbox/action/export.rb
vagrant-lxc-0.0.1 vendor/vagrant/plugins/providers/virtualbox/action/export.rb