Class: VagrantNfs4j::Config::Nfs4j

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-nfs4j/config/nfs4j.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNfs4j

Returns a new instance of Nfs4j.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vagrant-nfs4j/config/nfs4j.rb', line 21

def initialize
  @shares_config = UNSET_VALUE
  @host_ip = UNSET_VALUE
  @api_port = UNSET_VALUE
  @api_bearer = UNSET_VALUE
  @setup_firewall = UNSET_VALUE
  @daemon_start = UNSET_VALUE
  @daemon_exe = UNSET_VALUE
  @daemon_jar = UNSET_VALUE
  @daemon_cmd = UNSET_VALUE
  @daemon_opts = UNSET_VALUE
  @java_home = UNSET_VALUE
  @java_opts = UNSET_VALUE
end

Instance Attribute Details

#api_bearerObject

Returns the value of attribute api_bearer.



11
12
13
# File 'lib/vagrant-nfs4j/config/nfs4j.rb', line 11

def api_bearer
  @api_bearer
end

#api_portObject

Returns the value of attribute api_port.



10
11
12
# File 'lib/vagrant-nfs4j/config/nfs4j.rb', line 10

def api_port
  @api_port
end

#daemon_cmdObject

Returns the value of attribute daemon_cmd.



16
17
18
# File 'lib/vagrant-nfs4j/config/nfs4j.rb', line 16

def daemon_cmd
  @daemon_cmd
end

#daemon_exeObject

Returns the value of attribute daemon_exe.



14
15
16
# File 'lib/vagrant-nfs4j/config/nfs4j.rb', line 14

def daemon_exe
  @daemon_exe
end

#daemon_jarObject

Returns the value of attribute daemon_jar.



15
16
17
# File 'lib/vagrant-nfs4j/config/nfs4j.rb', line 15

def daemon_jar
  @daemon_jar
end

#daemon_optsObject

Returns the value of attribute daemon_opts.



17
18
19
# File 'lib/vagrant-nfs4j/config/nfs4j.rb', line 17

def daemon_opts
  @daemon_opts
end

#daemon_startObject

Returns the value of attribute daemon_start.



13
14
15
# File 'lib/vagrant-nfs4j/config/nfs4j.rb', line 13

def daemon_start
  @daemon_start
end

#host_ipObject

Returns the value of attribute host_ip.



9
10
11
# File 'lib/vagrant-nfs4j/config/nfs4j.rb', line 9

def host_ip
  @host_ip
end

#java_homeObject

Returns the value of attribute java_home.



18
19
20
# File 'lib/vagrant-nfs4j/config/nfs4j.rb', line 18

def java_home
  @java_home
end

#java_optsObject

Returns the value of attribute java_opts.



19
20
21
# File 'lib/vagrant-nfs4j/config/nfs4j.rb', line 19

def java_opts
  @java_opts
end

#setup_firewallObject

Returns the value of attribute setup_firewall.



12
13
14
# File 'lib/vagrant-nfs4j/config/nfs4j.rb', line 12

def setup_firewall
  @setup_firewall
end

#shares_configObject

Returns the value of attribute shares_config.



8
9
10
# File 'lib/vagrant-nfs4j/config/nfs4j.rb', line 8

def shares_config
  @shares_config
end

Instance Method Details

#finalize!Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/vagrant-nfs4j/config/nfs4j.rb', line 67

def finalize!
  @shares_config = {} if @shares_config == UNSET_VALUE
  @host_ip = "" if @host_ip == UNSET_VALUE
  @api_port = 9732 if @api_port == UNSET_VALUE
  @api_bearer = nil if @api_bearer == UNSET_VALUE
  @setup_firewall = true if @setup_firewall == UNSET_VALUE
  @daemon_start = true if @daemon_start == UNSET_VALUE
  @daemon_exe = true if @daemon_exe == UNSET_VALUE
  @daemon_jar = false if @daemon_jar == UNSET_VALUE
  @daemon_cmd = nil if @daemon_cmd == UNSET_VALUE
  @daemon_opts = nil if @daemon_opts == UNSET_VALUE
  @java_home = ENV['JAVA_HOME'] if @java_home == UNSET_VALUE
  @java_opts = ENV['JAVA_OPTS'] if @java_opts == UNSET_VALUE

  ENV['JAVA_HOME'] = @java_home if @java_home
  ENV['JAVA_OPTS'] = @java_opts if @java_opts

  if @daemon_jar
    @daemon_exe = false
  end

  if @daemon_exe
    @daemon_jar = false
  end

  if @daemon_cmd
    @daemon_exe = false
    @daemon_jar = false
  else
    @daemon_cmd = VagrantNfs4j::Nfs4jDaemon::Wrapper.new(
        config.api_port,
        config.api_bearer
    ).get_cmd_base(@daemon_exe, @daemon_jar, @java_home, @java_opts)
  end
end

#validate(machine) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/vagrant-nfs4j/config/nfs4j.rb', line 36

def validate(machine)
  errors = []

  config = machine.config.nfs4j

  errors << 'nfs4j.shares_config cannot be nil.' if config.shares_config.nil?
  errors << 'nfs4j.host_ip cannot be nil.' if config.host_ip.nil?
  errors << 'nfs4j.api_port cannot be nil.' if config.api_port.nil?

  java_required = false
  if config.daemon_start
    begin
      stdout, stderr, status = Open3.capture3("#{config.daemon_cmd} -h")
      if status.to_i != 0
        java_required = true
        errors << "nfs4j-daemon cannot be executed (#{config.daemon_cmd}) [#{status}]. check nfs4j.daemon_* and nfs4j.java_* options."
      elsif not stdout.include?('[<shares>...]')
        java_required = true
        errors << "nfs4j-daemon cannot be executed (#{config.daemon_cmd}) [doesn't looks like nfs4j-daemon]. check nfs4j.daemon_* and nfs4j.java_* options."
      end
    rescue StandardError => err
      java_required = true
      errors << "nfs4j-daemon cannot be executed (#{config.daemon_cmd}): #{err.message}. check nfs4j.daemon_* and nfs4j.java_* options."
    end
  end

  errors << "nfs4j-daemon requires Java >= 8. Make sure you actually have a JRE/JDK installed and JAVA_HOME environment variable or nfs4j.java_home option is set to JRE/JDK installation directory." if java_required

  {"nsf4j" => errors}
end