add gateway_ports option

This allows access to forwarded ports from outside the host.
Fixes #231.
This commit is contained in:
Adam Spiers
2014-09-16 18:01:46 +02:00
parent 64c40ffee6
commit a3c10b9e2f
2 changed files with 11 additions and 2 deletions

View File

@@ -309,6 +309,12 @@ vagrant-libvirt supports Forwarded Ports via ssh port forwarding. For each
`forwarded_port` directive you specify in your Vagrantfile, vagrant-libvirt `forwarded_port` directive you specify in your Vagrantfile, vagrant-libvirt
will maintain an active ssh process for the lifetime of the VM. will maintain an active ssh process for the lifetime of the VM.
vagrant-libvirt supports an additional `forwarded_port` option
`gateway_ports` which defaults to `false`, but can be set to `true` if
you want the forwarded port to be accessible from outside the Vagrant
host. In this case you should also set the `host_ip` option to `'*'`
since it defaults to `'localhost'`.
## Synced Folders ## Synced Folders
vagrant-libvirt supports bidirectional synced folders via nfs or 9p and vagrant-libvirt supports bidirectional synced folders via nfs or 9p and

View File

@@ -53,7 +53,8 @@ module VagrantPlugins
fp[:host_ip] || 'localhost', fp[:host_ip] || 'localhost',
fp[:host], fp[:host],
fp[:guest_ip] || @env[:machine].provider.ssh_info[:host], fp[:guest_ip] || @env[:machine].provider.ssh_info[:host],
fp[:guest] fp[:guest],
fp[:gateway_ports] || false
) )
store_ssh_pid(fp[:host], ssh_pid) store_ssh_pid(fp[:host], ssh_pid)
end end
@@ -78,13 +79,15 @@ module VagrantPlugins
mappings.values mappings.values
end end
def redirect_port(machine, host_ip, host_port, guest_ip, guest_port) def redirect_port(machine, host_ip, host_port, guest_ip, guest_port,
gateway_ports)
ssh_info = machine.ssh_info ssh_info = machine.ssh_info
params = %W( params = %W(
"-L #{host_ip}:#{host_port}:#{guest_ip}:#{guest_port}" "-L #{host_ip}:#{host_port}:#{guest_ip}:#{guest_port}"
-N -N
#{ssh_info[:host]} #{ssh_info[:host]}
).join(' ') ).join(' ')
params += ' -g' if gateway_ports
options = (%W( options = (%W(
User=#{ssh_info[:username]} User=#{ssh_info[:username]}