from oslo.config import cfg
from cinder.brick import exception
-from cinder.brick.initiator import executor
+from cinder.brick import executor
from cinder.brick.initiator import host_driver
from cinder.brick.initiator import linuxfc
from cinder.brick.initiator import linuxscsi
"""
import os
-from cinder.brick.initiator import executor
+from cinder.brick import executor
from cinder.openstack.common.gettextutils import _
from cinder.openstack.common import log as logging
from cinder.openstack.common import processutils as putils
from oslo.config import cfg
from cinder.brick import exception
+from cinder.brick import executor
from cinder.openstack.common import fileutils
from cinder.openstack.common.gettextutils import _
from cinder.openstack.common import log as logging
CONF.import_opt('volume_name_template', 'cinder.db')
-class TargetAdmin(object):
+class TargetAdmin(executor.Executor):
"""iSCSI target administration.
Base class for iSCSI target admin helpers.
"""
- def __init__(self, cmd, execute):
+ def __init__(self, cmd, root_helper, execute):
+ super(TargetAdmin, self).__init__(root_helper, execute=execute)
self._cmd = cmd
- self.set_execute(execute)
-
- def set_execute(self, execute):
- """Set the function to be used to execute commands."""
- self._execute = execute
def _run(self, *args, **kwargs):
self._execute(self._cmd, *args, run_as_root=True, **kwargs)
class TgtAdm(TargetAdmin):
"""iSCSI target administration using tgtadm."""
- def __init__(self, execute=putils.execute):
- super(TgtAdm, self).__init__('tgtadm', execute)
+ def __init__(self, root_helper, execute=putils.execute):
+ super(TgtAdm, self).__init__('tgtadm', root_helper, execute)
def _get_target(self, iqn):
(out, err) = self._execute('tgt-admin', '--show', run_as_root=True)
class IetAdm(TargetAdmin):
"""iSCSI target administration using ietadm."""
- def __init__(self, execute=putils.execute):
- super(IetAdm, self).__init__('ietadm', execute)
+ def __init__(self, root_helper, execute=putils.execute):
+ super(IetAdm, self).__init__('ietadm', root_helper, execute)
def _is_block(self, path):
mode = os.stat(path).st_mode
class LioAdm(TargetAdmin):
"""iSCSI target administration for LIO using python-rtslib."""
- def __init__(self, execute=putils.execute):
- super(LioAdm, self).__init__('rtstool', execute)
+ def __init__(self, root_helper, execute=putils.execute):
+ super(LioAdm, self).__init__('rtstool', root_helper, execute)
try:
self._execute('rtstool', 'verify')
raise exception.ISCSITargetAttachFailed(volume_id=volume['id'])
-def get_target_admin():
+def get_target_admin(root_helper):
if CONF.iscsi_helper == 'tgtadm':
- return TgtAdm()
+ return TgtAdm(root_helper)
elif CONF.iscsi_helper == 'fake':
return FakeIscsiHelper()
elif CONF.iscsi_helper == 'lioadm':
- return LioAdm()
+ return LioAdm(root_helper)
else:
- return IetAdm()
+ return IetAdm(root_helper)
from oslo.config import cfg
from cinder.brick import exception
+from cinder.brick import executor
from cinder.openstack.common import fileutils
from cinder.openstack.common.gettextutils import _
from cinder.openstack.common import log as logging
CONF.import_opt('volume_name_template', 'cinder.db')
-class TargetAdmin(object):
+class TargetAdmin(executor.Executor):
"""iSER target administration.
Base class for iSER target admin helpers.
"""
- def __init__(self, cmd, execute):
+ def __init__(self, cmd, root_helper, execute):
+ super(TargetAdmin, self).__init__(root_helper, execute=execute)
self._cmd = cmd
- self.set_execute(execute)
-
- def set_execute(self, execute):
- """Set the function to be used to execute commands."""
- self._execute = execute
def _run(self, *args, **kwargs):
self._execute(self._cmd, *args, run_as_root=True, **kwargs)
class TgtAdm(TargetAdmin):
"""iSER target administration using tgtadm."""
- def __init__(self, execute=putils.execute):
- super(TgtAdm, self).__init__('tgtadm', execute)
+ def __init__(self, root_helper, execute=putils.execute):
+ super(TgtAdm, self).__init__('tgtadm', root_helper, execute)
def _get_target(self, iqn):
(out, err) = self._execute('tgt-admin', '--show', run_as_root=True)
return self.tid
-def get_target_admin():
+def get_target_admin(root_helper):
if CONF.iser_helper == 'fake':
return FakeIserHelper()
else:
- return TgtAdm()
+ return TgtAdm(root_helper)
from itertools import izip
from cinder.brick import exception
+from cinder.brick import executor
from cinder.openstack.common.gettextutils import _
from cinder.openstack.common import log as logging
from cinder.openstack.common import processutils as putils
LOG = logging.getLogger(__name__)
-class LVM(object):
+class LVM(executor.Executor):
"""LVM object to enable various LVM related operations."""
def __init__(self, vg_name, root_helper, create_vg=False,
:param executor: Execute method to use, None uses common/processutils
"""
+ super(LVM, self).__init__(execute=executor, root_helper=root_helper)
self.vg_name = vg_name
self.pv_list = []
self.lv_list = []
self.vg_uuid = None
self.vg_thin_pool = None
self.vg_thin_pool_size = 0
- self.root_helper = root_helper
- self._set_execute(executor)
if create_vg and physical_volumes is not None:
self.pv_list = physical_volumes
exists = False
cmd = ['vgs', '--noheadings', '-o', 'name']
(out, err) = self._execute(*cmd,
- root_helper=self.root_helper,
+ root_helper=self._root_helper,
run_as_root=True)
if out is not None:
def _create_vg(self, pv_list):
cmd = ['vgcreate', self.vg_name, ','.join(pv_list)]
- self._execute(*cmd, root_helper=self.root_helper, run_as_root=True)
+ self._execute(*cmd, root_helper=self._root_helper, run_as_root=True)
def _get_vg_uuid(self):
(out, err) = self._execute('vgs', '--noheadings',
:returns: List of Dictionaries with LV info
"""
- self.lv_list = self.get_all_volumes(self.root_helper, self.vg_name)
+ self.lv_list = self.get_all_volumes(self._root_helper, self.vg_name)
return self.lv_list
def get_volume(self, name):
:returns: List of Dictionaries with PV info
"""
- self.pv_list = self.get_all_physical_volumes(self.root_helper,
+ self.pv_list = self.get_all_physical_volumes(self._root_helper,
self.vg_name)
return self.pv_list
:returns: Dictionaries of VG info
"""
- vg_list = self.get_all_volume_groups(self.root_helper, self.vg_name)
+ vg_list = self.get_all_volume_groups(self._root_helper, self.vg_name)
if len(vg_list) != 1:
LOG.error(_('Unable to find VG: %s') % self.vg_name)
self.vg_uuid = vg_list[0]['uuid']
if self.vg_thin_pool is not None:
- for lv in self.get_all_volumes(self.root_helper, self.vg_name):
+ for lv in self.get_all_volumes(self._root_helper, self.vg_name):
if lv['name'] == self.vg_thin_pool:
self.vg_thin_pool_size = lv['size']
"""
- if not self.supports_thin_provisioning(self.root_helper):
+ if not self.supports_thin_provisioning(self._root_helper):
LOG.error(_('Requested to setup thin provisioning, '
'however current LVM version does not '
'support it.'))
cmd = ['lvcreate', '-T', '-L', size_str, pool_path]
self._execute(*cmd,
- root_helper=self.root_helper,
+ root_helper=self._root_helper,
run_as_root=True)
self.vg_thin_pool = pool_path
try:
self._execute(*cmd,
- root_helper=self.root_helper,
+ root_helper=self._root_helper,
run_as_root=True)
except putils.ProcessExecutionError as err:
LOG.exception(_('Error creating Volume'))
try:
self._execute(*cmd,
- root_helper=self.root_helper,
+ root_helper=self._root_helper,
run_as_root=True)
except putils.ProcessExecutionError as err:
LOG.exception(_('Error creating snapshot'))
self._execute('lvremove',
'-f',
'%s/%s' % (self.vg_name, name),
- root_helper=self.root_helper, run_as_root=True)
+ root_helper=self._root_helper, run_as_root=True)
def revert(self, snapshot_name):
"""Revert an LV from snapshot.
"""
self._execute('lvconvert', '--merge',
- snapshot_name, root_helper=self.root_helper,
+ snapshot_name, root_helper=self._root_helper,
run_as_root=True)
def lv_has_snapshot(self, name):
out, err = self._execute('lvdisplay', '--noheading',
'-C', '-o', 'Attr',
'%s/%s' % (self.vg_name, name),
- root_helper=self.root_helper,
+ root_helper=self._root_helper,
run_as_root=True)
if out:
out = out.strip()
self.stubs.Set(iscsi.LioAdm, '_get_target', self.fake_get_target)
self.stubs.Set(iscsi.LioAdm, '__init__', self.fake_init)
- def fake_init(obj):
+ def fake_init(obj, root_helper):
return
def fake_get_target(obj, iqn):
self.verify_cmds(cmds)
def run_commands(self):
- tgtadm = iscsi.get_target_admin()
+ tgtadm = iscsi.get_target_admin(None)
tgtadm.set_execute(self.fake_execute)
tgtadm.create_iscsi_target(self.target_name, self.tid,
self.lun, self.path)
self.verify_cmds(cmds)
def run_commands(self):
- tgtadm = iser.get_target_admin()
+ tgtadm = iser.get_target_admin(None)
tgtadm.set_execute(self.fake_execute)
tgtadm.create_iser_target(self.target_name, self.tid,
self.lun, self.path)
VERSION = '1.0.0'
def __init__(self, *args, **kwargs):
- self.tgtadm = iscsi.get_target_admin()
+ root_helper = 'sudo cinder-rootwrap %s' % CONF.rootwrap_config
+ self.tgtadm = iscsi.get_target_admin(root_helper)
super(BlockDeviceDriver, self).__init__(*args, **kwargs)
self.configuration.append_config_values(volume_opts)
"""
def __init__(self, *args, **kwargs):
- self.tgtadm = iscsi.get_target_admin()
+ root_helper = 'sudo cinder-rootwrap %s' % CONF.rootwrap_config
+ self.tgtadm = iscsi.get_target_admin(root_helper)
super(LVMISCSIDriver, self).__init__(*args, **kwargs)
def set_execute(self, execute):
"""
def __init__(self, *args, **kwargs):
- self.tgtadm = iser.get_target_admin()
+ root_helper = 'sudo cinder-rootwrap %s' % CONF.rootwrap_config
+ self.tgtadm = iser.get_target_admin(root_helper)
LVMVolumeDriver.__init__(self, *args, **kwargs)
def set_execute(self, execute):