[libvirt] Allow custom metadata in domain configuration XML

Hi, Apologies for not using git-send-mail but for some reason its not working for me at the moment with gmail's SMTP. -- Regards, Zeeshan Ali (Khattak) FSF member#5124

On 01/20/2012 01:15 PM, Zeeshan Ali (Khattak) wrote:
From 6895c107970ea6daf3d0e7f8be9a1a4e97b2278b Mon Sep 17 00:00:00 2001 From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> Date: Fri, 20 Jan 2012 21:50:35 +0200 Subject: [PATCH] Allow custom metadata in domain configuration XML
Applications can now insert custom nodes and hierarchies into domain cofiguration XML. Although currently not enforced, application are required to use their own namespaces on every custom node they insert.
Looks like an interesting idea, as it gives applications more structure than what they would get by overloading the free-form <description>.
--- docs/formatdomain.html.in | 18 ++++++++++++++++++ src/conf/domain_conf.c | 21 +++++++++++++++++++++ src/conf/domain_conf.h | 3 +++
Hmm, you didn't update docs/schemas/domaincommon.rng. But how do you write a schema that accepts a <metadata> element with arbitrary contents? </me searches the web...> http://www.oasis-open.org/committees/relax-ng/tutorial.html#IDAFLZR <define name="anyElement"> <element> <anyName/> <zeroOrMore> <choice> <attribute> <anyName/> </attribute> <text/> <ref name="anyElement"/> </choice> </zeroOrMore> </element> </define> <define name='metadata'> <element name='metadata'> <choice> <text/> <zeroOrMore> <ref name='anyElement'/> </zeroOrMore> </choice> </element> </define>
+ <dl> + <dt><code>metadata</code></dt> + <dd><code>metadata</code> node could be used by applications to + store custom metadata in the form of XML nodes/trees. Applications + must use custom namespaces on any XML nodes they insert here. + <span class="since">Since 0.9.9</span></dd>
0.9.10.
@@ -11833,6 +11841,19 @@ virDomainDefFormatInternal(virDomainDefPtr def, goto cleanup; }
+ /* Custom metadata comes at the end */ + if (def->metadata) { + xmlBufferPtr xmlbuf; + + xmlbuf = xmlBufferCreate(); + if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata, 2, 0) < 0) {
Is this the right level of indentation if buf itself already has indentation (such as when <domain> is nested inside <domainsnapshot>? You may need to use virBufferGetIndent() and use that to alter the fourth argument to xmlNodeDump accordingly. Unless anyone else objects to this XML addition, I think it is probably okay; but I have a couple caveats: 1. you need to add tests that prove we can parse/regenerate user XML (that is, qemuxml2xmltest.c needs a new test case, and I'd also like to see one of the snapshot xml tests covering this to ensure indentation was taken care of) 2. we probably need an API to allow the user to change this XML on the fly for a running domain. Which means you ought to investigate whether you can merge your arbitrary XML alongside Peter's patch series [1] to add <title> and alter <description>. I think that adding a new flag VIR_DOMAIN_DESCRIPTION_METADATA for use in virDomainSetDescription would do the trick, rather than adding yet another API. [1]https://www.redhat.com/archives/libvir-list/2012-January/msg00709.html Looking forward to v2. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Hi Eric, On Fri, Jan 20, 2012 at 11:55 PM, Eric Blake <eblake@redhat.com> wrote:
On 01/20/2012 01:15 PM, Zeeshan Ali (Khattak) wrote:
From 6895c107970ea6daf3d0e7f8be9a1a4e97b2278b Mon Sep 17 00:00:00 2001 From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> Date: Fri, 20 Jan 2012 21:50:35 +0200 Subject: [PATCH] Allow custom metadata in domain configuration XML
Applications can now insert custom nodes and hierarchies into domain cofiguration XML. Although currently not enforced, application are required to use their own namespaces on every custom node they insert.
Looks like an interesting idea, as it gives applications more structure than what they would get by overloading the free-form <description>.
Thanks but four people contributed to this idea so I can't take much credit.
Hmm, you didn't update docs/schemas/domaincommon.rng.
Didn't know there is one. :)
But how do you write a schema that accepts a <metadata> element with arbitrary contents? </me searches the web...>
http://www.oasis-open.org/committees/relax-ng/tutorial.html#IDAFLZR
That might be an issue, I'll look into it.
@@ -11833,6 +11841,19 @@ virDomainDefFormatInternal(virDomainDefPtr def, goto cleanup; }
+ /* Custom metadata comes at the end */ + if (def->metadata) { + xmlBufferPtr xmlbuf; + + xmlbuf = xmlBufferCreate(); + if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata, 2, 0) < 0) {
Is this the right level of indentation if buf itself already has indentation (such as when <domain> is nested inside <domainsnapshot>? You may need to use virBufferGetIndent() and use that to alter the fourth argument to xmlNodeDump accordingly.
K.
Unless anyone else objects to this XML addition, I think it is probably okay; but I have a couple caveats:
1. you need to add tests that prove we can parse/regenerate user XML (that is, qemuxml2xmltest.c needs a new test case, and I'd also like to see one of the snapshot xml tests covering this to ensure indentation was taken care of)
Will do!
2. we probably need an API to allow the user to change this XML on the fly for a running domain.
Do we? I'm not sure about that. At least we (in Boxes context) dont' need it and I'm lazy. :) -- Regards, Zeeshan Ali (Khattak) FSF member#5124

On Fri, Jan 20, 2012 at 02:55:27PM -0700, Eric Blake wrote:
On 01/20/2012 01:15 PM, Zeeshan Ali (Khattak) wrote:
From 6895c107970ea6daf3d0e7f8be9a1a4e97b2278b Mon Sep 17 00:00:00 2001 From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> Date: Fri, 20 Jan 2012 21:50:35 +0200 Subject: [PATCH] Allow custom metadata in domain configuration XML
Applications can now insert custom nodes and hierarchies into domain cofiguration XML. Although currently not enforced, application are required to use their own namespaces on every custom node they insert.
Looks like an interesting idea, as it gives applications more structure than what they would get by overloading the free-form <description>.
--- docs/formatdomain.html.in | 18 ++++++++++++++++++ src/conf/domain_conf.c | 21 +++++++++++++++++++++ src/conf/domain_conf.h | 3 +++
Hmm, you didn't update docs/schemas/domaincommon.rng. But how do you write a schema that accepts a <metadata> element with arbitrary contents? </me searches the web...>
http://www.oasis-open.org/committees/relax-ng/tutorial.html#IDAFLZR
<define name="anyElement"> <element> <anyName/> <zeroOrMore> <choice> <attribute> <anyName/> </attribute> <text/> <ref name="anyElement"/> </choice> </zeroOrMore> </element> </define>
<define name='metadata'> <element name='metadata'> <choice> <text/> <zeroOrMore> <ref name='anyElement'/> </zeroOrMore> </choice> </element> </define>
+ <dl> + <dt><code>metadata</code></dt> + <dd><code>metadata</code> node could be used by applications to + store custom metadata in the form of XML nodes/trees. Applications + must use custom namespaces on any XML nodes they insert here. + <span class="since">Since 0.9.9</span></dd>
0.9.10.
@@ -11833,6 +11841,19 @@ virDomainDefFormatInternal(virDomainDefPtr def, goto cleanup; }
+ /* Custom metadata comes at the end */ + if (def->metadata) { + xmlBufferPtr xmlbuf; + + xmlbuf = xmlBufferCreate(); + if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata, 2, 0) < 0) {
Is this the right level of indentation if buf itself already has indentation (such as when <domain> is nested inside <domainsnapshot>? You may need to use virBufferGetIndent() and use that to alter the fourth argument to xmlNodeDump accordingly.
Unless anyone else objects to this XML addition, I think it is probably okay; but I have a couple caveats:
1. you need to add tests that prove we can parse/regenerate user XML (that is, qemuxml2xmltest.c needs a new test case, and I'd also like to see one of the snapshot xml tests covering this to ensure indentation was taken care of)
2. we probably need an API to allow the user to change this XML on the fly for a running domain. Which means you ought to investigate whether you can merge your arbitrary XML alongside Peter's patch series [1] to add <title> and alter <description>. I think that adding a new flag VIR_DOMAIN_DESCRIPTION_METADATA for use in virDomainSetDescription would do the trick, rather than adding yet another API. [1]https://www.redhat.com/archives/libvir-list/2012-January/msg00709.html
I'm not really convinced we need an API for setting the title/description either. Are we going to create APIs for setting every little attribute of the XML ? IMHO that's the job for libvirt-gconfig. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Mon, Jan 23, 2012 at 10:33:18 +0000, Daniel P. Berrange wrote:
On Fri, Jan 20, 2012 at 02:55:27PM -0700, Eric Blake wrote:
2. we probably need an API to allow the user to change this XML on the fly for a running domain. Which means you ought to investigate whether you can merge your arbitrary XML alongside Peter's patch series [1] to add <title> and alter <description>. I think that adding a new flag VIR_DOMAIN_DESCRIPTION_METADATA for use in virDomainSetDescription would do the trick, rather than adding yet another API. [1]https://www.redhat.com/archives/libvir-list/2012-January/msg00709.html
I'm not really convinced we need an API for setting the title/description either. Are we going to create APIs for setting every little attribute of the XML ? IMHO that's the job for libvirt-gconfig.
I think we still need a way to set title/description/... without the need to call virDomainDefine. Going through complete XML and virDomainDefine changes the configuration that will be used when a domain is started next time. For things that can be changed in runtime, we also provide APIs to do that, e.g., device addition/removal/update, ... Metadata may also be changed in runtime and I believe we should have some API(s) that would allow apps to do so. Jirka

On Fri, Jan 20, 2012 at 02:55:27PM -0700, Eric Blake wrote:
On 01/20/2012 01:15 PM, Zeeshan Ali (Khattak) wrote:
From 6895c107970ea6daf3d0e7f8be9a1a4e97b2278b Mon Sep 17 00:00:00 2001 From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> Date: Fri, 20 Jan 2012 21:50:35 +0200 Subject: [PATCH] Allow custom metadata in domain configuration XML
Applications can now insert custom nodes and hierarchies into domain cofiguration XML. Although currently not enforced, application are required to use their own namespaces on every custom node they insert.
Looks like an interesting idea, as it gives applications more structure than what they would get by overloading the free-form <description>.
--- docs/formatdomain.html.in | 18 ++++++++++++++++++ src/conf/domain_conf.c | 21 +++++++++++++++++++++ src/conf/domain_conf.h | 3 +++
Hmm, you didn't update docs/schemas/domaincommon.rng. But how do you write a schema that accepts a <metadata> element with arbitrary contents? </me searches the web...>
http://www.oasis-open.org/committees/relax-ng/tutorial.html#IDAFLZR
<define name="anyElement"> <element> <anyName/> <zeroOrMore> <choice> <attribute> <anyName/> </attribute> <text/> <ref name="anyElement"/> </choice> </zeroOrMore> </element> </define>
<define name='metadata'> <element name='metadata'> <choice> <text/> <zeroOrMore> <ref name='anyElement'/> </zeroOrMore> </choice> </element> </define>
Yes, that looks fine.
+ <dl> + <dt><code>metadata</code></dt> + <dd><code>metadata</code> node could be used by applications to + store custom metadata in the form of XML nodes/trees. Applications + must use custom namespaces on any XML nodes they insert here. + <span class="since">Since 0.9.9</span></dd>
0.9.10.
@@ -11833,6 +11841,19 @@ virDomainDefFormatInternal(virDomainDefPtr def, goto cleanup; }
+ /* Custom metadata comes at the end */ + if (def->metadata) { + xmlBufferPtr xmlbuf; + + xmlbuf = xmlBufferCreate(); + if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata, 2, 0) < 0) {
Is this the right level of indentation if buf itself already has indentation (such as when <domain> is nested inside <domainsnapshot>? You may need to use virBufferGetIndent() and use that to alter the fourth argument to xmlNodeDump accordingly.
Unless anyone else objects to this XML addition, I think it is probably okay; but I have a couple caveats:
FYI this XML design is something I suggested to the Boxes team, instead of hijacking the user's <description> field, so obviously it gets my vote. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (4)
-
Daniel P. Berrange
-
Eric Blake
-
Jiri Denemark
-
Zeeshan Ali (Khattak)