Halt works with new machine.

This required some modifications to the linux guest implementation. And
the other guests will have to be modified as well. This is because
`channel` is now `communicate`.
This commit is contained in:
Mitchell Hashimoto 2012-08-12 18:54:52 -07:00
parent f9752d78d8
commit 0eddda3552
4 changed files with 28 additions and 12 deletions

View File

@ -83,6 +83,15 @@ module Vagrant
# @see #execute
def sudo(command, opts=nil)
end
# Executes a command and returns true if the command succeeded,
# and false otherwise. By default, this executes as a normal user,
# and it is up to the communicator implementation if they expose an
# option for running tests as an administrator.
#
# @see #execute
def test(command, opts=nil)
end
end
end
end

View File

@ -85,6 +85,11 @@ module VagrantPlugins
end
end
def test(command, opts=nil)
opts = { :error_check => false }.merge(opts || {})
execute(command, opts) == 0
end
def upload(from, to)
@logger.debug("Uploading: #{from} to #{to}")

View File

@ -16,23 +16,25 @@ module VagrantPlugins
end
def distro_dispatch
if @vm.channel.test("cat /etc/debian_version")
return :debian if @vm.channel.test("cat /proc/version | grep 'Debian'")
return :ubuntu if @vm.channel.test("cat /proc/version | grep 'Ubuntu'")
end
@vm.communicate.tap do |comm|
if comm.test("cat /etc/debian_version") == 0
return :debian if comm.test("cat /proc/version | grep 'Debian'") == 0
return :ubuntu if comm.test("cat /proc/version | grep 'Ubuntu'") == 0
end
return :gentoo if @vm.channel.test("cat /etc/gentoo-release")
return :fedora if @vm.channel.test("grep 'Fedora release 16' /etc/redhat-release")
return :redhat if @vm.channel.test("cat /etc/redhat-release")
return :suse if @vm.channel.test("cat /etc/SuSE-release")
return :arch if @vm.channel.test("cat /etc/arch-release")
return :gentoo if comm.test("cat /etc/gentoo-release") == 0
return :fedora if comm.test("grep 'Fedora release 16' /etc/redhat-release") == 0
return :redhat if comm.test("cat /etc/redhat-release") == 0
return :suse if comm.test("cat /etc/SuSE-release") == 0
return :arch if comm.test("cat /etc/arch-release") == 0
end
# Can't detect the distro, assume vanilla linux
nil
end
def halt
@vm.channel.sudo("shutdown -h now")
@vm.communicate.sudo("shutdown -h now")
# Wait until the VM's state is actually powered off. If this doesn't
# occur within a reasonable amount of time (15 seconds by default),

View File

@ -17,9 +17,9 @@ module VagrantPlugins
end
# If we're not powered off now, then force it
if env[:machine].state != :poweroff
if env[:machine].provider.state != :poweroff
env[:ui].info I18n.t("vagrant.actions.vm.halt.force")
env[:machine].driver.halt
env[:machine].provider.halt
end
# Sleep for a second to verify that the VM properly