]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
network: fully support/use VIR_NETWORK_XML_INACTIVE flag
authorLaine Stump <laine@laine.org>
Mon, 4 Jun 2012 18:45:16 +0000 (14:45 -0400)
committerLaine Stump <laine@laine.org>
Wed, 13 Jun 2012 18:53:35 +0000 (14:53 -0400)
commit 52d064f42dbc857f4096dc60c0335395ffac73aa added
VIR_NETWORK_XML_INACTIVE in order to allow suppressing the
auto-generated list of VFs in network definitions, and a --inactive
flag to virsh net-dumpxml to take advantage of the flag. However, it
missed out on two opportunities:

1) Use INACTIVE to get the current config of the network as it
   exists on disk, rather than the currently active config.

2) Add INACTIVE to the flags used for the virsh net-edit command, so
   that it won't include the forward-pool interfaces that were
   autogenerated, and so that a re-edit of the network prior to
   restarting it will show any other edits made since the last restart
   of the network. (prior to this patch, if you edited a network a 2nd
   time without restarting, all of the previous edits would magically
   disappear).

In order to fit with the new #define-based generic edit function in
virsh.c, a new function vshNetworkGetXMLDesc() was added. This
function first tries to call virNetworkGetXMLDesc with the INACTIVE
flag added, then retries without if the first attempt fails (in the
manner expected when the server doesn't support it).

src/network/bridge_driver.c
tools/virsh.c
tools/virsh.pod

index 5f3132c4cda6fc9cb398c16a49804b06d3520b4c..79d3010f058aa84fe8540f01c3af352e388033fd 100644 (file)
@@ -2533,6 +2533,7 @@ static char *networkGetXMLDesc(virNetworkPtr net,
 {
     struct network_driver *driver = net->conn->networkPrivateData;
     virNetworkObjPtr network;
+    virNetworkDefPtr def;
     char *ret = NULL;
 
     virCheckFlags(VIR_NETWORK_XML_INACTIVE, NULL);
@@ -2547,7 +2548,12 @@ static char *networkGetXMLDesc(virNetworkPtr net,
         goto cleanup;
     }
 
-    ret = virNetworkDefFormat(network->def, flags);
+    if ((flags & VIR_NETWORK_XML_INACTIVE) && network->newDef)
+        def = network->newDef;
+    else
+        def = network->def;
+
+    ret = virNetworkDefFormat(def, flags);
 
 cleanup:
     if (network)
index 90ea43d8278d1e9c8989e9398ea082d3749980b7..98305c0d7e56cbabbf13b59eae82340e0e17184b 100644 (file)
@@ -15823,13 +15823,29 @@ static const vshCmdOptDef opts_network_edit[] = {
     {NULL, 0, 0, NULL}
 };
 
+static char *vshNetworkGetXMLDesc(virNetworkPtr network)
+{
+    unsigned int flags = VIR_NETWORK_XML_INACTIVE;
+    char *doc = virNetworkGetXMLDesc(network, flags);
+
+    if (!doc && last_error->code == VIR_ERR_INVALID_ARG) {
+        /* The server side libvirt doesn't support
+         * VIR_NETWORK_XML_INACTIVE, so retry without it.
+         */
+        virFreeError(last_error);
+        last_error = NULL;
+        flags &= ~VIR_NETWORK_XML_INACTIVE;
+        doc = virNetworkGetXMLDesc(network, flags);
+    }
+    return doc;
+}
+
 static bool
 cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd)
 {
     bool ret = false;
     virNetworkPtr network = NULL;
     virNetworkPtr network_edited = NULL;
-    unsigned int flags = 0;
 
     if (!vshConnectionUsability(ctl, ctl->conn))
         goto cleanup;
@@ -15838,7 +15854,7 @@ cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd)
     if (network == NULL)
         goto cleanup;
 
-#define EDIT_GET_XML virNetworkGetXMLDesc(network, flags)
+#define EDIT_GET_XML vshNetworkGetXMLDesc(network)
 #define EDIT_NOT_CHANGED \
     vshPrint(ctl, _("Network %s XML configuration not changed.\n"), \
              virNetworkGetName (network));                          \
index 6553825d7bb2a885ca2f0d96aea1aea7cea1d12d..6ca316e746efd1a976f674d43459a30bac757b1b 100644 (file)
@@ -1823,7 +1823,7 @@ Edit the XML configuration file for a network.
 
 This is equivalent to:
 
- virsh net-dumpxml network > network.xml
+ virsh net-dumpxml --inactive network > network.xml
  vi network.xml (or make changes with your other text editor)
  virsh net-define network.xml