[libvirt] [PATCH] virsh: lookup interface by name or mac other than one by one

Guannan Ren gren at redhat.com
Tue May 14 08:35:20 UTC 2013


On host without interface eth1, 'virsh iface-dumpxml eth1'
it reports
error: Interface not found: couldn't find interface with MAC address 'eth1'

after fix, it reports
error: Interface not found: couldn't find interface named 'eth1'
---
 tools/virsh-interface.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c
index f75c572..47883ae 100644
--- a/tools/virsh-interface.c
+++ b/tools/virsh-interface.c
@@ -46,6 +46,7 @@ vshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd,
 {
     virInterfacePtr iface = NULL;
     const char *n = NULL;
+    bool is_name = false;
     virCheckFlags(VSH_BYNAME | VSH_BYMAC, NULL);
 
     if (!optname)
@@ -62,14 +63,17 @@ vshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd,
     if (name)
         *name = n;
 
+    if (!strchr(n, ':'))
+        is_name = true;
+
     /* try it by NAME */
-    if (flags & VSH_BYNAME) {
+    if (is_name && (flags & VSH_BYNAME)) {
         vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as interface NAME\n",
                  cmd->def->name, optname);
         iface = virInterfaceLookupByName(ctl->conn, n);
-    }
+
     /* try it by MAC */
-    if (!iface && (flags & VSH_BYMAC)) {
+    } else if (!is_name && (flags & VSH_BYMAC)) {
         vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as interface MAC\n",
                  cmd->def->name, optname);
         iface = virInterfaceLookupByMACString(ctl->conn, n);
-- 
1.8.1.4




More information about the libvir-list mailing list