Check for redir before forwarding ports

Make a system call out to `which` to see if redir exists on the PATH
before trying to forward ports.  Raises a VagrantError if it does not.
This commit is contained in:
Darrell Hamilton 2013-07-14 22:42:49 -07:00
parent 14c1ebfd7c
commit ad41c445a4
3 changed files with 29 additions and 14 deletions

View file

@ -26,28 +26,33 @@ module Vagrant
if @env[:forwarded_ports].any?
env[:ui].info I18n.t("vagrant.actions.vm.forward_ports.forwarding")
forward_ports
if redir_installed?
forward_ports
else
raise Errors::RedirNotInstalled
end
end
end
def forward_ports
@container_ip = @env[:machine].provider.driver.assigned_ip
@env[:forwarded_ports].each do |fp|
message_attributes = {
# TODO: Add support for multiple adapters
:adapter => 'eth0',
:guest_port => fp[:guest],
:host_port => fp[:host]
}
@env[:forwarded_ports].each do |fp|
message_attributes = {
# TODO: Add support for multiple adapters
:adapter => 'eth0',
:guest_port => fp[:guest],
:host_port => fp[:host]
}
# TODO: Remove adapter from logging
@env[:ui].info(I18n.t("vagrant.actions.vm.forward_ports.forwarding_entry",
message_attributes))
# TODO: Remove adapter from logging
@env[:ui].info(I18n.t("vagrant.actions.vm.forward_ports.forwarding_entry",
message_attributes))
redir_pid = redirect_port(fp[:host], fp[:guest])
store_redir_pid(fp[:host], redir_pid)
end
redir_pid = redirect_port(fp[:host], fp[:guest])
store_redir_pid(fp[:host], redir_pid)
end
end
private
@ -79,6 +84,10 @@ module Vagrant
pid_file.write(redir_pid)
end
end
def redir_installed?
system "sudo which redir"
end
end
end
end

View file

@ -17,6 +17,9 @@ module Vagrant
class IncompatibleBox < Vagrant::Errors::VagrantError
error_key(:lxc_incompatible_box)
end
class RedirNotInstalled < Vagrant::Errors::VagrantError
error_key(:lxc_redir_not_installed)
end
end
end
end

View file

@ -40,3 +40,6 @@ en:
lxc_template_file_missing: |-
The template file used for creating the container was not found for %{name}
box.
lxc_redir_not_installed: |-
`redir` is not installed or is not accessible on the PATH.