Class: Inspec::Resources::LinuxInterface
- Inherits:
-
InterfaceInfo
- Object
- InterfaceInfo
- Inspec::Resources::LinuxInterface
- Defined in:
- lib/inspec/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
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/inspec/resources/interface.rb', line 102 def interface_info(iface) # will return "[mtu]\n1500\n[type]\n1" cmd = inspec.command("find /sys/class/net/#{iface}/ -maxdepth 1 -type f -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 family_addresses = addresses(iface) { name: iface, up: state, speed: speed, ipv4_addresses: family_addresses["inet"], ipv6_addresses: family_addresses["inet6"], } end |