Class: Vagrant::LXC::Action::PrepareNFSSettings

Inherits:
Object
  • Object
show all
Includes:
Util::Retryable
Defined in:
lib/vagrant-lxc/action/prepare_nfs_settings.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ PrepareNFSSettings

Returns a new instance of PrepareNFSSettings.



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

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.

Raises:

  • (Vagrant::Errors::NFSNoHostonlyNetwork)


44
45
46
47
48
49
50
51
52
53
54
# File 'lib/vagrant-lxc/action/prepare_nfs_settings.rb', line 44

def add_ips_to_env!(env)
  provider = @machine.provider

  host_ip    = read_host_ip
  machine_ip = provider.ssh_info[:host]

  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



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vagrant-lxc/action/prepare_nfs_settings.rb', line 12

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

  @app.call(env)

  # if using_nfs? # TODO: && !privileged_container?
  #   raise Errors::NfsWithoutPrivilegedError
  # end

  if using_nfs?
    @logger.info("Using NFS, preparing NFS settings by reading host IP and machine IP")
    add_ips_to_env!(env)
  end
end

#read_host_ipObject



56
57
58
59
60
# File 'lib/vagrant-lxc/action/prepare_nfs_settings.rb', line 56

def read_host_ip
  @machine.communicate.execute 'echo $SSH_CLIENT' do |buffer, output|
    return output.chomp.split(' ')[0] if buffer == :stdout
  end
end

#using_nfs?Boolean

We’re using NFS if we have any synced folder with NFS configured. If we are not using NFS we don’t need to do the extra work to populate these fields in the environment.

Returns:

  • (Boolean)


30
31
32
# File 'lib/vagrant-lxc/action/prepare_nfs_settings.rb', line 30

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