import itertools
import math
+import os
import re
import time
class LVM(executor.Executor):
"""LVM object to enable various LVM related operations."""
+ LVM_CMD_PREFIX = ['env', 'LC_ALL=C']
def __init__(self, vg_name, root_helper, create_vg=False,
physical_volumes=None, lvm_type='default',
- executor=putils.execute):
+ executor=putils.execute, lvm_conf=None):
"""Initialize the LVM object.
self.activate_lv(self.vg_thin_pool)
self.pv_list = self.get_all_physical_volumes(root_helper, vg_name)
+ if lvm_conf and os.path.isfile(lvm_conf):
+ LVM.LVM_CMD_PREFIX = ['env',
+ 'LC_ALL=C',
+ 'LVM_SYSTEM_DIR=/etc/cinder']
def _vg_exists(self):
"""Simple check to see if VG exists.
"""
exists = False
- (out, _err) = self._execute(
- 'env', 'LC_ALL=C', 'vgs', '--noheadings', '-o', 'name',
- self.vg_name, root_helper=self._root_helper, run_as_root=True)
+ cmd = LVM.LVM_CMD_PREFIX + ['vgs', '--noheadings',
+ '-o', 'name', self.vg_name]
+ (out, _err) = self._execute(*cmd,
+ root_helper=self._root_helper,
+ run_as_root=True)
if out is not None:
volume_groups = out.split()
self._execute(*cmd, root_helper=self._root_helper, run_as_root=True)
def _get_vg_uuid(self):
- (out, _err) = self._execute('env', 'LC_ALL=C', 'vgs', '--noheadings',
- '-o uuid', self.vg_name)
+ cmd = LVM.LVM_CMD_PREFIX + ['vgs', '--noheadings',
+ '-o', 'uuid', self.vg_name]
+ (out, _err) = self._execute(*cmd,
+ root_helper=self._root_helper,
+ run_as_root=True)
if out is not None:
return out.split()
else:
:returns: Free space in GB (float), calculated using data_percent
"""
- cmd = ['env', 'LC_ALL=C', 'lvs', '--noheadings', '--unit=g',
- '-o', 'size,data_percent', '--separator', ':', '--nosuffix']
-
+ cmd = LVM.LVM_CMD_PREFIX +\
+ ['lvs', '--noheadings', '--unit=g',
+ '-o', 'size,data_percent', '--separator',
+ ':', '--nosuffix']
# NOTE(gfidente): data_percent only applies to some types of LV so we
# make sure to append the actual thin pool name
cmd.append("/dev/%s/%s" % (vg_name, thin_pool_name))
"""
- cmd = ['env', 'LC_ALL=C', 'vgs', '--version']
+ cmd = LVM.LVM_CMD_PREFIX + ['vgs', '--version']
(out, _err) = putils.execute(*cmd,
root_helper=root_helper,
run_as_root=True)
"""
- cmd = ['env', 'LC_ALL=C', 'lvs', '--noheadings', '--unit=g',
- '-o', 'vg_name,name,size', '--nosuffix']
-
+ cmd = LVM.LVM_CMD_PREFIX + ['lvs', '--noheadings', '--unit=g',
+ '-o', 'vg_name,name,size', '--nosuffix']
if lv_name is not None and vg_name is not None:
cmd.append("%s/%s" % (vg_name, lv_name))
elif vg_name is not None:
"""
field_sep = '|'
-
- cmd = ['env', 'LC_ALL=C', 'pvs', '--noheadings',
- '--unit=g',
- '-o', 'vg_name,name,size,free',
- '--separator', field_sep,
- '--nosuffix']
-
+ cmd = LVM.LVM_CMD_PREFIX + ['pvs', '--noheadings',
+ '--unit=g',
+ '-o', 'vg_name,name,size,free',
+ '--separator', field_sep,
+ '--nosuffix']
(out, _err) = putils.execute(*cmd,
root_helper=root_helper,
run_as_root=True)
:returns: List of Dictionaries with VG info
"""
- cmd = ['env', 'LC_ALL=C', 'vgs', '--noheadings', '--unit=g',
- '-o', 'name,size,free,lv_count,uuid', '--separator', ':',
- '--nosuffix']
-
+ cmd = LVM.LVM_CMD_PREFIX + ['vgs', '--noheadings',
+ '--unit=g', '-o',
+ 'name,size,free,lv_count,uuid',
+ '--separator', ':',
+ '--nosuffix']
if vg_name is not None:
cmd.append(vg_name)
run_as_root=True)
def lv_has_snapshot(self, name):
- out, _err = self._execute(
- 'env', 'LC_ALL=C', 'lvdisplay', '--noheading',
- '-C', '-o', 'Attr', '%s/%s' % (self.vg_name, name),
- root_helper=self._root_helper, run_as_root=True)
+ cmd = LVM.LVM_CMD_PREFIX + ['lvdisplay', '--noheading', '-C', '-o',
+ 'Attr', '%s/%s' % (self.vg_name, name)]
+ out, _err = self._execute(*cmd,
+ root_helper=self._root_helper,
+ run_as_root=True)
if out:
out = out.strip()
if (out[0] == 'o') or (out[0] == 'O'):
cfg.StrOpt('lvm_type',
default='default',
help='Type of LVM volumes to deploy; (default or thin)'),
+ cfg.StrOpt('lvm_conf_file',
+ default='/etc/cinder/lvm.conf',
+ help='LVM conf file to use for the LVM driver in Cinder; '
+ 'this setting is ignored if the specified file does '
+ 'not exist (You can also specify \'None\' to not use '
+ 'a conf file even if one exists).')
]
CONF = cfg.CONF
"""Verify that requirements are in place to use LVM driver."""
if self.vg is None:
root_helper = utils.get_root_helper()
+
+ lvm_conf_file = self.configuration.lvm_conf_file
+ if lvm_conf_file.lower() == 'none':
+ lvm_conf_file = None
+
try:
self.vg = lvm.LVM(self.configuration.volume_group,
root_helper,
lvm_type=self.configuration.lvm_type,
- executor=self._execute)
+ executor=self._execute,
+ lvm_conf=lvm_conf_file)
+
except brick_exception.VolumeGroupNotFound:
message = (_("Volume Group %s does not exist") %
self.configuration.volume_group)
return false_ret
helper = utils.get_root_helper()
+
+ lvm_conf_file = self.configuration.lvm_conf_file
+ if lvm_conf_file.lower() == 'none':
+ lvm_conf_file = None
+
dest_vg_ref = lvm.LVM(dest_vg, helper,
lvm_type=lvm_type,
- executor=self._execute)
+ executor=self._execute,
+ lvm_conf=lvm_conf_file)
+
self.remove_export(ctxt, volume)
self._create_volume(volume['name'],
self._sizestr(volume['size']),