File: logicalvolume.py

package info (click to toggle)
bootstrap-vz 0.9.11%2B20180121git-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,244 kB
  • sloc: python: 8,800; sh: 813; makefile: 16
file content (38 lines) | stat: -rw-r--r-- 1,388 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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