Class: Vagrant::Actions::VM::Package
- Defined in:
- lib/vagrant/actions/vm/package.rb
Instance Attribute Summary collapse
-
#export_action ⇒ Object
readonly
Returns the value of attribute export_action.
-
#include_files ⇒ Object
Returns the value of attribute include_files.
-
#out_path ⇒ Object
Returns the value of attribute out_path.
Attributes inherited from Base
Instance Method Summary collapse
- #compress ⇒ Object
- #execute! ⇒ Object
-
#initialize(vm, out_path = nil, include_files = nil, *args) ⇒ Package
constructor
A new instance of Package.
- #prepare ⇒ Object
- #tar_path ⇒ Object
- #temp_path ⇒ Object
Methods inherited from Base
#cleanup, #follows, #precedes, #rescue
Methods included from Util
#error_and_exit, included, #logger, #wrap_output
Constructor Details
#initialize(vm, out_path = nil, include_files = nil, *args) ⇒ Package
Returns a new instance of Package.
9 10 11 12 13 14 |
# File 'lib/vagrant/actions/vm/package.rb', line 9 def initialize(vm, out_path = nil, include_files = nil, *args) super @out_path = out_path || "package" @include_files = include_files || [] @temp_path = nil end |
Instance Attribute Details
#export_action ⇒ Object (readonly)
Returns the value of attribute export_action.
7 8 9 |
# File 'lib/vagrant/actions/vm/package.rb', line 7 def export_action @export_action end |
#include_files ⇒ Object
Returns the value of attribute include_files.
6 7 8 |
# File 'lib/vagrant/actions/vm/package.rb', line 6 def include_files @include_files end |
#out_path ⇒ Object
Returns the value of attribute out_path.
5 6 7 |
# File 'lib/vagrant/actions/vm/package.rb', line 5 def out_path @out_path end |
Instance Method Details
#compress ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/vagrant/actions/vm/package.rb', line 39 def compress logger.info "Packaging VM into #{tar_path} ..." File.open(tar_path, File::CREAT | File::WRONLY, 0644) do |tar| Archive::Tar::Minitar::Output.open(tar) do |output| begin current_dir = FileUtils.pwd include_files.each do |f| logger.info "Packaging additional file: #{f}" Archive::Tar::Minitar.pack_file(f, output) end FileUtils.cd(temp_path) Dir.glob(File.join(".", "*")).each do |entry| Archive::Tar::Minitar.pack_file(entry, output) end ensure FileUtils.cd(current_dir) end end end end |
#execute! ⇒ Object
27 28 29 |
# File 'lib/vagrant/actions/vm/package.rb', line 27 def execute! compress end |
#prepare ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/vagrant/actions/vm/package.rb', line 16 def prepare # Verify the existance of all the additional files, if any @include_files.each do |file| raise ActionException.new(:package_include_file_doesnt_exist, :filename => file) unless File.exists?(file) end # Get the export action and store a reference to it @export_action = @runner.find_action(Export) raise ActionException.new(:packaged_requires_export) unless @export_action end |
#tar_path ⇒ Object
31 32 33 |
# File 'lib/vagrant/actions/vm/package.rb', line 31 def tar_path File.join(FileUtils.pwd, "#{out_path}#{@runner.env.config.package.extension}") end |
#temp_path ⇒ Object
35 36 37 |
# File 'lib/vagrant/actions/vm/package.rb', line 35 def temp_path export_action.temp_dir end |