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

[libvirt] [PATCH 5/5 v3] Added new option to virsh net-dumpxml called --inactive



The above option helps to differentiate between implicit and explicit interface pools.
---
 include/libvirt/libvirt.h.in |    4 ++++
 src/conf/network_conf.c      |   10 +++++++---
 src/conf/network_conf.h      |    2 +-
 src/network/bridge_driver.c  |    4 ++--
 src/test/test_driver.c       |    2 +-
 src/vbox/vbox_tmpl.c         |    2 +-
 tests/networkxml2xmltest.c   |    2 +-
 tools/virsh.c                |   13 +++++++++++--
 8 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 2480add..45fe060 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1783,6 +1783,10 @@ int                      virNodeGetCellsFreeMemory(virConnectPtr conn,
  * Virtual Networks API
  */
 
+typedef enum {
+    VIR_NETWORK_XML_INACTIVE = (1 << 0), /* dump inactive network information */
+} virNetworkXMLFlags;
+
 /**
  * virNetwork:
  *
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 9557e29..37b7454 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -1326,7 +1326,7 @@ virPortGroupDefFormat(virBufferPtr buf,
     return 0;
 }
 
-char *virNetworkDefFormat(const virNetworkDefPtr def)
+char *virNetworkDefFormat(const virNetworkDefPtr def, unsigned int flags)
 {
     virBuffer buf = VIR_BUFFER_INITIALIZER;
     unsigned char *uuid;
@@ -1366,6 +1366,9 @@ char *virNetworkDefFormat(const virNetworkDefPtr def)
             }
         }
 
+        if (flags && def->nForwardPfs) 
+            goto escape;
+
         if (def->nForwardIfs) {
             for (ii = 0; ii < def->nForwardIfs; ii++) {
                 if (def->forwardIfs[ii].dev) {
@@ -1373,8 +1376,9 @@ char *virNetworkDefFormat(const virNetworkDefPtr def)
                                           def->forwardIfs[ii].dev);
                 }
             }
-            virBufferAddLit(&buf, "  </forward>\n");
         }
+    escape:
+        virBufferAddLit(&buf, "  </forward>\n");
     }
 
     if (def->forwardType == VIR_NETWORK_FORWARD_NONE ||
@@ -1484,7 +1488,7 @@ int virNetworkSaveConfig(const char *configDir,
     int ret = -1;
     char *xml;
 
-    if (!(xml = virNetworkDefFormat(def)))
+    if (!(xml = virNetworkDefFormat(def, 0)))
         goto cleanup;
 
     if (virNetworkSaveXML(configDir, def, xml))
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index e25f8d3..27e568b 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -211,7 +211,7 @@ virNetworkDefPtr virNetworkDefParseFile(const char *filename);
 virNetworkDefPtr virNetworkDefParseNode(xmlDocPtr xml,
                                         xmlNodePtr root);
 
-char *virNetworkDefFormat(const virNetworkDefPtr def);
+char *virNetworkDefFormat(const virNetworkDefPtr def, unsigned int flags);
 
 static inline const char *
 virNetworkDefForwardIf(const virNetworkDefPtr def, size_t n)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 9ae9c50..feacd4a 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -2482,7 +2482,7 @@ static char *networkGetXMLDesc(virNetworkPtr net,
     virNetworkObjPtr network;
     char *ret = NULL;
 
-    virCheckFlags(0, NULL);
+    virCheckFlags(VIR_NETWORK_XML_INACTIVE, NULL);
 
     networkDriverLock(driver);
     network = virNetworkFindByUUID(&driver->networks, net->uuid);
@@ -2494,7 +2494,7 @@ static char *networkGetXMLDesc(virNetworkPtr net,
         goto cleanup;
     }
 
-    ret = virNetworkDefFormat(network->def);
+    ret = virNetworkDefFormat(network->def, flags);
 
 cleanup:
     if (network)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 89f7df1..b88bdfe 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -3264,7 +3264,7 @@ static char *testNetworkGetXMLDesc(virNetworkPtr network,
         goto cleanup;
     }
 
-    ret = virNetworkDefFormat(privnet->def);
+    ret = virNetworkDefFormat(privnet->def, flags);
 
 cleanup:
     if (privnet)
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 9b74a7b..270f106 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -8132,7 +8132,7 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network,
     VBOX_UTF16_FREE(networkInterfaceNameUtf16);
     VBOX_RELEASE(host);
 
-    ret = virNetworkDefFormat(def);
+    ret = virNetworkDefFormat(def, 0);
 
 cleanup:
     virNetworkDefFree(def);
diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c
index 5cdbedb..4249caa 100644
--- a/tests/networkxml2xmltest.c
+++ b/tests/networkxml2xmltest.c
@@ -30,7 +30,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
     if (!(dev = virNetworkDefParseString(inXmlData)))
         goto fail;
 
-    if (!(actual = virNetworkDefFormat(dev)))
+    if (!(actual = virNetworkDefFormat(dev, 0)))
         goto fail;
 
     if (STRNEQ(outXmlData, actual)) {
diff --git a/tools/virsh.c b/tools/virsh.c
index 90ff587..87cf48b 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -6619,6 +6619,7 @@ static const vshCmdInfo info_network_dumpxml[] = {
 
 static const vshCmdOptDef opts_network_dumpxml[] = {
     {"network", VSH_OT_DATA, VSH_OFLAG_REQ, N_("network name or uuid")},
+    {"inactive", VSH_OT_BOOL, VSH_OFLAG_NONE, N_("network information of an inactive domain")},
     {NULL, 0, 0, NULL}
 };
 
@@ -6628,14 +6629,22 @@ cmdNetworkDumpXML(vshControl *ctl, const vshCmd *cmd)
     virNetworkPtr network;
     bool ret = true;
     char *dump;
-
+    unsigned int flags = 0;
+    int inactive;
+    
     if (!vshConnectionUsability(ctl, ctl->conn))
         return false;
 
     if (!(network = vshCommandOptNetwork(ctl, cmd, NULL)))
         return false;
+    
+    inactive = vshCommandOptBool (cmd, "inactive");
+    
+    if (inactive)
+        flags |= VIR_NETWORK_XML_INACTIVE;
+
+    dump = virNetworkGetXMLDesc(network, flags);
 
-    dump = virNetworkGetXMLDesc(network, 0);
     if (dump != NULL) {
         vshPrint(ctl, "%s", dump);
         VIR_FREE(dump);
-- 
1.7.4.4


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