Class: Inspec::Resources::LinuxInterface
- Inherits:
-
InterfaceInfo
- Object
- InterfaceInfo
- Inspec::Resources::LinuxInterface
- Defined in:
- lib/resources/interface.rb
Instance Attribute Summary
Attributes inherited from InterfaceInfo
Instance Method Summary collapse
Methods inherited from InterfaceInfo
Methods included from Converter
Constructor Details
This class inherits a constructor from Inspec::Resources::InterfaceInfo
Instance Method Details
#interface_info(iface) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/resources/interface.rb', line 65 def interface_info(iface) # will return "[mtu]\n1500\n[type]\n1" cmd = inspec.command("find /sys/class/net/#{iface}/ -type f -maxdepth 1 -exec sh -c 'echo \"[$(basename {})]\"; cat {} || echo -n' \\;") return nil if cmd.exit_status.to_i != 0 # parse values, we only recieve values, therefore we threat them as keys params = SimpleConfig.new(cmd.stdout.chomp).params # abort if we got an empty result-set return nil if params.empty? # parse state state = false if params.key?('operstate') operstate, _value = params['operstate'].first state = operstate == 'up' end # parse speed speed = nil if params.key?('speed') speed, _value = params['speed'].first speed = convert_to_i(speed) end { name: iface, up: state, speed: speed, } end |