mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-22 09:50:37 +00:00

Enables the use of Logical Volumes as disk backends. It uses an existing volume group and has no support for creating a new one. It will not override an existing logical volume and fail gracefully. The lv is created, activated and then mounted as a loop device. The boostraping process is then launched on the loop device. Once the process is completed, the lv is unmounted and desactivated. The created lv will be deleted should the boostraping process fail. The lv must be activated before use. A manifest has been included for testing purposes.
38 lines
1.4 KiB
Python
38 lines
1.4 KiB
Python
from bootstrapvz.base.fs.volume import Volume
|
|
from bootstrapvz.common.tools import log_check_call
|
|
import os
|
|
|
|
|
|
class LogicalVolume(Volume):
|
|
|
|
def __init__(self, partitionmap):
|
|
super(LogicalVolume, self).__init__(partitionmap)
|
|
self.vg = ''
|
|
self.lv = ''
|
|
|
|
def create(self, volumegroup, logicalvolume):
|
|
self.vg = volumegroup
|
|
self.lv = logicalvolume
|
|
image_path = os.path.join(os.sep, 'dev', self.vg, self.lv)
|
|
self.fsm.create(image_path=image_path)
|
|
|
|
def _before_create(self, e):
|
|
self.image_path = e.image_path
|
|
lv_size = str(self.size.bytes.get_qty_in('MiB'))
|
|
log_check_call(['lvcreate', '--size', '{mib}M'.format(mib=lv_size),
|
|
'--name', self.lv, self.vg])
|
|
|
|
def _before_attach(self, e):
|
|
log_check_call(['lvchange', '--activate', 'y', self.image_path])
|
|
[self.loop_device_path] = log_check_call(['losetup', '--show', '--find', '--partscan', self.image_path])
|
|
self.device_path = self.loop_device_path
|
|
|
|
def _before_detach(self, e):
|
|
log_check_call(['losetup', '--detach', self.loop_device_path])
|
|
log_check_call(['lvchange', '--activate', 'n', self.image_path])
|
|
del self.loop_device_path
|
|
self.device_path = None
|
|
|
|
def delete(self):
|
|
log_check_call(['lvremove', '-f', self.image_path])
|
|
del self.image_path
|