2015-09-03 17:10:08 +02:00
# encoding: utf-8
require 'resources/file'
2018-03-22 21:25:45 +09:00
require 'utils/file_reader'
2015-09-03 17:10:08 +02:00
2015-10-26 04:04:18 +01:00
module Inspec::Resources
2016-03-09 10:35:35 +01:00
class Bond < FileResource
2015-09-03 17:10:08 +02:00
name 'bond'
2018-02-19 06:26:49 -08:00
supports platform : 'unix'
2015-11-27 14:02:38 +01: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
"
2015-09-03 17:10:08 +02:00
2018-03-22 21:25:45 +09:00
include FileReader
2015-09-03 17:10:08 +02:00
def initialize ( bond )
2015-10-12 13:01:58 +02:00
@bond = bond
2015-09-03 17:10:08 +02:00
@path = " /proc/net/bonding/ #{ bond } "
2015-10-26 04:04:18 +01:00
@file = inspec . file ( @path )
2018-03-22 21:25:45 +09:00
@content = read_file_content ( @path , allow_empty : true )
2015-09-03 17:10:08 +02:00
@params = { }
@loaded = false
end
def read_content
2015-09-05 16:07:54 +02:00
@params = SimpleConfig . new (
2018-03-22 21:25:45 +09:00
@content ,
2017-04-26 23:18:14 +02:00
assignment_regex : / ^ \ s*([^:]*?) \ s*: \ s*(.*?) \ s*$ / ,
2015-09-09 18:52:27 +02:00
multiple_values : true ,
2015-09-18 12:44:29 +02:00
) . params if @file . exist?
2015-09-03 17:10:08 +02:00
@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
2015-09-18 12:44:29 +02:00
def exist?
@file . exist?
2015-09-03 17:10:08 +02:00
end
def has_interface? ( interface )
2015-09-04 09:59:30 +02:00
params [ 'Slave Interface' ] . include? ( interface )
2015-09-03 17:10:08 +02:00
end
def interfaces
2015-09-04 09:59:30 +02:00
params [ 'Slave Interface' ]
2015-09-03 17:10:08 +02:00
end
2015-10-12 13:01:58 +02:00
2017-12-22 06:02:40 -08:00
def mode
params [ 'Bonding Mode' ] . first
end
2015-10-12 13:01:58 +02:00
def to_s
" Bond #{ @bond } "
end
2015-09-03 17:10:08 +02:00
end
end