1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-09 01:18:00 +03:00

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.
This commit is contained in:
Eric Blake 2012-01-24 17:26:38 -07:00
parent 78af071964
commit 4d71ff450f
4 changed files with 47 additions and 55 deletions

View File

@ -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>
...</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>

View File

@ -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))

View File

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

View File

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