diff --git a/lib/vagrant-parallels/action/prepare_nfs_settings.rb b/lib/vagrant-parallels/action/prepare_nfs_settings.rb index 9f2aa57..a7b962b 100644 --- a/lib/vagrant-parallels/action/prepare_nfs_settings.rb +++ b/lib/vagrant-parallels/action/prepare_nfs_settings.rb @@ -37,7 +37,7 @@ 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] - guest_ip = @machine.provider.driver.read_guest_ip + guest_ip = @machine.provider.driver.ssh_ip # If we couldn't determine either guest's or host's IP, then # it is probably a bug. Display an appropriate error message. diff --git a/lib/vagrant-parallels/driver/base.rb b/lib/vagrant-parallels/driver/base.rb index 0156c1e..37bd5b2 100644 --- a/lib/vagrant-parallels/driver/base.rb +++ b/lib/vagrant-parallels/driver/base.rb @@ -403,11 +403,12 @@ def read_forwarded_ports(global = false) end end - # Returns an IP of the virtual machine. It requires that Shared network - # adapter is configured for this VM and it obtains an IP via DHCP. + # Returns an IP of the virtual machine fetched from the DHCP lease file. + # It requires that Shared network adapter is configured for this VM + # and it obtains an IP via DHCP. # # @return [String] IP address leased by DHCP server in "Shared" network - def read_guest_ip + def read_guest_ip_dhcp mac_addr = read_mac_address.downcase leases_file = '/Library/Preferences/Parallels/parallels_dhcp_leases' leases = {} @@ -430,6 +431,15 @@ def read_guest_ip leases.max_by { |_ip, lease_time| lease_time }.first end + # Returns an IP of the virtual machine fetched from prlctl. + # + # @return [String] IP address returned by `prlctl list -f` command + def read_guest_ip_prlctl + vm_info = json { execute_prlctl('list', @uuid, '--full', '--json') } + ip = vm_info.first.fetch('ip_configured', nil) + ip == '-' ? nil : ip + end + # Returns path to the Parallels Tools ISO file. # # @param [String] guest_os Guest os type: "linux", "darwin" or "windows" @@ -757,11 +767,14 @@ def share_folders(folders) end end - # Reads the SSH IP of this VM. + # Reads the SSH IP of this VM from DHCP lease file or from `prlctl list` + # command - whatever returns a non-empty result. + # The method with DHCP does not work for *.macvm VMs on Apple M-series Macs, + # so we try both sources here. # # @return [String] IP address to use for SSH connection to the VM. def ssh_ip - read_guest_ip + read_guest_ip_dhcp || read_guest_ip_prlctl end # Reads the SSH port of this VM. diff --git a/lib/vagrant-parallels/driver/meta.rb b/lib/vagrant-parallels/driver/meta.rb index 88cd69f..8860d90 100644 --- a/lib/vagrant-parallels/driver/meta.rb +++ b/lib/vagrant-parallels/driver/meta.rb @@ -87,7 +87,8 @@ def initialize(uuid=nil) :read_bridged_interfaces, :read_current_snapshot, :read_forwarded_ports, - :read_guest_ip, + :read_guest_ip_dhcp, + :read_guest_ip_prlctl, :read_guest_tools_state, :read_guest_tools_iso_path, :read_host_only_interfaces,