Class: Inspec::Resources::KernelModule
- Inherits:
-
Object
- Object
- Inspec::Resources::KernelModule
- Defined in:
- lib/resources/kernel_module.rb
Instance Method Summary collapse
- #blacklisted? ⇒ Boolean
- #disabled? ⇒ Boolean
-
#initialize(modulename = nil) ⇒ KernelModule
constructor
A new instance of KernelModule.
- #loaded? ⇒ Boolean
- #to_s ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(modulename = nil) ⇒ KernelModule
Returns a new instance of KernelModule.
37 38 39 40 41 |
# File 'lib/resources/kernel_module.rb', line 37 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
#blacklisted? ⇒ Boolean
64 65 66 |
# File 'lib/resources/kernel_module.rb', line 64 def blacklisted? !modprobe_output.match(/^blacklist\s+#{@module}/).nil? || disabled_via_bin_true? || disabled_via_bin_false? end |
#disabled? ⇒ Boolean
60 61 62 |
# File 'lib/resources/kernel_module.rb', line 60 def disabled? !modprobe_output.match(%r{^install\s+#{@module}\s+/(s?)bin/(true|false)}).nil? end |
#loaded? ⇒ Boolean
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/resources/kernel_module.rb', line 43 def loaded? if inspec.os.redhat? || inspec.os.name == 'fedora' lsmod_cmd = '/sbin/lsmod' else lsmod_cmd = 'lsmod' end # 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_s ⇒ Object
73 74 75 |
# File 'lib/resources/kernel_module.rb', line 73 def to_s "Kernel Module #{@module}" end |
#version ⇒ Object
68 69 70 71 |
# File 'lib/resources/kernel_module.rb', line 68 def version cmd = inspec.command("#{modinfo_cmd_for_os} -F version #{@module}") cmd.exit_status.zero? ? cmd.stdout.delete("\n") : nil end |