Arik Hadas has uploaded a new change for review. Change subject: [WIP] use libvirt domain xml prepared in advance ......................................................................
[WIP] use libvirt domain xml prepared in advance Change-Id: I469fad3ca14a6b7f4675ef5c200175053f6dd4af Signed-off-by: Arik Hadas <aha...@redhat.com> --- M vdsm/virt/vmxml.py 1 file changed, 30 insertions(+), 8 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/82/65182/1 diff --git a/vdsm/virt/vmxml.py b/vdsm/virt/vmxml.py index b868a25..ee1a381 100644 --- a/vdsm/virt/vmxml.py +++ b/vdsm/virt/vmxml.py @@ -22,6 +22,7 @@ import xml.dom import xml.dom.minidom import xml.etree.ElementTree as etree +from xml.dom.minidom import parseString as _domParseStr from vdsm import constants from vdsm import cpuarch @@ -113,8 +114,11 @@ class Element(object): - def __init__(self, tagName, text=None, namespaceUri=None, **attrs): - if namespaceUri is not None: + def __init__(self, tagName, text=None, namespaceUri=None, elem=None, + **attrs): + if elem is not None: + self._elem = elem + elif namespaceUri is not None: self._elem = xml.dom.minidom.Document().createElementNS( namespaceUri, tagName) else: @@ -149,6 +153,29 @@ class Domain(object): def __init__(self, conf, log, arch): + self.conf = conf + self.log = log + + self.arch = arch + + if ('xml' in self.conf): + self._parseDomainXml() + else: + self._buildSkeleton() + + + def _parseDomainXml(self): + """ + Parse given libvirt domain xml + """ + self.doc = _domParseStr(self.conf['xml']) + domainElement = self.doc.getElementsByTagName('domain')[0] + self.dom = Element(None, elem=domainElement) + devicesElement = self.doc.childNodes[0].\ + getElementsByTagName('devices')[0] + self._devices = Element(None, elem=devicesElement) + + def _buildSkeleton(self): """ Create the skeleton of a libvirt domain xml @@ -163,13 +190,7 @@ </domain> """ - self.conf = conf - self.log = log - - self.arch = arch - self.doc = xml.dom.minidom.Document() - if utils.tobool(self.conf.get('kvmEnable', 'true')): domainType = 'kvm' else: @@ -200,6 +221,7 @@ self.dom.appendChild(self._devices) self.appendMetadata() + self.doc.appendChild(self.dom) def appendClock(self): """ -- To view, visit https://gerrit.ovirt.org/65182 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I469fad3ca14a6b7f4675ef5c200175053f6dd4af Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Arik Hadas <aha...@redhat.com> _______________________________________________ vdsm-patches mailing list -- vdsm-patches@lists.fedorahosted.org To unsubscribe send an email to vdsm-patches-le...@lists.fedorahosted.org