From 12fa24acdb05a56bfc01aac76d9f690ba8868af7 Mon Sep 17 00:00:00 2001 From: Avishay Traeger Date: Mon, 22 Jul 2013 13:43:29 +0300 Subject: [PATCH] Storwize/SVC: Use VolumeDriver's copy vol<->image. Inherit the VolumeDriver copy volume<->image functions. This patch also creates a new SanDriver class which is protocol-agnostic, and leaves the SanISCSIDriver class for drivers that wish to use it. Change-Id: Iad5cb030545ef7f4e01d006f1e63cdeeec713bf6 --- cinder/volume/drivers/san/san.py | 25 ++++++++++++++----------- cinder/volume/drivers/san/solaris.py | 7 +++---- cinder/volume/drivers/storwize_svc.py | 20 +------------------- 3 files changed, 18 insertions(+), 34 deletions(-) diff --git a/cinder/volume/drivers/san/san.py b/cinder/volume/drivers/san/san.py index 09ea3e29b..ad532810e 100644 --- a/cinder/volume/drivers/san/san.py +++ b/cinder/volume/drivers/san/san.py @@ -30,7 +30,7 @@ from cinder import exception from cinder.openstack.common import excutils from cinder.openstack.common import log as logging from cinder import utils -from cinder.volume.driver import ISCSIDriver +from cinder.volume import driver LOG = logging.getLogger(__name__) @@ -76,7 +76,7 @@ CONF = cfg.CONF CONF.register_opts(san_opts) -class SanISCSIDriver(ISCSIDriver): +class SanDriver(driver.VolumeDriver): """Base class for SAN-style storage volumes A SAN-style storage value is 'different' because the volume controller @@ -85,16 +85,14 @@ class SanISCSIDriver(ISCSIDriver): """ def __init__(self, *args, **kwargs): - super(SanISCSIDriver, self).__init__(*args, **kwargs) + execute = kwargs.pop('execute', self.san_execute) + super(SanDriver, self).__init__(execute=execute, + *args, **kwargs) self.configuration.append_config_values(san_opts) self.run_local = self.configuration.san_is_local self.sshpool = None - def _build_iscsi_target_name(self, volume): - return "%s%s" % (self.configuration.iscsi_target_prefix, - volume['name']) - - def _execute(self, *cmd, **kwargs): + def san_execute(self, *cmd, **kwargs): if self.run_local: return utils.execute(*cmd, **kwargs) else: @@ -172,6 +170,11 @@ class SanISCSIDriver(ISCSIDriver): if not self.configuration.san_ip: raise exception.InvalidInput(reason=_("san_ip must be set")) - def create_cloned_volume(self, volume, src_vref): - """Create a cloen of the specified volume.""" - raise NotImplementedError() + +class SanISCSIDriver(SanDriver, driver.ISCSIDriver): + def __init__(self, *args, **kwargs): + super(SanISCSIDriver, self).__init__(*args, **kwargs) + + def _build_iscsi_target_name(self, volume): + return "%s%s" % (self.configuration.iscsi_target_prefix, + volume['name']) diff --git a/cinder/volume/drivers/san/solaris.py b/cinder/volume/drivers/san/solaris.py index 38ab52b4a..cc6aa0e47 100644 --- a/cinder/volume/drivers/san/solaris.py +++ b/cinder/volume/drivers/san/solaris.py @@ -57,12 +57,11 @@ class SolarisISCSIDriver(SanISCSIDriver): Also make sure you can login using san_login & san_password/san_private_key """ def __init__(self, *cmd, **kwargs): - super(SolarisISCSIDriver, self).__init__(*cmd, - execute=self._execute, - **kwargs) + super(SolarisISCSIDriver, self).__init__(execute=self.solaris_execute, + *cmd, **kwargs) self.configuration.append_config_values(solaris_opts) - def _execute(self, *cmd, **kwargs): + def solaris_execute(self, *cmd, **kwargs): new_cmd = ['pfexec'] new_cmd.extend(cmd) return super(SolarisISCSIDriver, self)._execute(*new_cmd, diff --git a/cinder/volume/drivers/storwize_svc.py b/cinder/volume/drivers/storwize_svc.py index c2ed2ebcd..efe3b8a36 100755 --- a/cinder/volume/drivers/storwize_svc.py +++ b/cinder/volume/drivers/storwize_svc.py @@ -105,7 +105,7 @@ CONF = cfg.CONF CONF.register_opts(storwize_svc_opts) -class StorwizeSVCDriver(san.SanISCSIDriver): +class StorwizeSVCDriver(san.SanDriver): """IBM Storwize V7000 and SVC iSCSI/FC volume driver. Version history: @@ -1326,24 +1326,6 @@ class StorwizeSVCDriver(san.SanISCSIDriver): src_id=src_volume['id'], from_vol=True) - def copy_image_to_volume(self, context, volume, image_service, image_id): - opts = self._get_vdisk_params(volume['volume_type_id']) - if opts['protocol'] == 'iSCSI': - # Implemented in base iSCSI class - return super(StorwizeSVCDriver, self).copy_image_to_volume( - context, volume, image_service, image_id) - else: - raise NotImplementedError() - - def copy_volume_to_image(self, context, volume, image_service, image_meta): - opts = self._get_vdisk_params(volume['volume_type_id']) - if opts['protocol'] == 'iSCSI': - # Implemented in base iSCSI class - return super(StorwizeSVCDriver, self).copy_volume_to_image( - context, volume, image_service, image_meta) - else: - raise NotImplementedError() - def extend_volume(self, volume, new_size): LOG.debug(_('enter: extend_volume: volume %s') % volume['id']) ret = self._ensure_vdisk_no_fc_mappings(volume['name'], -- 2.45.2