Class: Vagrant::Action::VM::Halt

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

Instance Method Summary collapse

Constructor Details

#initialize(app, env, options = nil) ⇒ Halt

Returns a new instance of Halt.



5
6
7
8
# File 'lib/vagrant/action/vm/halt.rb', line 5

def initialize(app, env, options=nil)
  @app = app
  env.merge!(options || {})
end

Instance Method Details

#call(env) ⇒ Object



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

def call(env)
  if env["vm"].created? && env["vm"].vm.running?
    env["vm"].system.halt if !env["force"]

    if env["vm"].vm.state(true) != :powered_off
      env.ui.info I18n.t("vagrant.actions.vm.halt.force")
      env["vm"].vm.stop
    end

    # Sleep for a second to verify that the VM properly
    # cleans itself up
    sleep 1 if !env["vagrant.test"]
  end

  @app.call(env)
end