Module: VagrantPlugins::VCloud::Util::CompileForwardedPorts

Includes:
Vagrant::Util::ScopedHashOverride
Included in:
Action::ForwardPorts
Defined in:
lib/vagrant-vcloud/util/compile_forwarded_ports.rb

Instance Method Summary collapse

Instance Method Details

#compile_forwarded_ports(machine) ⇒ Object

This method compiles the forwarded ports into ForwardedPort models.



11
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
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
# File 'lib/vagrant-vcloud/util/compile_forwarded_ports.rb', line 11

def compile_forwarded_ports(machine)
  mappings = {}

  machine.config.vm.networks.each do |type, options|
    if type == :forwarded_port
      guest_port = options[:guest]
      host_port  = options[:host]
      options    = scoped_hash_override(options, :vcloud)
      id         = options[:id]

      # skip forwarded rules already found in handle_nat_port_collisions
      next if options[:already_exists]

      # skip forwarded rules if disabled
      next if !options[:disabled].nil? && options[:disabled] == true

      mappings[host_port] =
        Model::ForwardedPort.new(id, host_port, guest_port, 'Vagrant-vApp-Net', machine.provider_config.vdc_network_id, machine.provider_config.vdc_network_name, options)
    end
  end
  if !machine.provider_config.nics.nil?
    machine.provider_config.nics.each do |nic|
      next if nic[:forwarded_port].nil?
      nic[:forwarded_port].each do |fp|
        options = fp

        guest_port = options[:guest]
        host_port  = options[:host]
        options    = scoped_hash_override(options, :vcloud)
        id         = options[:id]

        # skip forwarded rules already found in handle_nat_port_collisions
        next if options[:already_exists]

        # skip forwarded rules if disabled
        next if !options[:disabled].nil? && options[:disabled] == true

        # find matching network
        edge_id = nil
        edge_name = nil
        if !machine.provider_config.networks.nil? && !machine.provider_config.networks[:vapp].nil?
          machine.provider_config.networks[:vapp].each do |net|
            next if net[:name] != nic[:network]
            edge_id = net[:parent_network]
            edge_name = net[:vdc_network_name]
            break
          end
        end
        if edge_id == nil || edge_name == nil
          edge_id = machine.provider_config.vdc_network_id
          edge_name = machine.provider_config.vdc_network_name
        end

        mappings[host_port] = Model::ForwardedPort.new(id, host_port, guest_port, nic[:network], edge_id, edge_name, options)

      end
    end
  end

  mappings.values
end