Class: VagrantPlugins::ProviderLibvirt::Action::ForwardPorts
- Inherits:
-
Object
- Object
- VagrantPlugins::ProviderLibvirt::Action::ForwardPorts
- Defined in:
- lib/vagrant-libvirt/action/forward_ports.rb
Overview
Adds support for vagrant’s ‘forward_ports` configuration directive.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #forward_ports ⇒ Object
-
#initialize(app, env) ⇒ ForwardPorts
constructor
A new instance of ForwardPorts.
Constructor Details
#initialize(app, env) ⇒ ForwardPorts
Returns a new instance of ForwardPorts.
6 7 8 9 |
# File 'lib/vagrant-libvirt/action/forward_ports.rb', line 6 def initialize(app, env) @app = app @logger = Log4r::Logger.new('vagrant_libvirt::action::forward_ports') end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vagrant-libvirt/action/forward_ports.rb', line 11 def call(env) @env = env # Get the ports we're forwarding env[:forwarded_ports] = compile_forwarded_ports(env[:machine].config) # Warn if we're port forwarding to any privileged ports env[:forwarded_ports].each do |fp| if fp[:host] <= 1024 env[:ui].warn I18n.t( 'vagrant.actions.vm.forward_ports.privileged_ports' ) break end end # Continue, we need the VM to be booted in order to grab its IP @app.call env if @env[:forwarded_ports].any? env[:ui].info I18n.t('vagrant.actions.vm.forward_ports.forwarding') forward_ports end end |
#forward_ports ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/vagrant-libvirt/action/forward_ports.rb', line 36 def forward_ports @env[:forwarded_ports].each do |fp| = { adapter: 'eth0', guest_port: fp[:guest], host_port: fp[:host] } @env[:ui].info(I18n.t( 'vagrant.actions.vm.forward_ports.forwarding_entry', )) ssh_pid = redirect_port( @env[:machine], fp[:host_ip] || 'localhost', fp[:host], fp[:guest_ip] || @env[:machine].provider.ssh_info[:host], fp[:guest] ) store_ssh_pid(fp[:host], ssh_pid) end end |