[PATCH 1/2] virsh: extend domif-{get, set}link command to accept target name as a parameter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Other virsh domifXXX commands can accept target name 
as a parameter to specify interface. From viewpoint of
consistency, virsh domif-getlink command should accept
target name as a parameter. This patch achieves this.


Signed-off-by: Taku Izumi <izumi.taku@xxxxxxxxxxxxxx>
---
 tools/virsh.c   |   25 ++++++++++++++++++-------
 tools/virsh.pod |    3 ++-
 2 files changed, 20 insertions(+), 8 deletions(-)

Index: libvirt/tools/virsh.c
===================================================================
--- libvirt.orig/tools/virsh.c
+++ libvirt/tools/virsh.c
@@ -1509,7 +1509,10 @@ cmdDomIfGetLink (vshControl *ctl, const 
     const char *iface = NULL;
     int flags = 0;
     char *state = NULL;
-    char *mac = NULL;
+    char *value = NULL;
+    unsigned char macaddr[VIR_MAC_BUFLEN];
+    const char *element;
+    const char *attribute;
     bool ret = false;
     int i;
     char *desc;
@@ -1552,27 +1555,35 @@ cmdDomIfGetLink (vshControl *ctl, const 
         goto cleanup;
     }
 
+    if (virParseMacAddr(iface, macaddr) == 0) {
+        element = "mac";
+        attribute = "address";
+    } else {
+        element = "target";
+        attribute = "dev";
+    }
+
     /* find interface with matching mac addr */
     for (i = 0; i < obj->nodesetval->nodeNr; i++) {
         cur = obj->nodesetval->nodeTab[i]->children;
 
         while (cur) {
             if (cur->type == XML_ELEMENT_NODE &&
-                xmlStrEqual(cur->name, BAD_CAST "mac")) {
+                xmlStrEqual(cur->name, BAD_CAST element)) {
 
-                mac = virXMLPropString(cur, "address");
+                value = virXMLPropString(cur, attribute);
 
-                if (STRCASEEQ(mac, iface)){
-                    VIR_FREE(mac);
+                if (STRCASEEQ(value, iface)){
+                    VIR_FREE(value);
                     goto hit;
                 }
-                VIR_FREE(mac);
+                VIR_FREE(value);
             }
             cur = cur->next;
         }
     }
 
-    vshError(ctl, _("Interface with address '%s' not found."), iface);
+    vshError(ctl, _("Interface (%s: %s) not found."), element, iface);
     goto cleanup;
 
 hit:
Index: libvirt/tools/virsh.pod
===================================================================
--- libvirt.orig/tools/virsh.pod
+++ libvirt/tools/virsh.pod
@@ -475,10 +475,11 @@ Modify link state of the domain's virtua
 state are "up" and "down. If --persistent is specified, only the persistent
 configuration of the domain is modified.
 
-=item B<domif-getlink> I<domain> I<interface-MAC> I<--persistent>
+=item B<domif-getlink> I<domain> I<interface-device> I<--persistent>
 
 Query link state of the domain's virtual interface. If --persistent
 is specified, query the persistent configuration.
+I<interface-device> can be the interface's target name or the MAC address.
 
 =item B<domiftune> I<domain> I<interface-device>
 [[I<--config>] [I<--live>] | [I<--current>]]

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]