Martin Polednik has uploaded a new change for review.
Change subject: vmdevices: move storage methods to storage module
......................................................................
vmdevices: move storage methods to storage module
Some of the methods found in VM class are heavily related to
legacy configuration parsing for storage. These can be safely moved to
storage module, reducing VM class polution and contributing to a better
code.
Change-Id: Ie7b2db4ba7569ff0170a948b2954064c99c804a0
Signed-off-by: Martin Polednik <mpolednik(a)redhat.com>
---
M vdsm/virt/vm.py
M vdsm/virt/vmdevices/storage.py
2 files changed, 66 insertions(+), 62 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/33/40133/1
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 8dabd9b..901537d 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -799,40 +799,6 @@
drv['truesize'] = 0
drv['apparentsize'] = 0
- def __legacyDrives(self):
- """
- Backward compatibility for qa scripts that specify direct paths.
- """
- legacies = []
- DEVICE_SPEC = ((0, 'hda'), (1, 'hdb'), (2, 'hdc'), (3,
'hdd'))
- for index, linuxName in DEVICE_SPEC:
- path = self.conf.get(linuxName)
- if path:
- legacies.append({'type': hwclass.DISK,
- 'device': 'disk', 'path': path,
- 'iface': 'ide', 'index': index,
- 'truesize': 0})
- return legacies
-
- def __removableDrives(self):
- removables = [{
- 'type': hwclass.DISK,
- 'device': 'cdrom',
- 'iface': vmdevices.storage.DEFAULT_INTERFACE_FOR_ARCH[self.arch],
- 'path': self.conf.get('cdrom', ''),
- 'index': 2,
- 'truesize': 0}]
- floppyPath = self.conf.get('floppy')
- if floppyPath:
- removables.append({
- 'type': hwclass.DISK,
- 'device': 'floppy',
- 'path': floppyPath,
- 'iface': 'fdc',
- 'index': 0,
- 'truesize': 0})
- return removables
-
def buildConfDevices(self):
"""
Return the "devices" section of this Vm's conf.
@@ -851,7 +817,9 @@
devConf = utils.picklecopy(self.conf['devices'])
except KeyError:
# (very) old Engines do not send device configuration
- devices[hwclass.DISK] = self.getConfDrives()
+ devices[hwclass.DISK] = \
+ vmdevices.storage.mapping_from_legacy_conf(self.conf,
+ self.arch)
devices[hwclass.NIC] = self.getConfNetworkInterfaces()
devices[hwclass.SOUND] = self.getConfSound()
devices[hwclass.VIDEO] = self.getConfVideo()
@@ -1007,33 +975,6 @@
'nicModel': model, 'network': bridge,
'device': 'bridge'})
return nics
-
- def getConfDrives(self):
- """
- Normalize drives provided by conf.
- """
- # FIXME
- # Will be better to change the self.conf but this implies an API change
- # Remove this when the API parameters will be consistent.
- confDrives = self.conf.get('drives', [])
- if not confDrives:
- confDrives.extend(self.__legacyDrives())
- confDrives.extend(self.__removableDrives())
-
- for drv in confDrives:
- drv['type'] = hwclass.DISK
- drv['format'] = drv.get('format') or 'raw'
- drv['propagateErrors'] = drv.get('propagateErrors') or
'off'
- drv['readonly'] = False
- drv['shared'] = False
- # FIXME: For BC we have now two identical keys: iface = if
- # Till the day that conf will not returned as a status anymore.
- drv['iface'] = drv.get('iface') or \
- drv.get(
- 'if',
- vmdevices.storage.DEFAULT_INTERFACE_FOR_ARCH[self.arch])
-
- return confDrives
def updateDriveIndex(self, drv):
if not drv['iface'] in self._usedIndices:
diff --git a/vdsm/virt/vmdevices/storage.py b/vdsm/virt/vmdevices/storage.py
index 19531d8..1b91991 100644
--- a/vdsm/virt/vmdevices/storage.py
+++ b/vdsm/virt/vmdevices/storage.py
@@ -27,6 +27,7 @@
from .. import vmxml
from .core import Base
+from . import hwclass
DEFAULT_INTERFACE_FOR_ARCH = {caps.Architecture.X86_64: 'ide',
caps.Architecture.PPC64: 'scsi',
@@ -45,6 +46,68 @@
return (cls.NONE, cls.EXCLUSIVE, cls.SHARED, cls.TRANSIENT)
+def mapping_from_legacy_conf(conf, arch):
+ """
+ Returns a list of drive specification dictionaries from legacy vm.conf
+ """
+ conf_drives = conf.get('drives', [])
+ if not conf_drives:
+ conf_drives.extend(__mapping_from_legacy_direct_paths(conf))
+ conf_drives.extend(__mapping_from_legacy_removable_drives(conf, arch))
+
+ for drive in conf_drives:
+ drive['type'] = hwclass.DISK
+ drive['format'] = drive.get('format') or 'raw'
+ drive['propagateErrors'] = drive.get('propagateErrors') or
'off'
+ drive['readonly'] = False
+ drive['shared'] = False
+ # FIXME: For BC we have now two identical keys: iface = if
+ # Till the day that conf will not returned as a status anymore.
+ drive['iface'] = drive.get('iface') or \
+ drive.get('if', DEFAULT_INTERFACE_FOR_ARCH[arch])
+
+ return conf_drives
+
+
+def __mapping_from_legacy_direct_paths(conf):
+ """
+ Backward compatibility for qa scripts that specify direct paths.
+ """
+ legacies = []
+ device_spec = ((0, 'hda'), (1, 'hdb'), (2, 'hdc'), (3,
'hdd'))
+ for index, linux_name in device_spec:
+ path = conf.get(linux_name)
+ if path:
+ legacies.append({'type': hwclass.DISK,
+ 'device': 'disk', 'path': path,
+ 'iface': 'ide', 'index': index,
+ 'truesize': 0})
+ return legacies
+
+
+def __mapping_from_legacy_removable_drives(conf, arch):
+ removables = [{
+ 'type': hwclass.DISK,
+ 'device': 'cdrom',
+ 'iface': DEFAULT_INTERFACE_FOR_ARCH[arch],
+ 'path': conf.get('cdrom', ''),
+ 'index': 2,
+ 'truesize': 0}]
+
+ floppy_path = conf.get('floppy')
+
+ if floppy_path:
+ removables.append({
+ 'type': hwclass.DISK,
+ 'device': 'floppy',
+ 'path': floppy_path,
+ 'iface': 'fdc',
+ 'index': 0,
+ 'truesize': 0})
+
+ return removables
+
+
class Drive(Base):
__slots__ = ('iface', '_path', 'readonly',
'bootOrder', 'domainID',
'poolID', 'imageID', 'UUID', 'volumeID',
'format',
--
To view, visit
https://gerrit.ovirt.org/40133
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie7b2db4ba7569ff0170a948b2954064c99c804a0
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Martin Polednik <mpolednik(a)redhat.com>