Class: Vagrant::Action::VM::Modify
- Inherits:
-
Object
- Object
- Vagrant::Action::VM::Modify
- Includes:
- Util::StackedProcRunner
- Defined in:
- lib/vagrant/action/vm/modify.rb
Overview
This class allows other actions on the virtual machine object to be consolidated under a single write lock. This vastly speeds up modification of virtual machines. This should be used whereever possible when dealing with virtual machine modifications.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ Modify
constructor
A new instance of Modify.
Methods included from Util::StackedProcRunner
#proc_stack, #push_proc, #run_procs!
Constructor Details
#initialize(app, env) ⇒ Modify
Returns a new instance of Modify.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/vagrant/action/vm/modify.rb', line 11 def initialize(app, env) @app = app # Initialize the proc_stack, which should already be empty # but just making sure here. proc_stack.clear # Create the lambda in the environment which is to be called # to add new procs to the modification sequence. env["vm.modify"] = lambda do |*procs| procs.each { |p| push_proc(&p) } end end |
Instance Method Details
#call(env) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/vagrant/action/vm/modify.rb', line 25 def call(env) # Run the procs we have saved up, save the machine, and reload # to verify we get the new settings run_procs!(env["vm"].vm) env["vm"].vm.save env["vm"].reload! @app.call(env) end |