From c1a766df989230bc0b03d53323f0fcd2809765a1 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Fri, 24 Mar 2017 17:09:33 +0100 Subject: [PATCH] Add PHC and timestamping info to network interface facts on Linux (#21767) --- lib/ansible/module_utils/facts.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index 91147bdac03..ca4c5894fcf 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -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):