Module: VirtualboxWSL2::WSL2CompileForwardedPorts
- Includes:
- Vagrant::Util::ScopedHashOverride
- Defined in:
- lib/virtualbox_WSL2.rb
Instance Method Summary collapse
-
#compile_forwarded_ports(config) ⇒ Object
This method compiles the forwarded ports into ForwardedPort models.
Instance Method Details
#compile_forwarded_ports(config) ⇒ Object
This method compiles the forwarded ports into ForwardedPort models.
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 |
# File 'lib/virtualbox_WSL2.rb', line 14 def compile_forwarded_ports(config) mappings = {} config.vm.networks.each do |type, | if type == :forwarded_port guest_port = [:guest] host_port = [:host] host_ip = [:host_ip] protocol = [:protocol] || "tcp" = scoped_hash_override(, :virtualbox) id = [:id] # If the forwarded port was marked as disabled, ignore. next if [:disabled] key = "#{host_ip}#{protocol}#{host_port}" mappings[key] = VagrantPlugins::ProviderVirtualBox::Model::ForwardedPort.new(id, host_port, guest_port, ) end end # Creating the second port forwarding entry for connections from WSL2 via Windows IP mappings.dup.each do |k, v| if Vagrant::Util::Platform.wsl? and k.start_with?("127.0.0.1tcp") and (v.id == "ssh") host_ip = "0.0.0.0" host_port = v.host_port guest_port = v.guest_port protocol = v.protocol id = "ssh_wsl2" auto_correct = v.auto_correct adapter = v.adapter guest_ip = v.guest_ip key = "#{host_ip}#{protocol}#{host_port}" mappings[key] = VagrantPlugins::ProviderVirtualBox::Model::ForwardedPort.new(id, host_port, guest_port, {:host_ip => host_ip, :protocol => protocol, :auto_correct => auto_correct, :adapter => adapter, :guest_ip => guest_ip}) end end mappings.values end |