Class: VagrantPlugins::Skytap::Action::PrepareNFSSettings

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-skytap/action/prepare_nfs_settings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ PrepareNFSSettings

Returns a new instance of PrepareNFSSettings.



7
8
9
10
11
# File 'lib/vagrant-skytap/action/prepare_nfs_settings.rb', line 7

def initialize(app,env)
  @app = app
  @env = env
  @logger = Log4r::Logger.new("vagrant_skytap::action::prepare_nfs_settings")
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



5
6
7
# File 'lib/vagrant-skytap/action/prepare_nfs_settings.rb', line 5

def env
  @env
end

#machineObject (readonly)

Returns the value of attribute machine.



5
6
7
# File 'lib/vagrant-skytap/action/prepare_nfs_settings.rb', line 5

def machine
  @machine
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/vagrant-skytap/action/prepare_nfs_settings.rb', line 13

def call(env)
  @machine = env[:machine]

  if using_nfs?
    env[:nfs_host_ip] = read_host_ip
    env[:nfs_machine_ip] = read_machine_ip
  end

  @app.call(env)
end

#read_host_ipObject

Returns the IP address of the host, preferring one on an interface which the client can route to.



30
31
32
33
34
35
36
37
# File 'lib/vagrant-skytap/action/prepare_nfs_settings.rb', line 30

def read_host_ip
  UDPSocket.open do |s|
    s.connect(machine.ssh_info[:host], 1)
    s.addr.last
  end.tap do |ret|
    @logger.debug "read_host_ip returning #{ret}"
  end
end

#read_machine_ipObject



39
40
41
# File 'lib/vagrant-skytap/action/prepare_nfs_settings.rb', line 39

def read_machine_ip
  machine.ssh_info[:host]
end

#using_nfs?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/vagrant-skytap/action/prepare_nfs_settings.rb', line 24

def using_nfs?
  @machine.config.vm.synced_folders.any? { |_, opts| opts[:type] == :nfs }
end