Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix #398 missing ip forwarding #399

Merged
merged 7 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions lib/vagrant-parallels/action/forward_ports.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ForwardPorts
include VagrantPlugins::Parallels::Util::CompileForwardedPorts
@@lock = Mutex.new

def initialize(app, env)
def initialize(app, _env)
@app = app
end

Expand All @@ -22,17 +22,15 @@ def call(env)
return @app.call(env) if env[:forwarded_ports].empty?

# Acquire both of class- and process-level locks so that we don't
# forward ports simultaneousely with someone else.
# forward ports simultaneously with someone else.
@@lock.synchronize do
begin
env[:machine].env.lock('forward_ports') do
env[:ui].output(I18n.t('vagrant.actions.vm.forward_ports.forwarding'))
forward_ports
end
rescue Errors::EnvironmentLockedError
sleep 1
retry
env[:machine].env.lock('forward_ports') do
env[:ui].output(I18n.t('vagrant.actions.vm.forward_ports.forwarding'))
forward_ports
end
rescue Vagrant::Errors::EnvironmentLockedError
sleep 1
retry
end

@app.call(env)
Expand All @@ -46,15 +44,17 @@ def forward_ports
@env[:forwarded_ports].each do |fp|
message_attributes = {
guest_port: fp.guest_port,
host_port: fp.host_port
guest_ip: fp.guest_ip,
host_port: fp.host_port,
host_ip: fp.host_ip
}

# Assuming the only reason to establish port forwarding is
# because the VM is using Shared networking. Host-only and
# bridged networking don't require port-forwarding and establishing
# forwarded ports on these attachment types has uncertain behaviour.
@env[:ui].detail(I18n.t('vagrant_parallels.actions.vm.forward_ports.forwarding_entry',
message_attributes))
**message_attributes))

# In Parallels Desktop the scope port forwarding rules is global,
# so we have to keep their names unique.
Expand All @@ -69,14 +69,16 @@ def forward_ports

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

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