Sha256: 926b5d4cbc2bb442bf496422d3449297e1a9ad1bb1a401a51e24854b3dced20a

Contents?: true

Size: 1.58 KB

Versions: 3

Compression:

Stored size: 1.58 KB

Contents

# encoding: utf-8

require 'resources/file'
require 'utils/file_reader'

module Inspec::Resources
  class Bond < FileResource
    name 'bond'
    supports platform: 'unix'
    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
    "

    include FileReader

    def initialize(bond)
      @bond = bond
      @path = "/proc/net/bonding/#{bond}"
      @file = inspec.file(@path)
      @content = read_file_content(@path, allow_empty: true)
      @params = {}
      @loaded = false
    end

    def read_content
      @params = SimpleConfig.new(
        @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)
      params['Slave Interface'].include?(interface)
    end

    def interfaces
      params['Slave Interface']
    end

    def mode
      params['Bonding Mode'].first
    end

    def to_s
      "Bond #{@bond}"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
inspec-2.1.81 lib/resources/bond.rb
inspec-2.1.21 lib/resources/bond.rb
inspec-2.1.10 lib/resources/bond.rb