Module: VagrantPlugins::SyncedFolderNFSGuest::ProviderVirtualBox::Cap
- Extended by:
- Vagrant::Util::Retryable
- Defined in:
- lib/vagrant-nfs_guest_vbfix/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
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vagrant-nfs_guest_vbfix/providers/virtualbox/cap/nfs_settings.rb', line 22 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 14 15 16 |
# File 'lib/vagrant-nfs_guest_vbfix/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) raise Vagrant::Errors::NFSNoHostonlyNetwork if !host_ip || !machine_ip 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
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/vagrant-nfs_guest_vbfix/providers/virtualbox/cap/nfs_settings.rb', line 63 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
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/vagrant-nfs_guest_vbfix/providers/virtualbox/cap/nfs_settings.rb', line 40 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
83 84 85 |
# File 'lib/vagrant-nfs_guest_vbfix/providers/virtualbox/cap/nfs_settings.rb', line 83 def self. {tries: 15, sleep: 1} end |