Exemplo n.º 1
0
    def __init__(self, device, readwrite=False):
        """
        initialize a  new instance
        :param device: the file descriptor
        :param readwrite: access type
        """
        self._is_libiscsi = False
        self._is_linux_sgio = False
        self._opcodes = scsi_enum_command.spc

        if _have_libiscsi and device[:8] == 'iscsi://':
            self._iscsi = libiscsi.iscsi_create_context(
                'iqn.2007-10.com.github:python-scsi')
            self._iscsi_url = libiscsi.iscsi_parse_full_url(
                self._iscsi, device)
            libiscsi.iscsi_set_targetname(self._iscsi, self._iscsi_url.target)
            libiscsi.iscsi_set_session_type(self._iscsi,
                                            libiscsi.ISCSI_SESSION_NORMAL)
            libiscsi.iscsi_set_header_digest(
                self._iscsi, libiscsi.ISCSI_HEADER_DIGEST_NONE_CRC32C)
            libiscsi.iscsi_full_connect_sync(self._iscsi,
                                             self._iscsi_url.portal,
                                             self._iscsi_url.lun)

            self._is_libiscsi = True
        elif _have_linux_sgio and device[:5] == '/dev/':
            self._is_linux_sgio = True
            self._fd = linux_sgio.open(device, bool(readwrite))
        else:
            raise NotImplementedError('No backend implemented for %s' % device)
Exemplo n.º 2
0
    def __init__(self,
                 device,
                 readwrite=False):
        """
        initialize a  new instance of a SCSIDevice

        :param device: the file descriptor
        :param readwrite: access type
        """
        self._is_libiscsi = False
        self._is_linux_sgio = False
        self._opcodes = scsi_enum_command.spc

        if _have_libiscsi and device[:8] == 'iscsi://':
            self._iscsi = libiscsi.iscsi_create_context('iqn.2007-10.com.github:python-scsi')
            self._iscsi_url = libiscsi.iscsi_parse_full_url(self._iscsi,
                                                            device)
            libiscsi.iscsi_set_targetname(self._iscsi,
                                          self._iscsi_url.target)
            libiscsi.iscsi_set_session_type(self._iscsi,
                                            libiscsi.ISCSI_SESSION_NORMAL)
            libiscsi.iscsi_set_header_digest(self._iscsi,
                                             libiscsi.ISCSI_HEADER_DIGEST_NONE_CRC32C)
            libiscsi.iscsi_full_connect_sync(self._iscsi,
                                             self._iscsi_url.portal,
                                             self._iscsi_url.lun)

            self._is_libiscsi = True
        elif _have_linux_sgio and device[:5] == '/dev/':
            self._is_linux_sgio = True
            self._fd = linux_sgio.open(device,
                                       bool(readwrite))
        else:
            raise NotImplementedError('No backend implemented for %s' % device)
Exemplo n.º 3
0
def discovery():
    _iscsi = libiscsi.iscsi_create_context('iqn.2007-10.com.github:python-scsi')
    _iscsi_url = libiscsi.iscsi_parse_full_url(_iscsi, 'iscsi://127.0.0.1/iqn.ronnie.test/1')
    libiscsi.iscsi_set_targetname(_iscsi, _iscsi_url.target)
    libiscsi.iscsi_set_session_type(_iscsi, libiscsi.ISCSI_SESSION_DISCOVERY)
    libiscsi.iscsi_set_header_digest(_iscsi, libiscsi.ISCSI_HEADER_DIGEST_NONE_CRC32C)
    libiscsi.iscsi_full_connect_sync(_iscsi, _iscsi_url.portal, _iscsi_url.lun)

    _da = libiscsi.iscsi_discovery_sync(_iscsi)
    da = _da
    while da:
        print 'Target', da.target_name
        dp = da.portals
        while dp:
            print '  Portal', dp.portal
            dp = dp.next
        da = da.next
    libiscsi.iscsi_free_discovery_data(_iscsi, _da)
Exemplo n.º 4
0
def discovery():
    _iscsi = libiscsi.iscsi_create_context(
        'iqn.2007-10.com.github:python-scsi')
    _iscsi_url = libiscsi.iscsi_parse_full_url(
        _iscsi, 'iscsi://127.0.0.1/iqn.ronnie.test/1')
    libiscsi.iscsi_set_targetname(_iscsi, _iscsi_url.target)
    libiscsi.iscsi_set_session_type(_iscsi, libiscsi.ISCSI_SESSION_DISCOVERY)
    libiscsi.iscsi_set_header_digest(_iscsi,
                                     libiscsi.ISCSI_HEADER_DIGEST_NONE_CRC32C)
    libiscsi.iscsi_full_connect_sync(_iscsi, _iscsi_url.portal, _iscsi_url.lun)

    _da = libiscsi.iscsi_discovery_sync(_iscsi)
    da = _da
    while da:
        print 'Target', da.target_name
        dp = da.portals
        while dp:
            print '  Portal', dp.portal
            dp = dp.next
        da = da.next
    libiscsi.iscsi_free_discovery_data(_iscsi, _da)