Class: Inspec::Resources::KernelModule
- Inherits:
-
Object
- Object
- Inspec::Resources::KernelModule
- Defined in:
- lib/resources/kernel_module.rb
Instance Method Summary collapse
-
#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.
16 17 18 19 20 21 |
# File 'lib/resources/kernel_module.rb', line 16 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
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/resources/kernel_module.rb', line 23 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
51 52 53 |
# File 'lib/resources/kernel_module.rb', line 51 def to_s "Kernel Module #{@module}" end |
#version ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/resources/kernel_module.rb', line 40 def version if inspec.os.redhat? || inspec.os.name == 'fedora' modinfo_cmd = "/sbin/modinfo -F version #{@module}" else modinfo_cmd = "modinfo -F version #{@module}" end cmd = inspec.command(modinfo_cmd) cmd.exit_status.zero? ? cmd.stdout.delete("\n") : nil end |