Class: VagrantPlugins::Skytap::Action::PrepareNFSSettings
- Includes:
- ActionHelpers
- Defined in:
- lib/vagrant-skytap/action/prepare_nfs_settings.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#host_vm ⇒ Object
readonly
Returns the value of attribute host_vm.
-
#machine ⇒ Object
readonly
Returns the value of attribute machine.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ PrepareNFSSettings
constructor
A new instance of PrepareNFSSettings.
-
#read_host_ip ⇒ String
Returns the IP address of the host, preferring one on an interface which the client can route to.
-
#read_machine_ip ⇒ String
Returns the IP address of the guest VM.
-
#using_nfs? ⇒ Boolean
Determine whether there are enabled synced folders defined for this machine which are either of type :nfs, or of the default type (Vagrant may choose NFS as the default).
Methods included from ActionHelpers
Constructor Details
#initialize(app, env) ⇒ PrepareNFSSettings
Returns a new instance of PrepareNFSSettings.
33 34 35 36 37 |
# File 'lib/vagrant-skytap/action/prepare_nfs_settings.rb', line 33 def initialize(app,env) @app = app @env = env @logger = Log4r::Logger.new("vagrant_skytap::action::prepare_nfs_settings") end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
31 32 33 |
# File 'lib/vagrant-skytap/action/prepare_nfs_settings.rb', line 31 def env @env end |
#host_vm ⇒ Object (readonly)
Returns the value of attribute host_vm.
31 32 33 |
# File 'lib/vagrant-skytap/action/prepare_nfs_settings.rb', line 31 def host_vm @host_vm end |
#machine ⇒ Object (readonly)
Returns the value of attribute machine.
31 32 33 |
# File 'lib/vagrant-skytap/action/prepare_nfs_settings.rb', line 31 def machine @machine end |
Instance Method Details
#call(env) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/vagrant-skytap/action/prepare_nfs_settings.rb', line 39 def call(env) @machine = env[:machine] @host_vm = env[:vagrant_host_vm] if using_nfs? env[:nfs_host_ip] = read_host_ip env[:nfs_machine_ip] = read_machine_ip end @app.call(env) end |
#read_host_ip ⇒ String
Returns the IP address of the host, preferring one on an interface which the client can route to. If we’re running in a Skytap VM, and the guest’s network is NAT-enabled, the host VM will have been assigned a NAT address which can be determined from its metadata.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/vagrant-skytap/action/prepare_nfs_settings.rb', line 72 def read_host_ip if host_vm host_iface = host_vm.reload.interfaces.first guest_network = current_vm(env).interfaces.first.network end if guest_network.try(:nat_enabled?) host_iface.nat_address_for_network(guest_network) else UDPSocket.open do |s| s.connect(machine.ssh_info[:host], 1) @logger.debug("PrepareNFSSettings#read_host_ip found the following addresses #{s.addr}") s.addr.last end end.tap do |ret| @logger.debug("PrepareNFSSettings#read_host_ip returning #{ret}") end end |
#read_machine_ip ⇒ String
Returns the IP address of the guest VM.
94 95 96 |
# File 'lib/vagrant-skytap/action/prepare_nfs_settings.rb', line 94 def read_machine_ip machine.ssh_info[:host] end |
#using_nfs? ⇒ Boolean
Determine whether there are enabled synced folders defined for this machine which are either of type :nfs, or of the default type (Vagrant may choose NFS as the default). github.com/mitchellh/vagrant/issues/4192
57 58 59 60 61 62 63 64 |
# File 'lib/vagrant-skytap/action/prepare_nfs_settings.rb', line 57 def using_nfs? machine.config.vm.synced_folders.any? do |_, opts| (opts[:type] == :nfs || opts[:type].blank?) unless opts[:disabled] end.tap do |ret| @logger.debug("PrepareNFSSettings#using_nfs? returning #{ret}. "\ "Synced folders: #{machine.config.vm.synced_folders.inspect}") end end |