Class: Inspec::Resources::Bond

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

Instance Attribute Summary

Attributes inherited from FileResource

#file, #mount_options, #path

Instance Method Summary collapse

Methods included from FileReader

#read_file_content

Methods inherited from FileResource

#allowed?, #contain, #content_as_json, #content_as_yaml, #executable?, #immutable?, #inherited?, #more_permissive_than?, #mounted?, #readable?, #sgid, #sticky, #suid, #user_permissions, #writable?

Methods included from Utils::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.



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

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



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

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

#exist?Boolean

Returns:

  • (Boolean)


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

def exist?
  @file.exist?
end

#has_interface?(interface) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#interfacesObject



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

def interfaces
  params["Slave Interface"]
end

#modeObject



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

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

#paramsObject

ensures the content is loaded before we return the params



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

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

#read_contentObject



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

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

#resource_idObject



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

def resource_id
  @path || "bond"
end

#to_sObject



70
71
72
# File 'lib/inspec/resources/bond.rb', line 70

def to_s
  "Bond #{@bond}"
end