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