[PATCHv2 09/13] snapshot: simplify indentation of network xml

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

 



More simplifications possible due to auto-indent.  Also,
<bandwidth> within <actual> was only using 6 instead of 8 spaces.

* src/util/network.h (virVirtualPortProfileFormat)
(virBandwidthDefFormat): Alter signature.
* src/util/network.c (virVirtualPortProfileFormat)
(virBandwidthDefFormat): Alter indentation.
(virBandwidthChildDefFormat): Tweak to make use easier.
* src/conf/network_conf.c (virPortGroupDefFormat)
(virNetworkDefFormat): Adjust callers.
* src/conf/domain_conf.c (virDomainNetDefFormat): Likewise.
(virDomainActualNetDefFormat): Likewise, and fix bandwidth
indentation.
---
 src/conf/domain_conf.c  |   23 ++++++++++++++-------
 src/conf/network_conf.c |   14 +++++++++---
 src/util/network.c      |   49 ++++++++++++++++------------------------------
 src/util/network.h      |   11 ++++-----
 4 files changed, 47 insertions(+), 50 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 40b06f3..70201af 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9415,15 +9415,18 @@ virDomainActualNetDefFormat(virBufferPtr buf,
             return ret;
         }
         virBufferAsprintf(buf, " mode='%s'/>\n", mode);
-        virVirtualPortProfileFormat(buf, def->data.direct.virtPortProfile,
-                                    "        ");
+        virBufferAdjustIndent(buf, 8);
+        virVirtualPortProfileFormat(buf, def->data.direct.virtPortProfile);
+        virBufferAdjustIndent(buf, -8);
         break;
     default:
         break;
     }

-    if (virBandwidthDefFormat(buf, def->bandwidth, "      ") < 0)
+    virBufferAdjustIndent(buf, 8);
+    if (virBandwidthDefFormat(buf, def->bandwidth) < 0)
         goto error;
+    virBufferAdjustIndent(buf, -8);

     virBufferAddLit(buf, "      </actual>\n");

@@ -9462,8 +9465,9 @@ virDomainNetDefFormat(virBufferPtr buf,
                                  def->data.network.portgroup);
         }
         virBufferAddLit(buf, "/>\n");
-        virVirtualPortProfileFormat(buf, def->data.network.virtPortProfile,
-                                    "      ");
+        virBufferAdjustIndent(buf, 6);
+        virVirtualPortProfileFormat(buf, def->data.network.virtPortProfile);
+        virBufferAdjustIndent(buf, -6);
         if ((flags & VIR_DOMAIN_XML_INTERNAL_ACTUAL_NET) &&
             (virDomainActualNetDefFormat(buf, def->data.network.actual) < 0))
             return -1;
