`destroy` gets a little farther, and properly halts the VM
This commit is contained in:
parent
bca8663742
commit
2fc18f7207
|
@ -17,6 +17,7 @@ module Vagrant
|
|||
module Builtin
|
||||
autoload :Call, "vagrant/action/builtin/call"
|
||||
autoload :Confirm, "vagrant/action/builtin/confirm"
|
||||
autoload :EnvSet, "vagrant/action/builtin/env_set"
|
||||
autoload :SSHExec, "vagrant/action/builtin/ssh_exec"
|
||||
autoload :SSHRun, "vagrant/action/builtin/ssh_run"
|
||||
end
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
module Vagrant
|
||||
module Action
|
||||
module Builtin
|
||||
# This middleware class allows you to modify the environment hash
|
||||
# in the middle of a middleware sequence. The new environmental data
|
||||
# will take affect at this stage in the middleware and will persist
|
||||
# through.
|
||||
class EnvSet
|
||||
def initialize(app, env, new_env=nil)
|
||||
@app = app
|
||||
@new_env = new_env || {}
|
||||
end
|
||||
|
||||
def call(env)
|
||||
# Merge in the new data
|
||||
env.merge!(@new_env)
|
||||
|
||||
# Carry on
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,11 +4,11 @@ module VagrantPlugins
|
|||
def execute
|
||||
options = {}
|
||||
|
||||
opts = OptionParser.new do |opts|
|
||||
opts.banner = "Usage: vagrant destroy [vm-name]"
|
||||
opts.separator ""
|
||||
opts = OptionParser.new do |o|
|
||||
o.banner = "Usage: vagrant destroy [vm-name]"
|
||||
o.separator ""
|
||||
|
||||
opts.on("-f", "--force", "Destroy without confirmation.") do |f|
|
||||
o.on("-f", "--force", "Destroy without confirmation.") do |f|
|
||||
options[:force] = f
|
||||
end
|
||||
end
|
||||
|
|
|
@ -37,6 +37,8 @@ module VagrantPlugins
|
|||
if env2[:result]
|
||||
b3.use Vagrant::Action::General::Validate
|
||||
b3.use CheckAccessible
|
||||
b3.use EnvSet, :force => true
|
||||
b3.use action_halt
|
||||
else
|
||||
b3.use MessageWillNotDestroy
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ module VagrantPlugins
|
|||
if current_state == :running || current_state == :gurumeditation
|
||||
# If the VM is running and we're not forcing, we can
|
||||
# attempt a graceful shutdown
|
||||
if current_state == :running && !env["force"]
|
||||
if current_state == :running && !env[:force]
|
||||
env[:ui].info I18n.t("vagrant.actions.vm.halt.graceful")
|
||||
env[:machine].guest.halt
|
||||
end
|
||||
|
@ -19,7 +19,7 @@ module VagrantPlugins
|
|||
# If we're not powered off now, then force it
|
||||
if env[:machine].provider.state != :poweroff
|
||||
env[:ui].info I18n.t("vagrant.actions.vm.halt.force")
|
||||
env[:machine].provider.halt
|
||||
env[:machine].provider.driver.halt
|
||||
end
|
||||
|
||||
# Sleep for a second to verify that the VM properly
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
require File.expand_path("../../../../base", __FILE__)
|
||||
|
||||
describe Vagrant::Action::Builtin::EnvSet do
|
||||
let(:app) { lambda { |env| } }
|
||||
let(:env) { {} }
|
||||
|
||||
it "should set the new environment" do
|
||||
described_class.new(app, env, :foo => :bar).call(env)
|
||||
|
||||
env[:foo].should == :bar
|
||||
end
|
||||
|
||||
it "should call the next middleware" do
|
||||
callable = lambda { |env| env[:called] = env[:foo] }
|
||||
|
||||
env[:called].should be_nil
|
||||
described_class.new(callable, env, :foo => :yep).call(env)
|
||||
env[:called].should == :yep
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue