This module provides functions that are related to Offloads.
The function parse_offloads in the module is intended to be use for parsing
offloads alias.
It takes argument offloads string and returns tuple of used offloads and its
combinations.
Signed-off-by: Kamil Jerabek <kjerabek(a)redhat.com>
---
v3 * parse_offloads modified to accept also offload "on" and offload name
containing "-"
---
lnst/RecipeCommon/Offloads.py | 53 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
create mode 100644 lnst/RecipeCommon/Offloads.py
diff --git a/lnst/RecipeCommon/Offloads.py b/lnst/RecipeCommon/Offloads.py
new file mode 100644
index 0000000..b78bcf9
--- /dev/null
+++ b/lnst/RecipeCommon/Offloads.py
@@ -0,0 +1,53 @@
+"""
+This module defines the functions for Offloads tuning that can be imported
+directly into LNST Python tasks.
+
+Copyright 2016 Red Hat, Inc.
+Licensed under the GNU General Public License, version 2 as
+published by the Free Software Foundation; see COPYING for details.
+"""
+
+__author__ = """
+kjerabek(a)redhat.com (Kamil Jerabek)
+"""
+
+import re
+
+def parse_offloads(offloads):
+ """Parse offloads combination in string to list of tuple, containing
+ summary of all used offloads, and list of all offloads settings.
+ The function parse all offloads combination, in each set all offloads
+ are on except the ones specified as off.
+
+ Keyword arguments:
+ offloads -- string of offloads combination separated with ';'
+ Expected input: "tso on gso on tx off; tso off tx off ;rx
off".
+ """
+
+ if offloads is None:
+ return None
+
+ is_valid = re.compile(r"^([a-z\-]+\s+(off|on)(\s*[;]\s*|\s*))+$")
+ opts_split = re.compile(r".*?(?=;)|.+$")
+ opts_offloads_split = re.compile(r"([a-z]+(?=\s+(off|on)))+")
+ offloads_split = re.compile(r"([a-z\-]+)(?=\s+off|\s+on)")
+
+ if re.match(is_valid, offloads) is None:
+ raise Exception('Invalid offloads format')
+
+ offload_set = (list(set(re.findall(offloads_split, offloads))), [])
+ opts_match = filter(None, re.findall(opts_split, offloads))
+
+ for opts in opts_match:
+ sett = []
+ match = re.findall(opts_offloads_split, opts)
+
+ for offload in offload_set[0]:
+ if (offload, 'off') in match:
+ sett.append((offload, 'off'))
+ else:
+ sett.append((offload, 'on'))
+
+ offload_set[1].append(sett)
+
+ return offload_set
--
2.5.5