On 11/2/20 9:26 AM, Lin Ma wrote:
Signed-off-by: Lin Ma <lma(a)suse.com>
---
tools/virsh-completer-interface.c | 13 +++++++++----
tools/virsh-completer-interface.h | 4 ++++
tools/virsh-interface.c | 8 +++-----
3 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/tools/virsh-completer-interface.c b/tools/virsh-completer-interface.c
index 777bb22b0b..c24a2cea6c 100644
--- a/tools/virsh-completer-interface.c
+++ b/tools/virsh-completer-interface.c
@@ -38,7 +38,8 @@ virshInterfaceCompleter(vshControl *ctl,
VIR_AUTOSTRINGLIST tmp = NULL;
virCheckFlags(VIR_CONNECT_LIST_INTERFACES_ACTIVE |
- VIR_CONNECT_LIST_INTERFACES_INACTIVE,
+ VIR_CONNECT_LIST_INTERFACES_INACTIVE |
+ VIRSH_INTERFACE_COMPLETER_MAC,
NULL);
if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
@@ -50,9 +51,13 @@ virshInterfaceCompleter(vshControl *ctl,
tmp = g_new0(char *, nifaces + 1);
for (i = 0; i < nifaces; i++) {
- const char *name = virInterfaceGetName(ifaces[i]);
-
- tmp[i] = g_strdup(name);
+ if (!(flags & VIRSH_INTERFACE_COMPLETER_MAC)) {
+ const char *name = virInterfaceGetName(ifaces[i]);
+ tmp[i] = g_strdup(name);
+ } else {
+ const char *mac = virInterfaceGetMACString(ifaces[i]);
+ tmp[i] = g_strdup(mac);
+ }
}
ret = g_steal_pointer(&tmp);
diff --git a/tools/virsh-completer-interface.h b/tools/virsh-completer-interface.h
index 2b382222d7..71bc44c4b9 100644
--- a/tools/virsh-completer-interface.h
+++ b/tools/virsh-completer-interface.h
@@ -22,6 +22,10 @@
#include "vsh.h"
+enum {
+ VIRSH_INTERFACE_COMPLETER_MAC = 1 << 0,
+};
This is not correct. VIRSH_INTERFACE_COMPLETER_MAC has value of 1 after
this. But so does VIR_CONNECT_LIST_INTERFACES_INACTIVE and therefore
there is no way to differentiate the two. After this commit 'virsh
iface-start --interface' starts printing MAC addresses instead of names.
If you accept my advice in 04/19 you can avoid this new flag completely.
Michal