@@ -9514,8 +9518,9 @@ virDomainNetDefFormat(virBufferPtr buf,
         virBufferAsprintf(buf, " mode='%s'",
                    virMacvtapModeTypeToString(def->data.direct.mode));
         virBufferAddLit(buf, "/>\n");
-        virVirtualPortProfileFormat(buf, def->data.direct.virtPortProfile,
-                                    "      ");
+        virBufferAdjustIndent(buf, 6);
+        virVirtualPortProfileFormat(buf, def->data.direct.virtPortProfile);
+        virBufferAdjustIndent(buf, -6);
         break;

     case VIR_DOMAIN_NET_TYPE_USER:
@@ -9580,8 +9585,10 @@ virDomainNetDefFormat(virBufferPtr buf,
         virBufferAsprintf(buf, "      <link state='%s'/>\n",
                           virDomainNetInterfaceLinkStateTypeToString(def->linkstate));

-    if (virBandwidthDefFormat(buf, def->bandwidth, "      ") < 0)
+    virBufferAdjustIndent(buf, 6);
+    if (virBandwidthDefFormat(buf, def->bandwidth) < 0)
         return -1;
+    virBufferAdjustIndent(buf, -6);

     if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
         return -1;
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index b98ffad..7bc2e2c 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -1267,8 +1267,10 @@ virPortGroupDefFormat(virBufferPtr buf,
         virBufferAddLit(buf, " default='yes'");
     }
     virBufferAddLit(buf, ">\n");
-    virVirtualPortProfileFormat(buf, def->virtPortProfile, "    ");
-    virBandwidthDefFormat(buf, def->bandwidth, "    ");
+    virBufferAdjustIndent(buf, 4);
+    virVirtualPortProfileFormat(buf, def->virtPortProfile);
+    virBandwidthDefFormat(buf, def->bandwidth);
+    virBufferAdjustIndent(buf, -4);
     virBufferAddLit(buf, "  </portgroup>\n");
 }

@@ -1341,15 +1343,19 @@ char *virNetworkDefFormat(const virNetworkDefPtr def)
     if (virNetworkDNSDefFormat(&buf, def->dns) < 0)
         goto error;

-    if (virBandwidthDefFormat(&buf, def->bandwidth, "  ") < 0)
+    virBufferAdjustIndent(&buf, 2);
+    if (virBandwidthDefFormat(&buf, def->bandwidth) < 0)
         goto error;
+    virBufferAdjustIndent(&buf, -2);

     for (ii = 0; ii < def->nips; ii++) {
         if (virNetworkIpDefFormat(&buf, &def->ips[ii]) < 0)
             goto error;
     }

-    virVirtualPortProfileFormat(&buf, def->virtPortProfile, "  ");
+    virBufferAdjustIndent(&buf, 2);
+    virVirtualPortProfileFormat(&buf, def->virtPortProfile);
+    virBufferAdjustIndent(&buf, -2);

     for (ii = 0; ii < def->nPortGroups; ii++)
         virPortGroupDefFormat(&buf, &def->portGroups[ii]);
diff --git a/src/util/network.c b/src/util/network.c
index ee69557..edf9c50 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -881,16 +881,14 @@ virVirtualPortProfileEqual(virVirtualPortProfileParamsPtr a, virVirtualPortProfi

 void
 virVirtualPortProfileFormat(virBufferPtr buf,
-                            virVirtualPortProfileParamsPtr virtPort,
-                            const char *indent)
+                            virVirtualPortProfileParamsPtr virtPort)
 {
     char uuidstr[VIR_UUID_STRING_BUFLEN];

     if (!virtPort || virtPort->virtPortType == VIR_VIRTUALPORT_NONE)
         return;

-    virBufferAsprintf(buf, "%s<virtualport type='%s'>\n",
-                      indent,
+    virBufferAsprintf(buf, "<virtualport type='%s'>\n",
                       virVirtualPortTypeToString(virtPort->virtPortType));

     switch (virtPort->virtPortType) {
@@ -902,9 +900,8 @@ virVirtualPortProfileFormat(virBufferPtr buf,
         virUUIDFormat(virtPort->u.virtPort8021Qbg.instanceID,
                       uuidstr);
         virBufferAsprintf(buf,
-                          "%s  <parameters managerid='%d' typeid='%d' "
+                          "  <parameters managerid='%d' typeid='%d' "
                           "typeidversion='%d' instanceid='%s'/>\n",
-                          indent,
                           virtPort->u.virtPort8021Qbg.managerID,
                           virtPort->u.virtPort8021Qbg.typeID,
                           virtPort->u.virtPort8021Qbg.typeIDVersion,
@@ -913,13 +910,12 @@ virVirtualPortProfileFormat(virBufferPtr buf,

     case VIR_VIRTUALPORT_8021QBH:
         virBufferAsprintf(buf,
-                          "%s  <parameters profileid='%s'/>\n",
-                          indent,
+                          "  <parameters profileid='%s'/>\n",
                           virtPort->u.virtPort8021Qbh.profileID);
         break;
     }

-    virBufferAsprintf(buf, "%s</virtualport>\n", indent);
+    virBufferAddLit(buf, "</virtualport>\n");
 }

 static int
@@ -1074,11 +1070,14 @@ virBandwidthChildDefFormat(virBufferPtr buf,
                            virRatePtr def,
                            const char *elem_name)
 {
-    if (!buf || !def || !elem_name)
+    if (!buf || !elem_name)
         return -1;
+    if (!def)
+        return 0;

     if (def->average) {
-        virBufferAsprintf(buf, "<%s average='%llu'", elem_name, def->average);
+        virBufferAsprintf(buf, "  <%s average='%llu'", elem_name,
+                          def->average);

         if (def->peak)
             virBufferAsprintf(buf, " peak='%llu'", def->peak);
@@ -1095,17 +1094,15 @@ virBandwidthChildDefFormat(virBufferPtr buf,
  * virBandwidthDefFormat:
  * @buf: Buffer to print to
  * @def: Data source
- * @indent: prepend all lines printed with this
  *
  * Formats bandwidth and prepend each line with @indent.
- * Passing NULL to @indent is equivalent passing "".
+ * @buf may use auto-indentation.
  *
  * Returns 0 on success, else -1.
  */
 int
 virBandwidthDefFormat(virBufferPtr buf,
-                      virBandwidthPtr def,
-                      const char *indent)
+                      virBandwidthPtr def)
 {
     int ret = -1;

@@ -1117,23 +1114,11 @@ virBandwidthDefFormat(virBufferPtr buf,
         goto cleanup;
     }

-    if (!indent)
-        indent = "";
-
-    virBufferAsprintf(buf, "%s<bandwidth>\n", indent);
-    if (def->in) {
-        virBufferAsprintf(buf, "%s  ", indent);
-        if (virBandwidthChildDefFormat(buf, def->in, "inbound") < 0)
-            goto cleanup;
-    }
-
-    if (def->out) {
-        virBufferAsprintf(buf, "%s  ", indent);
-        if (virBandwidthChildDefFormat(buf, def->out, "outbound") < 0)
-            goto cleanup;
-    }
-
-    virBufferAsprintf(buf, "%s</bandwidth>\n", indent);
+    virBufferAddLit(buf, "<bandwidth>\n");
+    if (virBandwidthChildDefFormat(buf, def->in, "inbound") < 0 ||
+        virBandwidthChildDefFormat(buf, def->out, "outbound") < 0)
+        goto cleanup;
+    virBufferAddLit(buf, "</bandwidth>\n");

     ret = 0;

diff --git a/src/util/network.h b/src/util/network.h
index 4d195af..552d5fd 100644
--- a/src/util/network.h
+++ b/src/util/network.h
@@ -1,7 +1,7 @@
 /*
  * network.h: network helper APIs for libvirt
  *
- * Copyright (C) 2009-2009 Red Hat, Inc.
+ * Copyright (C) 2009-2009, 2011 Red Hat, Inc.
  *
  * See COPYING.LIB for the License of this software
  *
@@ -147,16 +147,15 @@ virVirtualPortProfileParseXML(xmlNodePtr node,
                               virVirtualPortProfileParamsPtr *virtPort);
 void
 virVirtualPortProfileFormat(virBufferPtr buf,
-                            virVirtualPortProfileParamsPtr virtPort,
-                            const char *indent);
+                            virVirtualPortProfileParamsPtr virtPort);

-bool virVirtualPortProfileEqual(virVirtualPortProfileParamsPtr a, virVirtualPortProfileParamsPtr b);
+bool virVirtualPortProfileEqual(virVirtualPortProfileParamsPtr a,
+                                virVirtualPortProfileParamsPtr b);

 virBandwidthPtr virBandwidthDefParseNode(xmlNodePtr node);
 void virBandwidthDefFree(virBandwidthPtr def);
 int virBandwidthDefFormat(virBufferPtr buf,
-                          virBandwidthPtr def,
-                          const char *indent);
+                          virBandwidthPtr def);

 int virBandwidthEnable(virBandwidthPtr bandwidth, const char *iface);
 int virBandwidthDisable(const char *iface, bool may_fail);
-- 
1.7.4.4

--
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]