From 8dff1e0334fdb48df1f8bdb3c56fd88b184f44f4 Mon Sep 17 00:00:00 2001 From: Valyavskiy Viacheslav Date: Tue, 7 Jul 2015 14:34:22 +0300 Subject: [PATCH] Gather available offloading modes Gather available offloading modes for physical interfaces during the bootstrap stage. In this commit 'ethtool' util output parsing approach has been used. Nailgun agent collects modes and sent it to the nailgun API. These modes will be parsed via nailgun and will be put into offloading_modes JSON field of the interface db model. Change-Id: I172b61d3fccc00e5951616646fa82e33b8322997 Implements: blueprint selectable-offloading-type --- bin/agent | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/bin/agent b/bin/agent index d16ae7ea00..f5fb820e64 100755 --- a/bin/agent +++ b/bin/agent @@ -114,6 +114,15 @@ class McollectiveConfig end end +class Offloading + def initialize(name, sub) + @name, @sub = name, sub + end + + def to_json(options = {}) + {'name' => @name, 'state' => nil, 'sub' => @sub}.to_json() + end +end class NodeAgent def initialize(logger, url=nil) @@ -193,6 +202,38 @@ class NodeAgent interfaces end + # transform input array into array of the objects + # Example: + # [{ + # "state":null, + # "sub":[ + # { + # "state":null, + # "sub":[], + # "name":"tx-checksum-ipv6" + # }, + # ........... + # ], + # "name":"tx-checksumming" + # }, + # { + # "state":null, + # "sub":[], + # "name":"generic-segmentation-offload" + # }, + # ............. + # ] + def _parse_offloading(offloading_arr) + return [] if offloading_arr.empty? + inner = [] + current = offloading_arr.shift() + while offloading_arr.any? && offloading_arr.first().start_with?("\t") do + inner << offloading_arr.shift()[1..-1] + end + res = _parse_offloading(offloading_arr) + res << Offloading.new(current, _parse_offloading(inner)) + end + def _detailed detailed_meta = { :system => _system_info, @@ -238,6 +279,33 @@ class NodeAgent int_meta[:netmask] = addrinfo[:netmask] if addrinfo[:netmask] end end + begin + # this stuff will put all non-fixed offloading mode into array + # collect names of non-fixed offloading modes + # Example of ethtool -k ethX output: + # tx-checksumming: on + # tx-checksum-ipv4: on + # tx-checksum-ip-generic: off [fixed] + # tx-checksum-ipv6: on + # tx-checksum-fcoe-crc: off [fixed] + # tx-checksum-sctp: on + # scatter-gather: on + # tx-scatter-gather: on + # tx-scatter-gather-fraglist: off [fixed] + # generic-segmentation-offload: on + offloading_data = `ethtool -k #{int}`.split("\n").reject { |offloading| + offloading.include?("Features for") || + offloading.include?("fixed") + }.map { |offloading| + offloading.split(':')[0] + } + # transform raw data into array of objects + int_meta[:offloading_modes] = _parse_offloading(offloading_data) + rescue + # in case if we have no `ethtool` package installed we should + # return empty array to support nailgun's rest api call + int_meta[:offloading_modes] = [] + end detailed_meta[:interfaces] << int_meta end rescue Exception => e