Nir Soffer has uploaded a new change for review. Change subject: virt: Extract Drive.diskType property ......................................................................
virt: Extract Drive.diskType property This is the first step in breaking getXML() to separate methods for rendering individual elements, required to create replica disk xml without code duplication. The diskType property is also required for Ceph support, where it will be sent from the engine. This property helps the rest of the code to work in the same way if diskType was sent from the engine (new engine) or deduced from blockDev and networkDev properties (old engine). Change-Id: Iec13ca58ee4f3db919198bdeae781473a97e072d Signed-off-by: Nir Soffer <[email protected]> --- M vdsm/virt/vmdevices/storage.py 1 file changed, 24 insertions(+), 9 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/62/40062/1 diff --git a/vdsm/virt/vmdevices/storage.py b/vdsm/virt/vmdevices/storage.py index 82642d3..12625f1 100644 --- a/vdsm/virt/vmdevices/storage.py +++ b/vdsm/virt/vmdevices/storage.py @@ -27,6 +27,12 @@ from .core import Base +class DISK_TYPE: + BLOCK = "block" + NETWORK = "network" + FILE = "file" + + class DRIVE_SHARED_TYPE: NONE = "none" EXCLUSIVE = "exclusive" @@ -176,7 +182,7 @@ @property def networkDev(self): try: - return self.volumeInfo['volType'] == "network" + return self.volumeInfo['volType'] == DISK_TYPE.NETWORK except AttributeError: # To handle legacy and removable drives. return False @@ -207,6 +213,15 @@ # invalidating cached blockDev. self._blockDev = None self._path = path + + @property + def diskType(self): + if self.blockDev: + return DISK_TYPE.BLOCK + elif self.networkDev: + return DISK_TYPE.NETWORK + else: + return DISK_TYPE.FILE @property def transientDisk(self): @@ -310,24 +325,24 @@ self.device = getattr(self, 'device', 'disk') source = vmxml.Element('source') - if self.blockDev: - deviceType = 'block' + if self.diskType == DISK_TYPE.BLOCK: source.setAttrs(dev=self.path) - elif self.networkDev: - deviceType = 'network' + elif self.diskType == DISK_TYPE.NETWORK: source.setAttrs(protocol=self.volumeInfo['protocol'], name=self.volumeInfo['path']) hostAttrs = {'name': self.volumeInfo['volfileServer'], 'port': self.volumeInfo['volPort'], 'transport': self.volumeInfo['volTransport']} source.appendChildWithArgs('host', **hostAttrs) - else: - deviceType = 'file' - sourceAttrs = {'file': self.path} + elif self.diskType == DISK_TYPE.FILE: + sourceAttrs = {DISK_TYPE.FILE: self.path} if self.device == 'cdrom' or self.device == 'floppy': sourceAttrs['startupPolicy'] = 'optional' source.setAttrs(**sourceAttrs) - diskelem = self.createXmlElem('disk', deviceType, + else: + raise RuntimeError("Unsupported diskType %r", self.diskType) + + diskelem = self.createXmlElem('disk', self.diskType, ['device', 'address', 'sgio']) diskelem.setAttrs(snapshot='no') diskelem.appendChild(source) -- To view, visit https://gerrit.ovirt.org/40062 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iec13ca58ee4f3db919198bdeae781473a97e072d Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Nir Soffer <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
