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
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/inspec/resources/interface.rb', line 157 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 |