Skip to content

Commit

Permalink
Use Shared IP from DHCP instead of detecting it via VM option.
Browse files Browse the repository at this point in the history
VM options work only if Parallels Tools installed in the guest. So, we should to use universal
approach to support NFS in such guests as CoreOS, FreeBSD, OmniOS and so on.

Related to: [GH-152]
  • Loading branch information
legal90 committed Oct 26, 2014
1 parent 404d06b commit 0d5b1a4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 32 deletions.
38 changes: 7 additions & 31 deletions lib/vagrant-parallels/action/prepare_nfs_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,16 @@ def call(env)
#
# The ! indicates that this method modifies its argument.
def add_ips_to_env!(env)
host_ip = @machine.provider.driver.read_shared_interface[:ip]
host_ip = @machine.provider.driver.read_shared_interface[:ip]
guest_ip = @machine.provider.driver.read_guest_ip

if !host_ip
# If we couldn't determine host's IP, then it is probably a bug.
# Display an appropriate error message.
raise Vagrant::Errors::NFSNoHostIP
end
# If we couldn't determine either guest's or host's IP, then
# it is probably a bug. Display an appropriate error message.
raise Vagrant::Errors::NFSNoHostIP if !host_ip
raise Vagrant::Errors::NFSNoGuestIP if !guest_ip

env[:nfs_host_ip] = host_ip
env[:nfs_machine_ip] = read_machine_ip
end

# Returns the IPv4 addresses of the guest by looking at VM options.
#
# For DHCP interfaces, the ip address will be present at the option
# value only after VM boot
#
# @return [String] ip addresses
def read_machine_ip
# We need to wait for the guest's IP to show up as a VM option.
# Retry thresholds are relatively high since we might need to wait
# for DHCP, but even static IPs can take a second or two to appear.
retryable(retry_options.merge(on: Errors::ParallelsVMOptionNotFound)) do
ips = @machine.provider.driver.read_vm_option('ip').split(' ')
ips.select! { |ip| IPAddr.new(ip).ipv4? }.sort
end
rescue Errors::ParallelsVMOptionNotFound
# Display an appropriate error message.
raise Vagrant::Errors::NFSNoGuestIP
end

# Separating these out so we can stub out the sleep in tests
def retry_options
{tries: 7, sleep: 2}
env[:nfs_machine_ip] = guest_ip
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-parallels/driver/meta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def initialize(uuid=nil)
:import,
:read_bridged_interfaces,
:read_forwarded_ports,
:read_guest_ip,
:read_guest_tools_state,
:read_guest_tools_iso_path,
:read_host_only_interfaces,
Expand All @@ -100,7 +101,6 @@ def initialize(uuid=nil)
:read_state,
:read_used_ports,
:read_virtual_networks,
:read_vm_option,
:read_vms,
:read_vms_info,
:read_vms_paths,
Expand Down

0 comments on commit 0d5b1a4

Please # to comment.