aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2015-06-18 18:38:35 +0100
committerBryn M. Reeves <bmr@redhat.com>2015-06-18 18:38:35 +0100
commit4f7ee2b6b2eb7ba7b5a8a00b4a0fdb7d483afe13 (patch)
treefd31c3820cafcc0263d50c948bc4ea28560108d8
parent0105315ef05489bc7568dbcd0f5c38e5474b866a (diff)
downloadsos-4f7ee2b6b2eb7ba7b5a8a00b4a0fdb7d483afe13.tar.gz
[networking] improve readability of nmcli handling
In order to cope with multiple versions of NetworkManager with incompatible command-line syntax the NM portions of networking's setup() method had become a bit difficult to follow. Hide as much of the version mess as possible behind a local test_nm_status() function that handles all the known versions and use template variables where common command-line text exists between the versions. Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/plugins/networking.py41
1 files changed, 28 insertions, 13 deletions
diff --git a/sos/plugins/networking.py b/sos/plugins/networking.py
index a6db592f..550fe1c4 100644
--- a/sos/plugins/networking.py
+++ b/sos/plugins/networking.py
@@ -120,30 +120,45 @@ class Networking(Plugin):
# NetworkManager >= 0.9.9 will use the long names of
# "nmcli" objects.
- # NetworkManager >= 0.9.9 (Use long names of objects for nmcli)
- nmcli_con_details_cmd = ""
- nmcli_dev_details_cmd = ""
- nmcli_status_cmd_v1 = "nmcli --terse --fields RUNNING general status"
- nmcli_status_cmd_v0 = "nmcli --terse --fields RUNNING nm status"
- if self.call_ext_prog(
- nmcli_status_cmd_v1)['output'].lower().startswith("running"):
+ # All versions conform to the following templates with differnt
+ # strings for the object being operated on.
+ nmcli_con_details_template = "nmcli con %s id"
+ nmcli_dev_details_template = "nmcli dev %s"
+
+ # test NetworkManager status for the specified major version
+ def test_nm_status(version=1):
+ status_template = "nmcli --terse --fields RUNNING %s status"
+ obj_table = [
+ "nm", # < 0.9.9
+ "general" # >= 0.9.9
+ ]
+ status = self.call_ext_prog(status_template % obj_table[version])
+ return status['output'].lower().startswith("running")
+
+ # NetworkManager >= 0.9.9 (Use short name of objects for nmcli)
+ if test_nm_status(version=1):
self.add_cmd_output([
"nmcli general status",
"nmcli con",
"nmcli con show --active",
"nmcli dev"])
- nmcli_con_details_cmd = "nmcli con show id"
- nmcli_dev_details_cmd = "nmcli dev show"
+ nmcli_con_details_cmd = nmcli_con_details_template % "show"
+ nmcli_dev_details_cmd = nmcli_dev_details_template % "show"
+
# NetworkManager < 0.9.9 (Use short name of objects for nmcli)
- elif self.call_ext_prog(
- nmcli_status_cmd_v0)['output'].lower().startswith("running"):
+ elif test_nm_status(version=0):
self.add_cmd_output([
"nmcli nm status",
"nmcli con",
"nmcli con status",
"nmcli dev"])
- nmcli_con_details_cmd = "nmcli con list id"
- nmcli_dev_details_cmd = "nmcli dev list iface"
+ nmcli_con_details_cmd = nmcli_con_details_template % "list id"
+ nmcli_dev_details_cmd = nmcli_dev_details_template % "list iface"
+
+ # No grokkable NetworkManager version present
+ else:
+ nmcli_con_details_cmd = ""
+ nmcli_dev_details_cmd = ""
if len(nmcli_con_details_cmd) > 0:
nmcli_con_show_result = self.call_ext_prog(