xmlapi: Rework xmlns setting slightly

So the xmlns is not always set on the top element. We need this for
custom <metadata> support
This commit is contained in:
Cole Robinson 2018-09-13 10:33:08 -04:00
parent 841d5126d2
commit baaab74b6d
3 changed files with 17 additions and 18 deletions

View File

@ -1,4 +1,4 @@
<domain xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0" type="kvm">
<domain type="kvm">
<name>foobar</name>
<uuid>00000000-1111-2222-3333-444444444444</uuid>
<memory>65536</memory>
@ -400,7 +400,7 @@
<address iobase="507" type="isa"/>
</panic>
</devices>
<qemu:commandline>
<qemu:commandline xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0">
<qemu:arg value="-display"/>
<qemu:arg value="gtk,gl=on"/>
<qemu:arg value="-device"/>

View File

@ -1,13 +1,7 @@
-<domain type="test">
+<domain xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0" type="test">
<name>test-for-virtxml</name>
<uuid>12345678-12f4-1234-1234-123456789012</uuid>
<description>Test VM for virtxml cli tests
@@
</panic>
</devices>
<seclabel type="dynamic" model="selinux" relabel="yes"/>
+ <qemu:commandline>
+ <qemu:commandline xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0">
+ <qemu:arg value="-foo"/>
+ <qemu:arg value="bar,baz=wib wob"/>
+ </qemu:commandline>

View File

@ -97,7 +97,7 @@ class _XMLBase(object):
raise NotImplementedError()
def _node_set_property(self, node, propname, setval):
raise NotImplementedError()
def _node_new(self, xpathseg):
def _node_new(self, xpathseg, parentnode):
raise NotImplementedError()
def _node_add_child(self, parentxpath, parentnode, newnode):
raise NotImplementedError()
@ -212,7 +212,7 @@ class _XMLBase(object):
parentnode = tmpnode
continue
newnode = self._node_new(xpathseg)
newnode = self._node_new(xpathseg, parentnode)
self._node_add_child(oldxpath, parentnode, newnode)
parentnode = newnode
@ -307,17 +307,22 @@ class _Libxml2API(_XMLBase):
else:
node.setProp(propname, util.xml_escape(setval))
def _node_new(self, xpathseg):
def _node_new(self, xpathseg, parentnode):
newnode = libxml2.newNode(xpathseg.nodename)
if not xpathseg.nsname:
return newnode
ctxnode = self._ctx.contextNode()
for ns in util.listify(ctxnode.nsDefs()):
if ns.name == xpathseg.nsname:
break
else:
ns = ctxnode.newNs(
def _find_parent_ns():
parent = parentnode
while parent:
for ns in util.listify(parent.nsDefs()):
if ns.name == xpathseg.nsname:
return ns
parent = parent.get_parent()
ns = _find_parent_ns()
if not ns:
ns = newnode.newNs(
self.NAMESPACES[xpathseg.nsname], xpathseg.nsname)
newnode.setNs(ns)
return newnode