Move nbd modprobe check into separate function

Only require max_part param for partition manifests
This commit is contained in:
Anders Ingemann 2013-10-04 20:31:51 +02:00
parent 8891a18e4b
commit ba1842ca2b

View file

@ -12,7 +12,13 @@ class VirtualBoxVolume(LoopbackVolume):
self.image_path = e.image_path
log_check_call(['/usr/bin/qemu-img', 'create', '-f', 'vdi', self.image_path, str(self.size) + 'M'])
def _before_attach(self, e):
def _check_nbd_module(self):
from base.fs.partitionmaps.none import NoPartitions
if isinstance(self.partition_map, NoPartitions):
if not self._module_loaded('nbd'):
raise VolumeError('The kernel module `nbd\' must be loaded '
'(`modprobe nbd\') to attach .vdi images')
else:
num_partitions = len(self.partition_map.partitions)
if not self._module_loaded('nbd'):
msg = ('The kernel module `nbd\' must be loaded '
@ -29,6 +35,9 @@ class VirtualBoxVolume(LoopbackVolume):
'(`rmmod nbd; modprobe nbd max_part={num_partitions}\').'
.format(max_part=nbd_max_part, num_partitions=num_partitions))
raise VolumeError(msg)
def _before_attach(self, e):
self._check_nbd_module()
self.loop_device_path = self._find_free_nbd_device()
log_check_call(['/usr/bin/qemu-nbd', '--connect', self.loop_device_path, self.image_path])
self.device_path = self.loop_device_path