예제 #1
0
def _start_lio(iqn, portal_port, device):
    try:
        storage = rtslib_fb.BlockStorageObject(name=iqn, dev=device)
        target = rtslib_fb.Target(rtslib_fb.FabricModule('iscsi'),
                                  iqn,
                                  mode='create')
        tpg = rtslib_fb.TPG(target, mode='create')
        # disable all authentication
        tpg.set_attribute('authentication', '0')
        tpg.set_attribute('demo_mode_write_protect', '0')
        tpg.set_attribute('generate_node_acls', '1')
        # lun=1 is hardcoded in ironic
        rtslib_fb.LUN(tpg, storage_object=storage, lun=1)
        tpg.enable = 1
    except rtslib_fb.utils.RTSLibError as exc:
        msg = 'Failed to create a target: {}'.format(exc)
        raise errors.ISCSIError(msg)

    try:
        # bind to the default port on all interfaces
        listen_ip = netutils.wrap_ipv6(netutils.get_wildcard_address())
        rtslib_fb.NetworkPortal(tpg, listen_ip, portal_port)
    except rtslib_fb.utils.RTSLibError as exc:
        msg = 'Failed to publish a target: {}'.format(exc)
        raise errors.ISCSIError(msg)
예제 #2
0
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)
예제 #3
0
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:
        try:
            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.")
        except errors.ISCSICommandError:
            # This command may fail if the target was already torn down
            # and that is okay, we just want to ensure it has been torn
            # down so there should be no disk locks persisting.
            pass
        cmd = ['sync']
        _execute(cmd, "Error flushing buffers to disk.")
        try:
            cmd = ['tgtadm', '--lld', 'iscsi', '--mode', 'target', '--op',
                   'delete', '--tid', '1']
            _execute(cmd, "Error deleting the iscsi target configuration.")
        except errors.ISCSICommandError:
            # This command should remove the target from being offered.
            # It is just proper clean-up, and often previously the IPA
            # side, or "target" was never really torn down in many cases.
            pass
        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)
예제 #4
0
def _execute(cmd, error_msg, check_exit_code=None):
    if check_exit_code is None:
        check_exit_code = [0]

    try:
        stdout, stderr = utils.execute(*cmd, check_exit_code=check_exit_code)
    except processutils.ProcessExecutionError as e:
        LOG.error(error_msg)
        raise errors.ISCSIError(error_msg, e.exit_code, e.stdout, e.stderr)
예제 #5
0
def _wait_for_iscsi_daemon(interval=1, attempts=10):
    """Wait for the ISCSI daemon to start."""
    for attempt in range(attempts):
        if os.path.exists("/var/run/tgtd.ipc_abstract_namespace.0"):
            break
        time.sleep(interval)
    else:
        error_msg = "ISCSI daemon didn't initialize"
        LOG.error(error_msg)
        raise errors.ISCSIError(error_msg, 1, '', error_msg)
예제 #6
0
def clean_up(device):
    """Clean up iSCSI for a given device."""
    try:
        rts_root = rtslib_fb.RTSRoot()
    except (EnvironmentError, rtslib_fb.RTSLibError) as exc:
        LOG.info('Linux-IO is not available, not cleaning up. Error: %s.', exc)
        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)