Class: VagrantPlugins::ProviderVeertu::Action::PrepareNFSSettings
- Inherits:
-
Object
- Object
- VagrantPlugins::ProviderVeertu::Action::PrepareNFSSettings
- Includes:
- Vagrant::Action::Builtin::MixinSyncedFolders, Vagrant::Util::Retryable
- Defined in:
- lib/vagrant-veertu/action/prepare_nfs_settings.rb
Instance Method Summary collapse
-
#add_ips_to_env!(env) ⇒ Object
Extracts the proper host and guest IPs for NFS mounts and stores them in the environment for the SyncedFolder action to use them in mounting.
- #call(env) ⇒ Object
-
#find_host_only_adapter ⇒ Integer, String
Finds first host only network adapter and returns its adapter number and IP address.
-
#initialize(app, env) ⇒ PrepareNFSSettings
constructor
A new instance of PrepareNFSSettings.
-
#read_dynamic_machine_ip(adapter) ⇒ String
Returns the IP address of the guest by looking at veertu guest property for the appropriate guest adapter.
-
#read_static_machine_ips ⇒ 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.
Constructor Details
#initialize(app, env) ⇒ PrepareNFSSettings
Returns a new instance of PrepareNFSSettings.
10 11 12 13 |
# File 'lib/vagrant-veertu/action/prepare_nfs_settings.rb', line 10 def initialize(app, env) @app = app @logger = Log4r::Logger.new("vagrant::action::vm::nfs") end |
Instance Method Details
#add_ips_to_env!(env) ⇒ Object
Extracts the proper host and guest IPs for NFS mounts and stores them in the environment for the SyncedFolder action to use them in mounting.
The ! indicates that this method modifies its argument.
38 39 40 41 42 43 44 45 46 |
# File 'lib/vagrant-veertu/action/prepare_nfs_settings.rb', line 38 def add_ips_to_env!(env) adapter, host_ip = find_host_only_adapter machine_ip = read_static_machine_ips || read_dynamic_machine_ip(adapter) raise Vagrant::Errors::NFSNoHostonlyNetwork if !host_ip || !machine_ip env[:nfs_host_ip] = host_ip env[:nfs_machine_ip] = machine_ip end |
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/vagrant-veertu/action/prepare_nfs_settings.rb', line 15 def call(env) @machine = env[:machine] @app.call(env) opts = { cached: !!env[:synced_folders_cached], config: env[:synced_folders_config], disable_usable_check: !!env[:test], } folders = synced_folders(env[:machine], **opts) if folders.key?(:nfs) @logger.info("Using NFS, preparing NFS settings by reading host IP and machine IP") add_ips_to_env!(env) end end |
#find_host_only_adapter ⇒ Integer, String
Finds first host only network adapter and returns its adapter number and IP address
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/vagrant-veertu/action/prepare_nfs_settings.rb', line 52 def find_host_only_adapter @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 |
#read_dynamic_machine_ip(adapter) ⇒ String
Returns the IP address of the guest by looking at veertu guest property for the appropriate guest adapter.
For DHCP interfaces, the guest property will not be present until the guest completes
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/vagrant-veertu/action/prepare_nfs_settings.rb', line 93 def read_dynamic_machine_ip(adapter) return nil unless adapter # veertu 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::VeertuGuestPropertyNotFound)) do @machine.provider.driver.read_guest_ip(guestproperty_adapter) end rescue Vagrant::Errors::VeertuGuestPropertyNotFound # 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 ⇒ Array
Returns the IP address(es) of the guest by looking for static IPs given to host only adapters in the Vagrantfile
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/vagrant-veertu/action/prepare_nfs_settings.rb', line 70 def read_static_machine_ips 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
113 114 115 |
# File 'lib/vagrant-veertu/action/prepare_nfs_settings.rb', line 113 def {tries: 15, sleep: 1} end |