Module: VagrantPlugins::SyncedFolderNFSGuest::ProviderVirtualBox::Cap
- Extended by:
- Vagrant::Util::Retryable
- Defined in:
- lib/vagrant-nfs_guest/providers/virtualbox/cap/nfs_settings.rb
Class Method Summary collapse
-
.find_host_only_adapter(machine) ⇒ Integer, String
Finds first host only network adapter and returns its adapter number and IP address.
- .nfs_settings(machine) ⇒ Object
-
.read_dynamic_machine_ip(machine, adapter) ⇒ String
Returns the IP address of the guest by looking at vbox guest property for the appropriate guest adapter.
-
.read_static_machine_ips(machine) ⇒ Array
Returns the IP address(es) of the guest by looking for static IPs given to host only adapters in the Vagrantfile.
-
.retry_options ⇒ Object
Separating these out so we can stub out the sleep in tests.
Class Method Details
.find_host_only_adapter(machine) ⇒ Integer, String
Finds first host only network adapter and returns its adapter number and IP address
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/vagrant-nfs_guest/providers/virtualbox/cap/nfs_settings.rb', line 19 def self.find_host_only_adapter(machine) machine.provider.driver.read_network_interfaces.each do |adapter, opts| if opts[:type] == :hostonly machine.provider.driver.read_host_only_interfaces.each do |interface| if interface[:name] == opts[:hostonly] return adapter, interface[:ip] end end end end nil end |
.nfs_settings(machine) ⇒ Object
9 10 11 12 13 |
# File 'lib/vagrant-nfs_guest/providers/virtualbox/cap/nfs_settings.rb', line 9 def self.nfs_settings(machine) adapter, host_ip = self.find_host_only_adapter(machine) machine_ip = self.read_static_machine_ips(machine) || self.read_dynamic_machine_ip(machine, adapter) return host_ip, machine_ip end |
.read_dynamic_machine_ip(machine, adapter) ⇒ String
Returns the IP address of the guest by looking at vbox guest property for the appropriate guest adapter.
For DHCP interfaces, the guest property will not be present until the guest completes
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/vagrant-nfs_guest/providers/virtualbox/cap/nfs_settings.rb', line 60 def self.read_dynamic_machine_ip(machine, adapter) return nil unless adapter # vbox guest properties are 0-indexed, while showvminfo network # interfaces are 1-indexed. go figure. guestproperty_adapter = adapter - 1 # we need to wait for the guest's IP to show up as a guest property. # 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(.merge(on: Vagrant::Errors::VirtualBoxGuestPropertyNotFound)) do machine.provider.driver.read_guest_ip(guestproperty_adapter) end rescue Vagrant::Errors::VirtualBoxGuestPropertyNotFound # this error is more specific with a better error message directing # the user towards the fact that it's probably a reportable bug raise Vagrant::Errors::NFSNoGuestIP end |
.read_static_machine_ips(machine) ⇒ Array
Returns the IP address(es) of the guest by looking for static IPs given to host only adapters in the Vagrantfile
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/vagrant-nfs_guest/providers/virtualbox/cap/nfs_settings.rb', line 37 def self.read_static_machine_ips(machine) ips = [] machine.config.vm.networks.each do |type, | if type == :private_network && [:type] != :dhcp && [:ip].is_a?(String) ips << [:ip] end end if ips.empty? return nil end ips end |
.retry_options ⇒ Object
Separating these out so we can stub out the sleep in tests
80 81 82 |
# File 'lib/vagrant-nfs_guest/providers/virtualbox/cap/nfs_settings.rb', line 80 def self. {tries: 15, sleep: 1} end |