Class: VagrantPlugins::Utm::Action::PrepareNFSSettings
- Inherits:
-
Object
- Object
- VagrantPlugins::Utm::Action::PrepareNFSSettings
- Includes:
- Vagrant::Action::Builtin::MixinSyncedFolders, Vagrant::Util::Retryable
- Defined in:
- lib/vagrant_utm/action/prepare_nfs_settings.rb
Overview
This action prepares the NFS settings for the machine.
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
-
#initialize(app, _env) ⇒ PrepareNFSSettings
constructor
A new instance of PrepareNFSSettings.
-
#read_dynamic_machine_ip ⇒ String
Returns the IP address of the guest by looking at utm guest additions for the appropriate guest adapter.
-
#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.
11 12 13 14 |
# File 'lib/vagrant_utm/action/prepare_nfs_settings.rb', line 11 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.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vagrant_utm/action/prepare_nfs_settings.rb', line 39 def add_ips_to_env!(env) # Hardcoded IP for the host IP host_ip = "10.0.2.2" machine_ip = read_dynamic_machine_ip 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
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/vagrant_utm/action/prepare_nfs_settings.rb', line 16 def call(env) @machine = env[:machine] @app.call(env) opts = { cached: !env[:synced_folders_cached].nil?, config: env[:synced_folders_config], disable_usable_check: !env[:test].nil? } folders = synced_folders(env[:machine], **opts) return unless folders.key?(:nfs) @logger.info("Using NFS, preparing NFS settings by reading host IP and machine IP") add_ips_to_env!(env) end |
#read_dynamic_machine_ip ⇒ String
Returns the IP address of the guest by looking at utm guest additions for the appropriate guest adapter.
For DHCP interfaces, the guest property will not be present until the guest completes
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/vagrant_utm/action/prepare_nfs_settings.rb', line 58 def read_dynamic_machine_ip # 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 # Read the IP address from the list given by qemu-guest-agent @machine.provider.driver.read_guest_ip[0] 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 |
#retry_options ⇒ Object
Separating these out so we can stub out the sleep in tests
73 74 75 |
# File 'lib/vagrant_utm/action/prepare_nfs_settings.rb', line 73 def { tries: 15, sleep: 1 } end |