]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
bandwidth: Create format functions
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 22 Jul 2011 14:07:26 +0000 (16:07 +0200)
committerDaniel Veillard <veillard@redhat.com>
Mon, 25 Jul 2011 05:49:44 +0000 (13:49 +0800)
src/conf/domain_conf.c
src/conf/network_conf.c
src/libvirt_private.syms
src/util/network.c
src/util/network.h

index e11ad987a6d56020ec2e2e6488ab6b4e83b39d65..072c970e7d375f4b5efdd480ddee0283db497e67 100644 (file)
@@ -8855,6 +8855,9 @@ virDomainNetDefFormat(virBufferPtr buf,
         virBufferAddLit(buf,   "      </tune>\n");
     }
 
+    if (virBandwidthDefFormat(buf, def->bandwidth, "      ") < 0)
+        return -1;
+
     if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
         return -1;
 
index 01c094cba26e2eafcee3def4d49bf95138c3deda..1ef80dc01db5f654244d909eed56b6e6d2fef9dc 100644 (file)
@@ -1329,6 +1329,9 @@ char *virNetworkDefFormat(const virNetworkDefPtr def)
     if (virNetworkDNSDefFormat(&buf, def->dns) < 0)
         goto error;
 
+    if (virBandwidthDefFormat(&buf, def->bandwidth, "  ") < 0)
+        goto error;
+
     for (ii = 0; ii < def->nips; ii++) {
         if (virNetworkIpDefFormat(&buf, &def->ips[ii]) < 0)
             goto error;
index 5d7faa08776005aac114fa77417a2579bc78a7c7..2efe9412c506e8b60fb426807d1b19d4b0ded4eb 100644 (file)
@@ -710,6 +710,7 @@ nlComm;
 
 
 # network.h
+virBandwidthDefFormat;
 virBandwidthDefFree;
 virBandwidthDefParseNode;
 virSocketAddrBroadcast;
index 2ba6f768fba622058d53656e63d22ac87303f9f5..563921981675f3edfbde942a4d3069f4d79aff59 100644 (file)
@@ -1030,3 +1030,75 @@ virBandwidthDefFree(virBandwidthPtr def)
     VIR_FREE(def->out);
     VIR_FREE(def);
 }
+
+static int
+virBandwidthChildDefFormat(virBufferPtr buf,
+                           virRatePtr def,
+                           const char *elem_name)
+{
+    if (!buf || !def || !elem_name)
+        return -1;
+
+    if (def->average) {
+        virBufferAsprintf(buf, "<%s average='%llu'", elem_name, def->average);
+
+        if (def->peak)
+            virBufferAsprintf(buf, " peak='%llu'", def->peak);
+
+        if (def->burst)
+            virBufferAsprintf(buf, " burst='%llu'", def->burst);
+        virBufferAddLit(buf, "/>\n");
+    }
+
+    return 0;
+}
+
+/**
+ * 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 "".
+ *
+ * Returns 0 on success, else -1.
+ */
+int
+virBandwidthDefFormat(virBufferPtr buf,
+                      virBandwidthPtr def,
+                      const char *indent)
+{
+    int ret = -1;
+
+    if (!buf)
+        goto cleanup;
+
+    if (!def) {
+        ret = 0;
+        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);
+
+    ret = 0;
+
+cleanup:
+    return ret;
+}
index 4d35388c617affcc3d8b844141487bc602a44332..d0181fddfa3c103189633dd72eca3dd184827cfb 100644 (file)
@@ -152,4 +152,7 @@ virVirtualPortProfileFormat(virBufferPtr buf,
 
 virBandwidthPtr virBandwidthDefParseNode(xmlNodePtr node);
 void virBandwidthDefFree(virBandwidthPtr def);
+int virBandwidthDefFormat(virBufferPtr buf,
+                          virBandwidthPtr def,
+                          const char *indent);
 #endif /* __VIR_NETWORK_H__ */