Class: Vagrant::LXC::Action::ForwardPorts
- Inherits:
-
Object
- Object
- Vagrant::LXC::Action::ForwardPorts
- Defined in:
- lib/vagrant-lxc/action/forward_ports.rb
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.
7 8 9 10 |
# File 'lib/vagrant-lxc/action/forward_ports.rb', line 7 def initialize(app, env) @app = app @logger = Log4r::Logger.new("vagrant::lxc::action::forward_ports") end |
Instance Method Details
#call(env) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/vagrant-lxc/action/forward_ports.rb', line 12 def call(env) @env = env # Get the ports we're forwarding env[:forwarded_ports] = compile_forwarded_ports(env[:machine].config) if @env[:forwarded_ports].any? and not redir_installed? raise Errors::RedirNotInstalled end # 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
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/vagrant-lxc/action/forward_ports.rb', line 39 def forward_ports @env[:forwarded_ports].each do |fp| = { # 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", )) redir_pid = redirect_port( fp[:host_ip], fp[:host], fp[:guest_ip] || @env[:machine].provider.ssh_info[:host], fp[:guest] ) store_redir_pid(fp[:host], redir_pid) end end |