Class: Vagrant::Actions::VM::Export

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

Instance Attribute Summary collapse

Attributes inherited from Base

#runner

Instance Method Summary collapse

Methods inherited from Base

#follows, #initialize, #precedes, #prepare

Methods included from Util

#error_and_exit, included, #logger, #wrap_output

Constructor Details

This class inherits a constructor from Vagrant::Actions::Base

Instance Attribute Details

#temp_dirObject (readonly)

Returns the value of attribute temp_dir.



5
6
7
# File 'lib/vagrant/actions/vm/export.rb', line 5

def temp_dir
  @temp_dir
end

Instance Method Details

#cleanupObject



12
13
14
15
16
17
# File 'lib/vagrant/actions/vm/export.rb', line 12

def cleanup
  if temp_dir
    logger.info "Removing temporary export directory..."
    FileUtils.rm_r(temp_dir)
  end
end

#execute!Object



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

def execute!
  setup_temp_dir
  export
end

#exportObject



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

def export
  logger.info "Exporting VM to #{ovf_path} ..."
  @runner.vm.export(ovf_path, {}, true)
end

#ovf_pathObject



30
31
32
# File 'lib/vagrant/actions/vm/export.rb', line 30

def ovf_path
  File.join(temp_dir, @runner.env.config.vm.box_ovf)
end

#rescue(exception) ⇒ Object



19
20
21
# File 'lib/vagrant/actions/vm/export.rb', line 19

def rescue(exception)
  cleanup
end

#setup_temp_dirObject



23
24
25
26
27
28
# File 'lib/vagrant/actions/vm/export.rb', line 23

def setup_temp_dir
  @temp_dir = File.join(@runner.env.tmp_path, Time.now.to_i.to_s)

  logger.info "Creating temporary directory for export..."
  FileUtils.mkpath(temp_dir)
end