From d09dc2f45ed2e6a93008aa8bace04856c22d26bc Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Fri, 14 May 2021 09:29:57 +0800 Subject: [PATCH] Add helper to get value by field using "nmcli --get-values" Resolves: bz1919052 Upstream: Fedora Conflict: None commit 10c309b5f715496d70959a06f7c236cab31fb5a9 Author: Coiby Xu Date: Thu Apr 1 15:32:08 2021 +0800 Add helper to get value by field using "nmcli --get-values" nmcli --get-values connection show /org/freedesktop/NetworkManager/ActiveConnection/1 returns the following value for the corresponding field respectively, Field Value IP4.DNS "10.19.42.41 | 10.11.5.19 | 10.5.30.160" 802-3-ethernet.s390-subchannels "" bond.options "mode=balance-rr" Signed-off-by: Coiby Xu Acked-by: Kairui Song Signed-off-by: Coiby Xu --- kdump-lib.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/kdump-lib.sh b/kdump-lib.sh index 46e5e03..795f952 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -372,6 +372,26 @@ get_hwaddr() fi } + +# Get value by a field using "nmcli -g" +# +# "nmcli --get-values" allows us to retrive value(s) by field, for example, +# nmcli --get-values connection show /org/freedesktop/NetworkManager/ActiveConnection/1 +# returns the following value for the corresponding field respectively, +# Field Value +# IP4.DNS "10.19.42.41 | 10.11.5.19 | 10.5.30.160" +# 802-3-ethernet.s390-subchannels "" +# bond.options "mode=balance-rr" +get_nmcli_value_by_field() +{ + local _nm_show_cmd=$1 + local _field=$2 + + local val=$(LANG=C nmcli --get-values $_field $_nm_show_cmd) + + echo -n "$val" +} + get_ifcfg_by_device() { grep -E -i -l "^[[:space:]]*DEVICE=\"*${1}\"*[[:space:]]*$" \