Class: VagrantPlugins::ProviderVeertu::Action::ForwardPorts

Inherits:
Object
  • Object
show all
Includes:
Util::CompileForwardedPorts
Defined in:
lib/vagrant-veertu/action/forward_ports.rb

Instance Method Summary collapse

Methods included from Util::CompileForwardedPorts

#compile_forwarded_ports

Constructor Details

#initialize(app, env) ⇒ ForwardPorts

Returns a new instance of ForwardPorts.



8
9
10
11
# File 'lib/vagrant-veertu/action/forward_ports.rb', line 8

def initialize(app, env)
  @app = app
  @logger = Log4r::Logger.new("vagrant::provider::veertu_5_0")
end

Instance Method Details

#call(env) ⇒ Object


Execution




16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vagrant-veertu/action/forward_ports.rb', line 16

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_port <= 1024
      env[:ui].warn I18n.t("vagrant.actions.vm.forward_ports.privileged_ports")
      break
    end
  end

  env[:ui].output(I18n.t("vagrant.actions.vm.forward_ports.forwarding"))
  forward_ports

  @app.call(env)
end

#forward_portsObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/vagrant-veertu/action/forward_ports.rb', line 36

def forward_ports
  ports = []

  #interfaces = @env[:machine].provider.driver.read_network_interfaces

  @env[:forwarded_ports].each do |fp|
    message_attributes = {
      adapter: fp.adapter,
      guest_port: fp.guest_port,
      host_port: fp.host_port
    }

    # Assuming the only reason to establish port forwarding is
    # because the VM is using Veertu NAT networking. Host-only
    # bridged networking don't require port-forwarding and establishing
    # forwarded ports on these attachment types has uncertain behaviour.
    @env[:ui].detail(I18n.t("vagrant.actions.vm.forward_ports.forwarding_entry",
                            message_attributes))
    @logger.debug(YAML::dump(fp))
    # Verify we have the network interface to attach to
    #if !interfaces[fp.adapter]
    #  raise Vagrant::Errors::ForwardPortAdapterNotFound,
    #    adapter: fp.adapter.to_s,
    #    guest: fp.guest_port.to_s,
    #    host: fp.host_port.to_s
    #end
    #
    ## Port forwarding requires the network interface to be a NAT interface,
    ## so verify that that is the case.
    #if interfaces[fp.adapter][:type] != :nat
    #  @env[:ui].detail(I18n.t("vagrant.actions.vm.forward_ports.non_nat",
    #                        message_attributes))
    #  next
    #end

    # Add the options to the ports array to send to the driver later
    ports << {
      adapter:   fp.adapter,
      guestip:   fp.guest_ip,
      guestport: fp.guest_port,
      hostip:    fp.host_ip,
      hostport:  fp.host_port,
      name:      fp.id,
      protocol:  fp.protocol
    }
  end

  if !ports.empty?
    # We only need to forward ports if there are any to forward
    @env[:machine].provider.driver.forward_ports(ports)
  end
end