Class: Serverspec::Type::NfsExport

Inherits:
Base
  • Object
show all
Defined in:
lib/serverspec_extra_types/types/nfs_export.rb

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, options = {}) ⇒ NfsExport

Returns a new instance of NfsExport.



9
10
11
12
# File 'lib/serverspec_extra_types/types/nfs_export.rb', line 9

def initialize(name = nil, options = {})
  super(name, options)
  @export = name
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/serverspec_extra_types/types/nfs_export.rb', line 14

def exists?
  get_inspection.success?
end

#get_inspectionObject

rubocop:disable Naming/AccessorMethodName



46
47
48
49
# File 'lib/serverspec_extra_types/types/nfs_export.rb', line 46

def get_inspection
  command = "grep #{@export} /etc/exports"
  @get_inspection ||= @runner.run_command(command)
end

#has_host?(host_id, option = nil) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
# File 'lib/serverspec_extra_types/types/nfs_export.rb', line 18

def has_host?(host_id, option = nil)
  if option
    check_options(host_id, option)
  else
    hosts.key?(host_id)
  end
end

#host(host_id) ⇒ Object



37
38
39
# File 'lib/serverspec_extra_types/types/nfs_export.rb', line 37

def host(host_id)
  hosts[host_id]
end

#hostsObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/serverspec_extra_types/types/nfs_export.rb', line 26

def hosts
  unless @hosts
    @hosts = {}
    inspection.split(' ')[1..-1].each do |item|
      (host, options) = item.split('(')
      @hosts[host] = options.split(')')[0].split(',')
    end
  end
  @hosts
end

#inspectionObject



41
42
43
# File 'lib/serverspec_extra_types/types/nfs_export.rb', line 41

def inspection
  @inspection ||= get_inspection.stdout
end