Class: VagrantPlugins::XenServer::Action::PrepareNFSSettings

Inherits:
Object
  • Object
show all
Includes:
Vagrant::Action::Builtin::MixinSyncedFolders
Defined in:
lib/vagrant-xenserver/action/prepare_nfs_settings.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ PrepareNFSSettings

Returns a new instance of PrepareNFSSettings.



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

def initialize(app,env)
  @app = app
  @logger = Log4r::Logger.new("vagrant::action::vm::nfs")
end

Instance Method Details

#call(env) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/vagrant-xenserver/action/prepare_nfs_settings.rb', line 35

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

  if using_nfs?
    @logger.info("Using NFS, preparing NFS settings by reading host IP and machine IP")
    env[:nfs_host_ip]    = read_host_ip(env[:machine],env)
    env[:nfs_machine_ip] = env[:xs_host_ip]

    @logger.info("host IP: #{env[:nfs_host_ip]} machine IP: #{env[:nfs_machine_ip]}")

    raise Vagrant::Errors::NFSNoHostonlyNetwork if !env[:nfs_machine_ip] || !env[:nfs_host_ip]
  end
end

#get_local_ip_linux(ip) ⇒ Object



64
65
66
67
68
# File 'lib/vagrant-xenserver/action/prepare_nfs_settings.rb', line 64

def get_local_ip_linux(ip)
  re = /src ([0-9\.]+)/
  match = `ip route get to #{ip} | head -n 1`.match re
  match[1]
end

#get_local_ip_mac(ip) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/vagrant-xenserver/action/prepare_nfs_settings.rb', line 69

def get_local_ip_mac(ip)
  re = /interface: ([a-z0-9]+)/
  match = `route get #{ip} | grep interface | head -n 1`.match re
  interface = match[1]
  re = /inet ([0-9\.]+)/
  match = `ifconfig #{interface} inet | tail -1`.match re
  match[1]
end

#read_host_ip(machine, env) ⇒ String

Returns the IP address of the interface that will route to the xs_host

Parameters:

  • machine (Machine)

Returns:

  • (String)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/vagrant-xenserver/action/prepare_nfs_settings.rb', line 61

def read_host_ip(machine,env)
  ip = Socket.getaddrinfo(env[:machine].provider_config.xs_host,nil)[0][2]
  env[:xs_host_ip] = ip
  def get_local_ip_linux(ip)
    re = /src ([0-9\.]+)/
    match = `ip route get to #{ip} | head -n 1`.match re
    match[1]
  end
  def get_local_ip_mac(ip)
    re = /interface: ([a-z0-9]+)/
    match = `route get #{ip} | grep interface | head -n 1`.match re
    interface = match[1]
    re = /inet ([0-9\.]+)/
    match = `ifconfig #{interface} inet | tail -1`.match re
    match[1]
  end
  if os == :linux then get_local_ip_linux(ip)
  elsif os == :macosx then get_local_ip_mac(ip)
  else raise Vagrant::Errors::UnknownOS # "unknown os: #{host_os.inspect}"
  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)


53
54
55
# File 'lib/vagrant-xenserver/action/prepare_nfs_settings.rb', line 53

def using_nfs?
  !!synced_folders(@machine)[:nfs]
end