On 04/25/2014 08:11 AM, Sheldon wrote:
+def set_vm_metadata_element(dom, meta_xml, mode="all"):
+ element = etree.fromstring(meta_xml)
+ # From libvirt doc, Passing None for @metadata says to remove that element
+ # from the domain XML (passing the empty string leaves the element present)
+ # Do not support remove the old metadata
+ dom.setMetadata(libvirt.VIR_DOMAIN_METADATA_ELEMENT, meta_xml,
+ "kimchi", KIMCHI_META_URL + element.tag,

Why are you append element.tag to namespace? Use only https://github.com/kimchi-project/kimchi/ as namespace
If we don not like it. I change it next version.

The reason as follow

as libvirt docs(http://libvirt.org/formatdomain.html#elementsMetadata) says:
<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="http://app1.org/app1/">..</app1:foo>
    <app2:bar xmlns:app2="http://app1.org/app2/">..</app2:bar>
  </metadata>
  ...
metadata



yes, one application use one namespace.

append element.tag to namespace, make every "kimchi" element has an unique uri.
this looks like all the "kimchi" prefix element are belong to one "kimchi" application.
looks like "foo" are "bar" are all "kimchi", but they has different xmlns.
  <metadata>
    <kimchi:foo xmlns:kimchi="http://kimchi.org/kimchi/foo">..</kimchi:foo>
    <kimchi:bar xmlns:kimchi="http://kimchi.org/kimchi/bar">..</kimchi:bar>
  </metadata>

The libvirt API can easy to set/get the every metadata element.
get foo by: virDomain.metadata(@type, "https://kimchi.org/kimchi/foo/")
get bar by: virDomain.metadata(@type, "https://kimchi.org/kimchi/bar/")

set foo by: virDomain.setMetadata(@type, "<foo></foo>", "https://kimchi.org/kimchi/foo/")
set bar by: virDomain.setMetadata(@type, "<bar></bar>", "https://kimchi.org/kimchi/bar/")

looks like foo and bar belong to "kimchi" element, but they are independent.  
Their is no relationship between them.
If we just want to handle foo, we do not need to care "bar".

like we can call kimchi api, every api is unique uri. every api are independent.



virDomain.metadata
Type:       instancemethod
String Form:<unbound method virDomain.metadata>
File:       /usr/lib64/python2.7/site-packages/libvirt.py
Definition: libvirt.virDomain.metadata(self, type, uri, flags=0)
Docstring:
Retrieves the appropriate domain element given by @type.
If VIR_DOMAIN_METADATA_ELEMENT is requested parameter @uri
must be set to the name of the namespace the requested elements
belong to, otherwise must be None.

If an element of the domain XML is not present, the resulting
error will be VIR_ERR_NO_DOMAIN_METADATA.  This method forms
a shortcut for seeing information from virDomainSetMetadata()
without having to go through virDomainGetXMLDesc().

@flags controls whether the live domain or persistent
configuration will be queried.
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


-- 
Thanks and best regards!

Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com>
IBM Linux Technology Center