message = _("Failed to create iscsi target for volume %(volume_id)s.")
+class ISCSITargetUpdateFailed(BrickException):
+ message = _("Failed to update iscsi target for volume %(name)s.")
+
+
class ISCSITargetRemoveFailed(BrickException):
message = _("Failed to remove iscsi target for volume %(volume_id)s.")
old_persist_file = os.path.join(volumes_dir, old_name)
try:
- (out, err) = self._execute('tgt-admin',
- '--update',
- name,
- run_as_root=True)
-
- LOG.debug("StdOut from tgt-admin --update: %s" % out)
- LOG.debug("StdErr from tgt-admin --update: %s" % err)
+ self.update_iscsi_target(name)
# Grab targets list for debug
# Consider adding a check for lun 0 and 1 for tgtadm
return tid
+ def update_iscsi_target(self, name):
+
+ LOG.info(_('Updating iscsi target: %s') % name)
+
+ try:
+ (out, err) = self._execute('tgt-admin', '--update', name,
+ run_as_root=True)
+ except putils.ProcessExecutionError as e:
+ LOG.error(_("Failed to update iscsi target %(name)s: %(e)s") %
+ {'name': name, 'e': str(e)})
+ LOG.debug("StdOut from tgt-admin --update: %s" % out)
+ LOG.debug("StdErr from tgt-admin --update: %s" % err)
+ raise exception.ISCSITargetUpdateFailed(name=name)
+
def remove_iscsi_target(self, tid, lun, vol_id, vol_name, **kwargs):
LOG.info(_('Removing iscsi_target for: %s') % vol_id)
vol_uuid_file = vol_name
self.tid += 1
return self.tid
+ def update_iscsi_target(self, name):
+ return
+
class LioAdm(TargetAdmin):
"""iSCSI target administration for LIO using python-rtslib."""
def _iscsi_authentication(self, chap, name, password):
return "%s %s %s" % (chap, name, password)
+ def initialize_connection(self, volume, connector):
+ """Initializes the connection and returns connection info.
+
+ This function overrides the base class implementation so that the iSCSI
+ target can be updated. This is necessary in the event that a user
+ extended the volume before attachement.
+ """
+
+ # update the iSCSI target
+ iscsi_name = "%s%s" % (self.configuration.iscsi_target_prefix,
+ volume['name'])
+ self.tgtadm.update_iscsi_target(iscsi_name)
+
+ # continue with the base class behaviour
+ return driver.ISCSIDriver.initialize_connection(self,
+ volume,
+ connector)
+
class LVMISERDriver(LVMISCSIDriver, driver.ISERDriver):
"""Executes commands relating to ISER volumes.