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

[libvirt] [PATCH] metadata: group metadata next to description



It's better to group all the metadata together.  This is a
cosmetic output change; since the RNG allows interleave, it
doesn't matter where the user stuck it on input, and an XPath
query will find it in the same location when parsing the output.

* src/conf/domain_conf.c (virDomainDefFormatInternal): Output
metadata earlier.
* docs/formatdomain.html.in: Update documentation.
* tests/domainsnapshotxml2xmlout/metadata.xml: Update test.
* tests/qemuxml2xmloutdata/qemuxml2xmlout-metadata.xml: Likewise.
---

As threatened here:

> I also think that this section belongs up next to <description>; but
> I'll move it as a followup patch.

 docs/formatdomain.html.in                          |   39 +++++++----------
 src/conf/domain_conf.c                             |   47 ++++++++++----------
 tests/domainsnapshotxml2xmlout/metadata.xml        |    8 ++--
 .../qemuxml2xmloutdata/qemuxml2xmlout-metadata.xml |    8 ++--
 4 files changed, 47 insertions(+), 55 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 6b025e8..dca9a81 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -33,6 +33,10 @@
   &lt;name&gt;fv0&lt;/name&gt;
   &lt;uuid&gt;4dea22b31d52d8f32516782e98ab3fa0&lt;/uuid&gt;
   &lt;description&gt;Some human readable description&lt;/description&gt;
+  &lt;metadata&gt;
+    &lt;app1:foo xmlns:app1="http://app1.org/app1/"&gt;..&lt;/app1:foo&gt;
+    &lt;app2:bar xmlns:app2="http://app1.org/app2/"&gt;..&lt;/app2:bar&gt;
+  &lt;/metadata&gt;
   ...</pre>

     <dl>
@@ -56,9 +60,18 @@

       <dt><code>description</code></dt>
       <dd>The content of the <code>description</code> element provides a
-      human readable description of the virtual machine. This data is not
-      used by libvirt in any way, it can contain any information the user
-      wants. <span class="since">Since 0.7.2</span></dd>
+        human readable description of the virtual machine. This data is not
+        used by libvirt in any way, it can contain any information the user
+        wants. <span class="since">Since 0.7.2</span></dd>
+
+      <dt><code>metadata</code></dt>
+      <dd>The <code>metadata</code> node can be used by applications
+        to store custom metadata in the form of XML
+        nodes/trees. Applications must use custom namespaces on their
+        XML nodes/trees, with only one top-level element per namespace
+        (if the application needs structure, they should have
+        sub-elements to their namespace
+        element). <span class="since">Since 0.9.10</span></dd>
     </dl>

     <h3><a name="elementsOS">Operating system booting</a></h3>
@@ -3556,26 +3569,6 @@ qemu-kvm -net nic,model=? /dev/null
       sub-element <code>label</code> are supported.
     </p>

-    <h3><a name="customMetadata">Custom metadata</a></h3>
-
-<pre>
-  ...
-  &lt;metadata&gt;
-    &lt;app1:foo xmlns:app1="http://app1.org/app1/"&gt;..&lt;/app1:foo&gt;
-    &lt;app2:bar xmlns:app2="http://app1.org/app2/"&gt;..&lt;/app2:bar&gt;
-  &lt;/metadata&gt;
-  ...</pre>
-
-    <dl>
-      <dt><code>metadata</code></dt>
-      <dd>The <code>metadata</code> node can be used by applications to
-      store custom metadata in the form of XML nodes/trees. Applications
-      must use custom namespaces on their XML nodes/trees, with only
-      one top-level element per namespace (if the application needs
-      structure, they should have sub-elements to their namespace
-      element). <span class="since">Since 0.9.10</span></dd>
-    </dl>
-
     <h2><a name="examples">Example configs</a></h2>

     <p>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index f2c8d02..e872396 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11431,6 +11431,29 @@ virDomainDefFormatInternal(virDomainDefPtr def,
     virBufferEscapeString(buf, "  <description>%s</description>\n",
                           def->description);

+    if (def->metadata) {
+        xmlBufferPtr xmlbuf;
+        int oldIndentTreeOutput = xmlIndentTreeOutput;
+
+        /* Indentation on output requires that we previously set
+         * xmlKeepBlanksDefault to 0 when parsing; also, libxml does 2
+         * spaces per level of indentation of intermediate elements,
+         * but no leading indentation before the starting element.
+         * Thankfully, libxml maps what looks like globals into
+         * thread-local uses, so we are thread-safe.  */
+        xmlIndentTreeOutput = 1;
+        xmlbuf = xmlBufferCreate();
+        if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata,
+                        virBufferGetIndent(buf, false) / 2 + 1, 1) < 0) {
+            xmlBufferFree(xmlbuf);
+            xmlIndentTreeOutput = oldIndentTreeOutput;
+            goto cleanup;
+        }
+        virBufferAsprintf(buf, "  %s\n", (char *) xmlBufferContent(xmlbuf));
+        xmlBufferFree(xmlbuf);
+        xmlIndentTreeOutput = oldIndentTreeOutput;
+    }
+
     virBufferAsprintf(buf, "  <memory>%lu</memory>\n", def->mem.max_balloon);
     virBufferAsprintf(buf, "  <currentMemory>%lu</currentMemory>\n",
                       def->mem.cur_balloon);
