1
# Copyright 2014-2015 Canonical Limited.
3
# This file is part of charm-helpers.
5
# charm-helpers is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU Lesser General Public License version 3 as
7
# published by the Free Software Foundation.
9
# charm-helpers is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU Lesser General Public License for more details.
14
# You should have received a copy of the GNU Lesser General Public License
15
# along with charm-helpers. If not, see <http://www.gnu.org/licenses/>.
17
from subprocess import (
26
##################################################
28
##################################################
29
def deactivate_lvm_volume_group(block_device):
31
Deactivate any volume gruop associated with an LVM physical volume.
33
:param block_device: str: Full path to LVM physical volume
35
vg = list_lvm_volume_group(block_device)
37
cmd = ['vgchange', '-an', vg]
41
def is_lvm_physical_volume(block_device):
43
Determine whether a block device is initialized as an LVM PV.
45
:param block_device: str: Full path of block device to inspect.
47
:returns: boolean: True if block device is a PV, False if not.
50
check_output(['pvdisplay', block_device])
52
except CalledProcessError:
56
def remove_lvm_physical_volume(block_device):
58
Remove LVM PV signatures from a given block device.
60
:param block_device: str: Full path of block device to scrub.
62
p = Popen(['pvremove', '-ff', block_device],
64
p.communicate(input='y\n')
67
def list_lvm_volume_group(block_device):
69
List LVM volume group associated with a given block device.
71
Assumes block device is a valid LVM PV.
73
:param block_device: str: Full path of block device to inspect.
75
:returns: str: Name of volume group associated with block device or None
78
pvd = check_output(['pvdisplay', block_device]).splitlines()
81
if l.strip().startswith('VG Name'):
82
vg = ' '.join(l.strip().split()[2:])
86
def create_lvm_physical_volume(block_device):
88
Initialize a block device as an LVM physical volume.
90
:param block_device: str: Full path of block device to initialize.
93
check_call(['pvcreate', block_device])
96
def create_lvm_volume_group(volume_group, block_device):
98
Create an LVM volume group backed by a given block device.
100
Assumes block device has already been initialized as an LVM PV.
102
:param volume_group: str: Name of volume group to create.
103
:block_device: str: Full path of PV-initialized block device.
105
check_call(['vgcreate', volume_group, block_device])