inspec/lib/resources/bond.rb

70 lines
1.5 KiB
Ruby
Raw Normal View History

# encoding: utf-8
2015-10-06 16:55:44 +00:00
# author: Christoph Hartmann
# author: Dominik Richter
require 'resources/file'
2015-10-26 03:04:18 +00:00
module Inspec::Resources
class Bond < FileResource
name 'bond'
2015-11-27 13:02:38 +00:00
desc 'Use the bond InSpec audit resource to test a logical, bonded network interface (i.e. "two or more network interfaces aggregated into a single, logical network interface"). On Linux platforms, any value in the /proc/net/bonding directory may be tested.'
example "
describe bond('bond0') do
it { should exist }
end
"
def initialize(bond)
@bond = bond
@path = "/proc/net/bonding/#{bond}"
2015-10-26 03:04:18 +00:00
@file = inspec.file(@path)
@content = nil
@params = {}
@loaded = false
end
def read_content
# parse the file
@content = @file.content
2015-09-05 14:07:54 +00:00
@params = SimpleConfig.new(
@file.content,
assignment_regex: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
multiple_values: true,
).params if @file.exist?
@loaded = true
@content
end
# ensures the content is loaded before we return the params
def params
read_content if @loaded == false
@params
end
def content
read_content if @loaded == false
@content
end
def exist?
@file.exist?
end
def has_interface?(interface)
2015-09-04 07:59:30 +00:00
params['Slave Interface'].include?(interface)
end
def interfaces
2015-09-04 07:59:30 +00:00
params['Slave Interface']
end
def mode
params['Bonding Mode'].first
end
def to_s
"Bond #{@bond}"
end
end
end