<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 04/25/2014 08:11 AM, Sheldon wrote:<br>
</div>
<blockquote cite="mid:5359A81D.4030401@linux.vnet.ibm.com"
type="cite">
<blockquote type="cite" style="color: #000000;">+def
set_vm_metadata_element(dom, meta_xml, mode="all"):
<br>
+ element = etree.fromstring(meta_xml)
<br>
+ # From libvirt doc, Passing None for @metadata says to remove
that element
<br>
+ # from the domain XML (passing the empty string leaves the
element present)
<br>
+ # Do not support remove the old metadata
<br>
+ dom.setMetadata(libvirt.VIR_DOMAIN_METADATA_ELEMENT, meta_xml,
<br>
+ "kimchi", KIMCHI_META_URL + element.tag,
<br>
</blockquote>
<br>
Why are you append element.tag to namespace? Use only <a
moz-do-not-send="true" class="moz-txt-link-freetext"
href="https://github.com/kimchi-project/kimchi/">https://github.com/kimchi-project/kimchi/</a>
as namespace
</blockquote>
If we don not like it. I change it next version. <br>
<br>
The reason as follow<br>
<br>
as libvirt
docs(<a class="moz-txt-link-freetext" href="http://libvirt.org/formatdomain.html#elementsMetadata">http://libvirt.org/formatdomain.html#elementsMetadata</a>) says: <br>
<pre xml:space="preserve" style="border: 1px solid rgb(153, 153, 153); background-color: rgb(238, 238, 238); color: rgb(0, 0, 0); padding: 1em; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-position: initial initial; background-repeat: initial initial;"><domain type='xen' id='3'>
<name>fv0</name>
<uuid>4dea22b31d52d8f32516782e98ab3fa0</uuid>
<title>A short description - title - of the domain</title>
<description>Some human readable description</description>
<metadata>
<app1:foo xmlns:app1=<a class="moz-txt-link-rfc2396E" href="http://app1.org/app1/">"http://app1.org/app1/"</a>>..</app1:foo>
<app2:bar xmlns:app2=<a class="moz-txt-link-rfc2396E" href="http://app1.org/app2/">"http://app1.org/app2/"</a>>..</app2:bar>
</metadata>
...</pre>
<dt style="margin-left: 1em; margin-right: 2em; color: rgb(0, 0, 0);
font-family: Verdana, Arial, Helvetica, sans-serif; font-size:
13px; font-style: normal; font-variant: normal; font-weight:
normal; letter-spacing: normal; line-height: normal; orphans:
auto; text-align: start; text-indent: 0px; text-transform: none;
white-space: normal; widows: auto; word-spacing: 0px;
-webkit-text-stroke-width: 0px; background-color: rgb(255, 255,
255);"><code>metadata</code></dt>
<br>
<br>
<br>
yes, one application use one namespace. <br>
<br>
append element.tag to namespace, make every "kimchi" element has an
unique uri.<br>
this looks like all the "kimchi" prefix element are belong to one
"kimchi" application.<br>
looks like "foo" are "bar" are all "kimchi", but they has different
xmlns.<br>
<pre xml:space="preserve" style="border: 1px solid rgb(153, 153, 153); background-color: rgb(238, 238, 238); color: rgb(0, 0, 0); padding: 1em; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-position: initial initial; background-repeat: initial initial;"> <metadata>
<kimchi:foo xmlns:kimchi=<a class="moz-txt-link-rfc2396E" href="http://kimchi.org/kimchi/foo">"http://kimchi.org/kimchi/foo"</a>>..</kimchi:foo>
<kimchi:bar xmlns:kimchi=<a class="moz-txt-link-rfc2396E" href="http://kimchi.org/kimchi/bar">"http://kimchi.org/kimchi/bar"</a>>..</kimchi:bar>
</metadata></pre>
<br>
The libvirt API can easy to set/get the every metadata element. <br>
get foo by: virDomain.metadata(@type,
<a class="moz-txt-link-rfc2396E" href="https://kimchi.org/kimchi/foo/">"https://kimchi.org/kimchi/foo/"</a>)<br>
get bar by: virDomain.metadata(@type,
<a class="moz-txt-link-rfc2396E" href="https://kimchi.org/kimchi/bar/">"https://kimchi.org/kimchi/bar/"</a>)<br>
<br>
set foo by: virDomain.setMetadata(@type, "<foo></foo>",
<a class="moz-txt-link-rfc2396E" href="https://kimchi.org/kimchi/foo/">"https://kimchi.org/kimchi/foo/"</a>)<br>
set bar by: virDomain.setMetadata(@type, "<bar></bar>",
<a class="moz-txt-link-rfc2396E" href="https://kimchi.org/kimchi/bar/">"https://kimchi.org/kimchi/bar/"</a>)<br>
<br>
looks like foo and bar belong to "kimchi" element, but they are
independent. <br>
Their is no relationship between them. <br>
If we just want to handle foo, we do not need to care "bar". <br>
<br>
like we can call kimchi api, every api is unique uri. every api are
independent.<br>
<br>
<br>
<br>
virDomain.metadata<br>
Type: instancemethod<br>
String Form:<unbound method virDomain.metadata><br>
File: /usr/lib64/python2.7/site-packages/libvirt.py<br>
Definition: libvirt.virDomain.metadata(self, type, uri, flags=0)<br>
Docstring:<br>
Retrieves the appropriate domain element given by @type.<br>
If VIR_DOMAIN_METADATA_ELEMENT is requested parameter @uri<br>
must be set to the name of the namespace the requested elements<br>
belong to, otherwise must be None.<br>
<br>
If an element of the domain XML is not present, the resulting<br>
error will be VIR_ERR_NO_DOMAIN_METADATA. This method forms<br>
a shortcut for seeing information from virDomainSetMetadata()<br>
without having to go through virDomainGetXMLDesc().<br>
<br>
@flags controls whether the live domain or persistent<br>
configuration will be queried. <br>
<dd style="margin-left: 2em; margin-right: 2em; margin-bottom:
0.5em; color: rgb(0, 0, 0); font-family: Verdana, Arial,
Helvetica, sans-serif; font-size: 13px; font-style: normal;
font-variant: normal; font-weight: normal; letter-spacing: normal;
line-height: normal; orphans: auto; text-align: start;
text-indent: 0px; text-transform: none; white-space: normal;
widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;
background-color: rgb(255, 255, 255);">The<span
class="Apple-converted-space"> </span><code>metadata</code><span
class="Apple-converted-space"> </span>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="Apple-converted-space"> </span><span
class="since" style="color: rgb(60, 133, 124); font-style:
italic; font-weight: bold;">Since 0.9.10</span></dd>
<br>
<br>
<pre class="moz-signature" cols="72">--
Thanks and best regards!
Sheldon Feng(冯少合)<a class="moz-txt-link-rfc2396E" href="mailto:shaohef@linux.vnet.ibm.com"><shaohef@linux.vnet.ibm.com></a>
IBM Linux Technology Center</pre>
</body>
</html>