]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: let domif-{get,set}link take target name
authorTaku Izumi <izumi.taku@jp.fujitsu.com>
Fri, 20 Jan 2012 06:30:47 +0000 (15:30 +0900)
committerEric Blake <eblake@redhat.com>
Fri, 20 Jan 2012 23:53:36 +0000 (16:53 -0700)
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@jp.fujitsu.com>
tools/virsh.c
tools/virsh.pod

index ddbe6713dfa5d7bd816a6578b092fb5fa19a451b..d635b56a7ee31f40d507865d26aef3be6a770f5f 100644 (file)
@@ -1344,8 +1344,11 @@ cmdDomIfSetLink (vshControl *ctl, const vshCmd *cmd)
     virDomainPtr dom;
     const char *iface;
     const char *state;
-    const char *mac;
+    const char *value;
     const char *desc;
+    unsigned char macaddr[VIR_MAC_BUFLEN];
+    const char *element;
+    const char *attr;
     bool persistent;
     bool ret = false;
     unsigned int flags = 0;
@@ -1405,26 +1408,34 @@ cmdDomIfSetLink (vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
     }
 
+    if (virParseMacAddr(iface, macaddr) == 0) {
+        element = "mac";
+        attr = "address";
+    } else {
+        element = "target";
+        attr = "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")) {
-                mac = virXMLPropString(cur, "address");
+                xmlStrEqual(cur->name, BAD_CAST element)) {
+                value = virXMLPropString(cur, attr);
 
-                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:
@@ -1509,7 +1520,10 @@ cmdDomIfGetLink (vshControl *ctl, const vshCmd *cmd)
     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 *attr;
     bool ret = false;
     int i;
     char *desc;
@@ -1552,27 +1566,35 @@ cmdDomIfGetLink (vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
     }
 
+    if (virParseMacAddr(iface, macaddr) == 0) {
+        element = "mac";
+        attr = "address";
+    } else {
+        element = "target";
+        attr = "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, attr);
 
-                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 c88395bfa1d76e7eca640279d5f6282d363408a3..67f93a9acd2f06f113fe8f6980af9ed9009120e7 100644 (file)
@@ -469,16 +469,18 @@ B<Explanation of fields> (fields appear in the folowing order):
 
 Get network interface stats for a running domain.
 
-=item B<domif-setlink> I<domain> I<interface-MAC> I<state> I<--persistent>
+=item B<domif-setlink> I<domain> I<interface-device> I<state> I<--persistent>
 
 Modify link state of the domain's virtual interface. Possible values for
 state are "up" and "down. If --persistent is specified, only the persistent
 configuration of the domain is modified.
+I<interface-device> can be the interface's target name or the MAC address.
 
-=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>]]