Sha256: 7d1957f7b0b2b194d5503e0796537289788a504e0248092ff20345f63d15ecb2

Contents?: true

Size: 1.51 KB

Versions: 99

Compression:

Stored size: 1.51 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

99 entries across 99 versions & 2 rubygems

Version Path
inspec-core-3.7.1 lib/resources/bond.rb
inspec-3.7.1 lib/resources/bond.rb
inspec-core-3.6.6 lib/resources/bond.rb
inspec-3.6.6 lib/resources/bond.rb
inspec-core-3.6.4 lib/resources/bond.rb
inspec-3.6.4 lib/resources/bond.rb
inspec-core-2.3.28 lib/resources/bond.rb
inspec-2.3.28 lib/resources/bond.rb
inspec-core-3.6.2 lib/resources/bond.rb
inspec-3.6.2 lib/resources/bond.rb
inspec-core-3.5.0 lib/resources/bond.rb
inspec-3.5.0 lib/resources/bond.rb
inspec-core-3.4.1 lib/resources/bond.rb
inspec-3.4.1 lib/resources/bond.rb
inspec-core-3.3.14 lib/resources/bond.rb
inspec-3.3.14 lib/resources/bond.rb
inspec-core-3.2.6 lib/resources/bond.rb
inspec-3.2.6 lib/resources/bond.rb
inspec-core-3.1.3 lib/resources/bond.rb
inspec-3.1.3 lib/resources/bond.rb