OSDN Git Service

add ethtool\'s informations to LinuxNetAgent
authort.moriyama <t.moriyama@users.sourceforge.jp>
Sun, 21 Jul 2013 17:28:27 +0000 (02:28 +0900)
committert.moriyama <t.moriyama@users.sourceforge.jp>
Sun, 21 Jul 2013 17:28:27 +0000 (02:28 +0900)
linkpair/collect/agent/linuxnet_agent.py

index f052080..4e87c7b 100644 (file)
@@ -2,8 +2,6 @@
 # -*- coding: utf-8 -*-
 #
 
-__version__ = '1.1'
-
 import re
 from linkpair.device import Device
 from linkpair.port import Port
@@ -57,28 +55,52 @@ class LinuxNetAgent(BaseAgent):
                 
         for interface in interfaces:
             # interface informations
+            res_ethtool = self._runner.exec_cmd("ethtool " + interface)
+            self._parse_ethtool_output(res_ethtool, port_meta)
+
+            # interface driver informations
             res_ethtool = self._runner.exec_cmd("ethtool -i " + interface)
-            for i in range(0, len(res_ethtool)):
-                ethtool_line = res_ethtool[i].strip()
-                if self._u.d_push(
-                    re.search(r'(\S+): (\S+)',
-                        ethtool_line)) is not None:
-                    match = self._u.d_pop()
-                    if_property = match.group(1).strip()
-                    port_meta[if_property] = match.group(2).strip()
+            self._parse_ethtool_output(res_ethtool, port_meta)
 
             # interface statistics
             res_ethtool = self._runner.exec_cmd("ethtool -S " + interface)
-            for i in range(0, len(res_ethtool)):
-                ethtool_line = res_ethtool[i].strip()
-                if self._u.d_push(
-                    re.search(r'(\S+): (\S+)',
-                        ethtool_line)) is not None:
-                    match = self._u.d_pop()
-                    if_property = match.group(1).strip()
-                    port_meta[if_property] = match.group(2).strip()
+            self._parse_ethtool_output(res_ethtool, port_meta)
+
+            # interface offload settings
+            res_ethtool = self._runner.exec_cmd("ethtool -k " + interface)
+            self._parse_ethtool_output(res_ethtool, port_meta)
                     
             self._cu.add_port(Port(interface, Port.DEFAULT_TYPE, port_meta))
             interface = ""
             port_meta = {}
+            
+    def _parse_ethtool_output(self, res_ethtool, port_meta):
+        if_property = ""
+        multi_line = False
+        multi_line_property = ""
+        multi_line_value = ""
+        
+        for i in range(0, len(res_ethtool)):
+            ethtool_line = res_ethtool[i].rstrip()
+            if self._u.d_push(
+                re.search(r'(\S.*):\s+(\S.*)', ethtool_line)) is not None:
+                match = self._u.d_pop()
+                if_property = match.group(1).strip()
+                if re.search(r' link modes', if_property):
+                    multi_line = True
+                    multi_line_property = if_property
+                    multi_line_value = match.group(2).strip()
+                else:
+                    if multi_line:
+                        port_meta[multi_line_property] = multi_line_value
+                        multi_line = False
+                        multi_line_property = ""
+                        multi_line_value = ""
+                    port_meta[if_property] = match.group(2).strip()
+
+            elif multi_line and self._u.d_push(
+                re.search(r'\s+(\S.*)', ethtool_line)) is not None:
+                match = self._u.d_pop()
+                multi_line_value += " " + match.group(1).strip()
+