Class: Vagrant::Action::VM::Export

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/action/vm/export.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Export

Returns a new instance of Export.



9
10
11
12
# File 'lib/vagrant/action/vm/export.rb', line 9

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

Instance Attribute Details

#temp_dirObject (readonly)

Returns the value of attribute temp_dir.



7
8
9
# File 'lib/vagrant/action/vm/export.rb', line 7

def temp_dir
  @temp_dir
end

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vagrant/action/vm/export.rb', line 14

def call(env)
  @env = env

  raise Errors::VMPowerOffToPackage if @env["vm"].state != :poweroff

  setup_temp_dir
  export

  @app.call(env)

  recover(env) # called to cleanup temp directory
end

#exportObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vagrant/action/vm/export.rb', line 39

def export
  @env[:ui].info I18n.t("vagrant.actions.vm.export.exporting")
  @env[:vm].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

#ovf_pathObject



51
52
53
# File 'lib/vagrant/action/vm/export.rb', line 51

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

#recover(env) ⇒ Object



27
28
29
30
31
# File 'lib/vagrant/action/vm/export.rb', line 27

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

#setup_temp_dirObject



33
34
35
36
37
# File 'lib/vagrant/action/vm/export.rb', line 33

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