From 4d71ff450fc1c5fa5c76c8e025756257cf4067fb Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Tue, 24 Jan 2012 17:26:38 -0700 Subject: [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 the same information 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. --- docs/formatdomain.html.in | 39 +++++++-------- src/conf/domain_conf.c | 47 +++++++++---------- tests/domainsnapshotxml2xmlout/metadata.xml | 8 ++-- .../qemuxml2xmlout-metadata.xml | 8 ++-- 4 files changed, 47 insertions(+), 55 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 6b025e8564..dca9a81a4b 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -33,6 +33,10 @@ <name>fv0</name> <uuid>4dea22b31d52d8f32516782e98ab3fa0</uuid> <description>Some human readable description</description> + <metadata> + <app1:foo xmlns:app1="http://app1.org/app1/">..</app1:foo> + <app2:bar xmlns:app2="http://app1.org/app2/">..</app2:bar> + </metadata> ...
@@ -56,9 +60,18 @@
description
The content of the description 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. Since 0.7.2
+ 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. Since 0.7.2 + +
metadata
+
The metadata 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). Since 0.9.10

Operating system booting

@@ -3556,26 +3569,6 @@ qemu-kvm -net nic,model=? /dev/null sub-element label are supported.

-

Custom metadata

- -
-  ...
-  <metadata>
-    <app1:foo xmlns:app1="http://app1.org/app1/">..</app1:foo>
-    <app2:bar xmlns:app2="http://app1.org/app2/">..</app2:bar>
-  </metadata>
-  ...
- -
-
metadata
-
The metadata 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). Since 0.9.10
-
-

Example configs

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f2c8d02171..e872396cb7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11431,6 +11431,29 @@ virDomainDefFormatInternal(virDomainDefPtr def, virBufferEscapeString(buf, " %s\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, " %lu\n", def->mem.max_balloon); virBufferAsprintf(buf, " %lu\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, "\n"); if (virBufferError(buf)) diff --git a/tests/domainsnapshotxml2xmlout/metadata.xml b/tests/domainsnapshotxml2xmlout/metadata.xml index 45180c9c59..f0ad70b2d2 100644 --- a/tests/domainsnapshotxml2xmlout/metadata.xml +++ b/tests/domainsnapshotxml2xmlout/metadata.xml @@ -9,6 +9,10 @@ QEMUGuest1 c7a5fdbd-edaf-9455-926a-d65c16db1809 + + fooish + barish + 219100 219100 1 @@ -30,9 +34,5 @@ - - fooish - barish - diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-metadata.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-metadata.xml index a6888ee3ae..a029404181 100644 --- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-metadata.xml +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-metadata.xml @@ -1,6 +1,10 @@ QEMUGuest1 c7a5fdbd-edaf-9455-926a-d65c16db1809 + + fooish + barish + 219100 219100 1 @@ -22,8 +26,4 @@ - - fooish - barish -