@@ -11844,30 +11867,6 @@ virDomainDefFormatInternal(virDomainDefPtr def,
             goto cleanup;
     }

-    /* Custom metadata comes at the end */
-    if (def->metadata) {
-        xmlBufferPtr xmlbuf;
-        int oldIndentTreeOutput = xmlIndentTreeOutput;
-
-        /* Indentation on output requires that we previously set
-         * xmlKeepBlanksDefault to 0 when parsing; also, libxml does 2
-         * spaces per level of indentation of intermediate elements,
-         * but no leading indentation before the starting element.
-         * Thankfully, libxml maps what looks like globals into
-         * thread-local uses, so we are thread-safe.  */
-        xmlIndentTreeOutput = 1;
-        xmlbuf = xmlBufferCreate();
-        if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata,
-                        virBufferGetIndent(buf, false) / 2 + 1, 1) < 0) {
-            xmlBufferFree(xmlbuf);
-            xmlIndentTreeOutput = oldIndentTreeOutput;
-            goto cleanup;
-        }
-        virBufferAsprintf(buf, "  %s\n", (char *) xmlBufferContent(xmlbuf));
-        xmlBufferFree(xmlbuf);
-        xmlIndentTreeOutput = oldIndentTreeOutput;
-    }
-
     virBufferAddLit(buf, "</domain>\n");

     if (virBufferError(buf))
diff --git a/tests/domainsnapshotxml2xmlout/metadata.xml b/tests/domainsnapshotxml2xmlout/metadata.xml
index 45180c9..f0ad70b 100644
--- a/tests/domainsnapshotxml2xmlout/metadata.xml
+++ b/tests/domainsnapshotxml2xmlout/metadata.xml
@@ -9,6 +9,10 @@
   <domain type='qemu'>
     <name>QEMUGuest1</name>
     <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+    <metadata>
+      <app1:foo xmlns:app1="http://foo.org/";>fooish</app1:foo>
+      <app2:bar xmlns:app2="http://bar.com/"; maman="baz">barish</app2:bar>
+    </metadata>
     <memory>219100</memory>
     <currentMemory>219100</currentMemory>
     <vcpu cpuset='1-4,8-20,525'>1</vcpu>
@@ -30,9 +34,5 @@
       <controller type='ide' index='0'/>
       <memballoon model='virtio'/>
     </devices>
-    <metadata>
-      <app1:foo xmlns:app1="http://foo.org/";>fooish</app1:foo>
-      <app2:bar xmlns:app2="http://bar.com/"; maman="baz">barish</app2:bar>
-    </metadata>
   </domain>
 </domainsnapshot>
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-metadata.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-metadata.xml
index a6888ee..a029404 100644
--- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-metadata.xml
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-metadata.xml
@@ -1,6 +1,10 @@
 <domain type='qemu'>
   <name>QEMUGuest1</name>
   <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <metadata>
+    <app1:foo xmlns:app1="http://foo.org/";>fooish</app1:foo>
+    <app2:bar xmlns:app2="http://bar.com/"; maman="baz">barish</app2:bar>
+  </metadata>
   <memory>219100</memory>
   <currentMemory>219100</currentMemory>
   <vcpu cpuset='1-4,8-20,525'>1</vcpu>
@@ -22,8 +26,4 @@
     <controller type='ide' index='0'/>
     <memballoon model='virtio'/>
   </devices>
-  <metadata>
-    <app1:foo xmlns:app1="http://foo.org/";>fooish</app1:foo>
-    <app2:bar xmlns:app2="http://bar.com/"; maman="baz">barish</app2:bar>
-  </metadata>
 </domain>
-- 
1.7.7.5


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