2015-09-03 15:10:08 +00:00
|
|
|
# encoding: utf-8
|
2015-10-06 16:55:44 +00:00
|
|
|
# author: Christoph Hartmann
|
|
|
|
# author: Dominik Richter
|
2015-09-03 15:10:08 +00:00
|
|
|
|
|
|
|
require 'resources/file'
|
|
|
|
|
2015-10-21 17:30:01 +00:00
|
|
|
# Usage:
|
|
|
|
# describe bond('bond0') do
|
|
|
|
# it { should exist }
|
|
|
|
# it { should have_interface 'eth0' }
|
|
|
|
# end
|
|
|
|
|
2015-10-26 03:04:18 +00:00
|
|
|
module Inspec::Resources
|
2015-09-03 15:10:08 +00:00
|
|
|
class Bond < File
|
|
|
|
name 'bond'
|
|
|
|
|
|
|
|
def initialize(bond)
|
2015-10-12 11:01:58 +00:00
|
|
|
@bond = bond
|
2015-09-03 15:10:08 +00:00
|
|
|
@path = "/proc/net/bonding/#{bond}"
|
2015-10-26 03:04:18 +00:00
|
|
|
@file = inspec.file(@path)
|
2015-09-03 15:10:08 +00:00
|
|
|
@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,
|
2015-09-03 15:10:08 +00:00
|
|
|
assignment_re: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
|
2015-09-09 16:52:27 +00:00
|
|
|
multiple_values: true,
|
2015-09-18 10:44:29 +00:00
|
|
|
).params if @file.exist?
|
2015-09-03 15:10:08 +00: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 10:44:29 +00:00
|
|
|
def exist?
|
|
|
|
@file.exist?
|
2015-09-03 15:10:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def has_interface?(interface)
|
2015-09-04 07:59:30 +00:00
|
|
|
params['Slave Interface'].include?(interface)
|
2015-09-03 15:10:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def interfaces
|
2015-09-04 07:59:30 +00:00
|
|
|
params['Slave Interface']
|
2015-09-03 15:10:08 +00:00
|
|
|
end
|
2015-10-12 11:01:58 +00:00
|
|
|
|
|
|
|
def to_s
|
|
|
|
"Bond #{@bond}"
|
|
|
|
end
|
2015-09-03 15:10:08 +00:00
|
|
|
end
|
|
|
|
end
|