Add PHC and timestamping info to network interface facts on Linux (#21767)

This commit is contained in:
Miroslav Lichvar 2017-03-24 17:09:33 +01:00 committed by Adrian Likins
parent 25be6aebc3
commit c1a766df98

View file

@ -2721,7 +2721,7 @@ class LinuxNetwork(Network):
parse_ip_output(primary_data)
parse_ip_output(secondary_data, secondary=True)
interfaces[device]['features'] = self.get_ethtool_data(device)
interfaces[device].update(self.get_ethtool_data(device))
# replace : by _ in interface name since they are hard to use in template
new_interfaces = {}
@ -2734,12 +2734,13 @@ class LinuxNetwork(Network):
def get_ethtool_data(self, device):
features = {}
data = {}
ethtool_path = self.module.get_bin_path("ethtool")
if ethtool_path:
args = [ethtool_path, '-k', device]
rc, stdout, stderr = self.module.run_command(args, errors='surrogate_then_replace')
if rc == 0:
features = {}
for line in stdout.strip().splitlines():
if not line or line.endswith(":"):
continue
@ -2747,7 +2748,18 @@ class LinuxNetwork(Network):
if not value:
continue
features[key.strip().replace('-','_')] = value.strip()
return features
data['features'] = features
args = [ethtool_path, '-T', device]
rc, stdout, stderr = self.module.run_command(args, errors='surrogate_then_replace')
if rc == 0:
data['timestamping'] = [m.lower() for m in re.findall('SOF_TIMESTAMPING_(\w+)', stdout)]
data['hw_timestamp_filters'] = [m.lower() for m in re.findall('HWTSTAMP_FILTER_(\w+)', stdout)]
m = re.search('PTP Hardware Clock: (\d+)', stdout)
if m:
data['phc_index'] = int(m.groups()[0])
return data
class GenericBsdIfconfigNetwork(Network):