Class: Inspec::Resources::Bond

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

Instance Attribute Summary

Attributes inherited from FileResource

#file, #mount_options

Instance Method Summary collapse

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.



16
17
18
19
20
21
22
23
# File 'lib/resources/bond.rb', line 16

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

Instance Method Details

#contentObject



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

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

#exist?Boolean

Returns:

  • (Boolean)


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

def exist?
  @file.exist?
end

#has_interface?(interface) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#interfacesObject



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

def interfaces
  params['Slave Interface']
end

#modeObject



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

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

#paramsObject

ensures the content is loaded before we return the params



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

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

#read_contentObject



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

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

#to_sObject



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

def to_s
  "Bond #{@bond}"
end