1
from subprocess import (
10
##################################################
12
##################################################
13
def deactivate_lvm_volume_group(block_device):
15
Deactivate any volume gruop associated with an LVM physical volume.
17
:param block_device: str: Full path to LVM physical volume
19
vg = list_lvm_volume_group(block_device)
21
cmd = ['vgchange', '-an', vg]
25
def is_lvm_physical_volume(block_device):
27
Determine whether a block device is initialized as an LVM PV.
29
:param block_device: str: Full path of block device to inspect.
31
:returns: boolean: True if block device is a PV, False if not.
34
check_output(['pvdisplay', block_device])
36
except CalledProcessError:
40
def remove_lvm_physical_volume(block_device):
42
Remove LVM PV signatures from a given block device.
44
:param block_device: str: Full path of block device to scrub.
46
p = Popen(['pvremove', '-ff', block_device],
48
p.communicate(input='y\n')
51
def list_lvm_volume_group(block_device):
53
List LVM volume group associated with a given block device.
55
Assumes block device is a valid LVM PV.
57
:param block_device: str: Full path of block device to inspect.
59
:returns: str: Name of volume group associated with block device or None
62
pvd = check_output(['pvdisplay', block_device]).splitlines()
64
if l.strip().startswith('VG Name'):
65
vg = ' '.join(l.split()).split(' ').pop()
69
def create_lvm_physical_volume(block_device):
71
Initialize a block device as an LVM physical volume.
73
:param block_device: str: Full path of block device to initialize.
76
check_call(['pvcreate', block_device])
79
def create_lvm_volume_group(volume_group, block_device):
81
Create an LVM volume group backed by a given block device.
83
Assumes block device has already been initialized as an LVM PV.
85
:param volume_group: str: Name of volume group to create.
86
:block_device: str: Full path of PV-initialized block device.
88
check_call(['vgcreate', volume_group, block_device])