NAT checking for forwarded ports
This commit is contained in:
parent
1e21fdd67a
commit
e31ef01679
|
@ -91,6 +91,8 @@ module Vagrant
|
|||
def forward_ports(vm)
|
||||
ports = []
|
||||
|
||||
interfaces = @env[:vm].driver.read_network_interfaces
|
||||
|
||||
@env[:vm].config.vm.forwarded_ports.each do |name, options|
|
||||
adapter = options[:adapter] + 1
|
||||
message_attributes = {
|
||||
|
@ -107,13 +109,16 @@ module Vagrant
|
|||
@env[:ui].info(I18n.t("vagrant.actions.vm.forward_ports.forwarding_entry",
|
||||
message_attributes))
|
||||
|
||||
# Port forwarding requires the network interface to be a NAT interface,
|
||||
# so verify that that is the case.
|
||||
if interfaces[adapter][:type] != "nat"
|
||||
@env[:ui].info(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 << options.merge(:name => name, :adapter => adapter)
|
||||
|
||||
# TODO: Check for non-nat again... This was removed during the VBoxManage
|
||||
# transition but should be brought back.
|
||||
# @env[:ui].info(I18n.t("vagrant.actions.vm.forward_ports.non_nat",
|
||||
# message_attributes))
|
||||
end
|
||||
|
||||
@env[:vm].driver.forward_ports(ports)
|
||||
|
|
|
@ -227,13 +227,6 @@ module Vagrant
|
|||
results
|
||||
end
|
||||
|
||||
# This reads the guest additions version for a VM.
|
||||
def read_guest_additions_version
|
||||
output = execute("guestproperty", "get", @uuid, "/VirtualBox/GuestAdd/Version")
|
||||
return $1.to_s if output =~ /^Value: (.+?)$/
|
||||
return nil
|
||||
end
|
||||
|
||||
# This reads the list of host only networks.
|
||||
def read_bridged_interfaces
|
||||
execute("list", "bridgedifs").split("\n\n").collect do |block|
|
||||
|
@ -256,6 +249,13 @@ module Vagrant
|
|||
end
|
||||
end
|
||||
|
||||
# This reads the guest additions version for a VM.
|
||||
def read_guest_additions_version
|
||||
output = execute("guestproperty", "get", @uuid, "/VirtualBox/GuestAdd/Version")
|
||||
return $1.to_s if output =~ /^Value: (.+?)$/
|
||||
return nil
|
||||
end
|
||||
|
||||
# Reads and returns the available host only interfaces.
|
||||
def read_host_only_interfaces
|
||||
execute("list", "hostonlyifs").split("\n\n").collect do |block|
|
||||
|
@ -286,6 +286,23 @@ module Vagrant
|
|||
nil
|
||||
end
|
||||
|
||||
# This reads the network interfaces and returns various information
|
||||
# about them.
|
||||
#
|
||||
# @return [Hash]
|
||||
def read_network_interfaces
|
||||
nics = {}
|
||||
execute("showvminfo", @uuid, "--machinereadable").split("\n").each do |line|
|
||||
if line =~ /^nic(\d+)="(.+?)"$/
|
||||
nics[$1.to_i] = {
|
||||
:type => $2.to_s
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
nics
|
||||
end
|
||||
|
||||
# This reads the state for the given UUID. The state of the VM
|
||||
# will be returned as a symbol.
|
||||
def read_state
|
||||
|
|
Loading…
Reference in New Issue