Class: KernelModule

Inherits:
Object
  • Object
show all
Defined in:
lib/resources/kernel_module.rb

Overview

author: Christoph Hartmann author: Dominik Richter license: All rights reserved

Instance Method Summary collapse

Constructor Details

#initialize(modulename = nil) ⇒ KernelModule

Returns a new instance of KernelModule.



15
16
17
18
19
20
# File 'lib/resources/kernel_module.rb', line 15

def initialize(modulename = nil)
  @module = modulename

  # this resource is only supported on Linux
  return skip_resource 'The `kernel_parameter` resource is not supported on your OS.' if !inspec.os.linux?
end

Instance Method Details

#loaded?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/resources/kernel_module.rb', line 22

def loaded?
  # default lsmod command
  lsmod_cmd = 'lsmod'
  # special care for CentOS 5 and sudo
  lsmod_cmd = '/sbin/lsmod' if inspec.os[:family] == 'centos' && inspec.os[:release].to_i == 5

  # get list of all modules
  cmd = inspec.command(lsmod_cmd)
  return false if cmd.exit_status != 0

  # check if module is loaded
  re = Regexp.new('^'+Regexp.quote(@module)+'\s')
  found = cmd.stdout.match(re)
  !found.nil?
end

#to_sObject



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

def to_s
  "Kernel Module #{@module}"
end