Class: Inspec::Resources::Bond

Inherits:
FileResource show all
Includes:
FileReader
Defined in:
lib/resources/bond.rb

Instance Attribute Summary

Attributes inherited from FileResource

#file, #mount_options

Instance Method Summary collapse

Methods included from FileReader

#read_file_content

Methods inherited from FileResource

#allowed?, #contain, #executable?, #mounted?, #readable?, #sgid, #sticky, #suid, #writable?

Methods included from LinuxMountParser

#includes_whitespaces?, #parse_mount_options

Methods included from FilePermissionsSelector

#select_file_perms_style

Constructor Details

#initialize(bond) ⇒ Bond

Returns a new instance of Bond.



19
20
21
22
23
24
25
26
# File 'lib/resources/bond.rb', line 19

def initialize(bond)
  @bond = bond
  @path = "/proc/net/bonding/#{bond}"
  @file = inspec.file(@path)
  @content = read_file_content(@path, allow_empty: true)
  @params = {}
  @loaded = false
end

Instance Method Details

#contentObject



44
45
46
47
# File 'lib/resources/bond.rb', line 44

def content
  read_content if @loaded == false
  @content
end

#exist?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/resources/bond.rb', line 49

def exist?
  @file.exist?
end

#has_interface?(interface) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/resources/bond.rb', line 53

def has_interface?(interface)
  params['Slave Interface'].include?(interface)
end

#interfacesObject



57
58
59
# File 'lib/resources/bond.rb', line 57

def interfaces
  params['Slave Interface']
end

#modeObject



61
62
63
# File 'lib/resources/bond.rb', line 61

def mode
  params['Bonding Mode'].first
end

#paramsObject

ensures the content is loaded before we return the params



39
40
41
42
# File 'lib/resources/bond.rb', line 39

def params
  read_content if @loaded == false
  @params
end

#read_contentObject



28
29
30
31
32
33
34
35
36
# File 'lib/resources/bond.rb', line 28

def read_content
  @params = SimpleConfig.new(
    @content,
    assignment_regex: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
    multiple_values: true,
  ).params if @file.exist?
  @loaded = true
  @content
end

#to_sObject



65
66
67
# File 'lib/resources/bond.rb', line 65

def to_s
  "Bond #{@bond}"
end