def clean_up(device): """Clean up iSCSI for a given device.""" try: rts_root = rtslib_fb.RTSRoot() except (OSError, EnvironmentError, rtslib_fb.RTSLibError) as exc: LOG.info( 'Linux-IO is not available, attemting to stop tgtd mapping. ' 'Error: %s.', exc) cmd = [ 'tgtadm', '--lld', 'iscsi', '--mode', 'target', '--op', 'unbind', '--tid', '1', '--initiator-address', 'ALL' ] _execute(cmd, "Error when cleaning up iscsi binds.") cmd = ['sync'] _execute(cmd, "Error flushing buffers to disk.") cmd = [ 'tgtadm', '--lld', 'iscsi', '--mode', 'target', '--op', 'delete', '--tid', '1' ] _execute(cmd, "Error deleting the iscsi target configuration.") return storage = None for x in rts_root.storage_objects: if x.udev_path == device: storage = x break if storage is None: LOG.info( 'Device %(dev)s not found in the current iSCSI mounts ' '%(mounts)s.', { 'dev': device, 'mounts': [x.udev_path for x in rts_root.storage_objects] }) return else: LOG.info('Deleting iSCSI target %(target)s for device %(dev)s.', { 'target': storage.name, 'dev': device }) try: for x in rts_root.targets: if x.wwn == storage.name: x.delete() break storage.delete() except rtslib_fb.utils.RTSLibError as exc: msg = ('Failed to delete iSCSI target %(target)s for device %(dev)s: ' '%(error)s') % { 'target': storage.name, 'dev': device, 'error': exc } raise errors.ISCSIError(msg)
def checker(*args, **kwargs): # This seems not to work on Ubuntu, so commented out. #subprocess.check_output('mount|grep -q configfs || ' # 'mount -t configfs configfs /sys/kernel/config', shell=True) dbus.SystemBus().get_object('org.kernel.TCMUService1', '/org/kernel/TCMUService1') try: return func(*args, **kwargs) finally: try: rtslib.RTSRoot().save_to_file() except Exception, e: log.exception("error saving config")
def delete_filtered_volume(req, name=None): if not name: raise TargetdError(GENERAL_TARGETD_ERROR, "No name specified.") root = rtslib.RTSRoot() stores = [obj for obj in root.storage_objects if obj.name == name and obj.plugin == 'user'] if len(stores) != 1: raise TargetdError(GENERAL_TARGETD_ERROR, "%d backstores with name %r." % (len(stores), name)) targets = {} for target in root.targets: for tpg in target.tpgs: for lun in tpg.luns: if lun.storage_object.name == name: targets[target] = 1 for target in targets.keys(): log.debug("Deleting loopback target %s for %s." % (target.wwn, name)) target.delete() log.debug("Deleting %s." % name) stores[0].delete()