From a3c10b9e2f7343cf5ab859f9a5869820530d88a8 Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Tue, 16 Sep 2014 18:01:46 +0200 Subject: [PATCH] add gateway_ports option This allows access to forwarded ports from outside the host. Fixes #231. --- README.md | 6 ++++++ lib/vagrant-libvirt/action/forward_ports.rb | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 60815be..169617c 100644 --- a/README.md +++ b/README.md @@ -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 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 vagrant-libvirt supports bidirectional synced folders via nfs or 9p and diff --git a/lib/vagrant-libvirt/action/forward_ports.rb b/lib/vagrant-libvirt/action/forward_ports.rb index 3e52ed7..29de638 100644 --- a/lib/vagrant-libvirt/action/forward_ports.rb +++ b/lib/vagrant-libvirt/action/forward_ports.rb @@ -53,7 +53,8 @@ module VagrantPlugins fp[:host_ip] || 'localhost', fp[: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) end @@ -78,13 +79,15 @@ module VagrantPlugins mappings.values 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 params = %W( "-L #{host_ip}:#{host_port}:#{guest_ip}:#{guest_port}" -N #{ssh_info[:host]} ).join(' ') + params += ' -g' if gateway_ports options = (%W( User=#{ssh_info[:username]}