Esempio n. 1
0
    def _configure(self, dev, size, wwn, write_back):
        self._check_self()

        block_type = get_blockdev_type(dev)
        if block_type is None: # a file
            if os.path.exists(os.path.realpath(dev)) and not os.path.isfile(dev):
                raise RTSLibError("Path not to a file or block device")

            if size is None:
                raise RTSLibError("Path is to a file, size needed")

            self._control("fd_dev_name=%s,fd_dev_size=%d" % (dev, size))

        else: # a block device
            # size is ignored but we can't raise an exception because
            # dump() saves it and thus restore() will call us with it.

            if block_type != 0:
                raise RTSLibError("Device is not a TYPE_DISK block device")

            if is_dev_in_use(dev):
                raise RTSLibError("Device %s is already in use" % dev)

            self._control("fd_dev_name=%s" % dev)

        if write_back:
            self.set_attribute("emulate_write_cache", 1)
            self._control("fd_buffered_io=%d" % write_back)

        self._set_udev_path(dev)

        self._enable()

        super(FileIOStorageObject, self)._configure(wwn)
Esempio n. 2
0
    def _configure(self, dev, size, wwn, write_back):
        self._check_self()

        block_type = get_blockdev_type(dev)
        if block_type is None: # a file
            if os.path.exists(os.path.realpath(dev)) and not os.path.isfile(dev):
                raise RTSLibError("Path not to a file or block device")

            if size is None:
                raise RTSLibError("Path is to a file, size needed")

            self._control("fd_dev_name=%s,fd_dev_size=%d" % (dev, size))

        else: # a block device
            # size is ignored but we can't raise an exception because
            # dump() saves it and thus restore() will call us with it.

            if block_type != 0:
                raise RTSLibError("Device is not a TYPE_DISK block device")

            if is_dev_in_use(dev):
                raise RTSLibError("Device %s is already in use" % dev)

            self._control("fd_dev_name=%s" % dev)

        if write_back:
            self.set_attribute("emulate_write_cache", 1)
            self._control("fd_buffered_io=%d" % write_back)

        self._set_udev_path(dev)

        self._enable()

        super(FileIOStorageObject, self)._configure(wwn)
Esempio n. 3
0
    def _configure(self, dev, wwn, readonly):
        self._check_self()
        if get_blockdev_type(dev) != 0:
            raise RTSLibError("Device %s is not a TYPE_DISK block device" % dev)
        if is_dev_in_use(dev):
            raise RTSLibError("Cannot configure StorageObject because "
                              + "device %s is already in use" % dev)
        self._set_udev_path(dev)
        self._control("udev_path=%s" % dev)
        self._control("readonly=%d" % readonly)
        self._enable()

        super(BlockStorageObject, self)._configure(wwn)
Esempio n. 4
0
    def _configure(self, dev, wwn, readonly):
        self._check_self()
        if get_blockdev_type(dev) != 0:
            raise RTSLibError("Device %s is not a TYPE_DISK block device" % dev)
        if is_dev_in_use(dev):
            raise RTSLibError("Cannot configure StorageObject because "
                              + "device %s is already in use" % dev)
        self._set_udev_path(dev)
        self._control("udev_path=%s" % dev)
        self._control("readonly=%d" % readonly)
        self._enable()

        super(BlockStorageObject, self)._configure(wwn)
Esempio n. 5
0
    def _configure(self, dev, size, wwn, buffered_mode):
        self._check_self()
        rdev = os.path.realpath(dev)
        if not os.path.isdir(os.path.dirname(rdev)):
            raise RTSLibError("The dev parameter must be a path to a "
                              + "file inside an existing directory, "
                              + "not %s." % str(os.path.dirname(dev)))
        if os.path.isdir(rdev):
            raise RTSLibError("The dev parameter must be a path to a "
                              + "file or block device not a directory:"
                              + "%s." % dev)

        block_type = get_block_type(rdev)
        if block_type is None and not is_disk_partition(rdev):
            if os.path.exists(rdev) and not os.path.isfile(dev):
                raise RTSLibError("Device %s is neither a file, " % dev
                                  + "a disk partition or a block device.")
            # It is a file
            if size is None:
                raise RTSLibError("The size parameter is mandatory "
                                  + "when using a file.")
            size = convert_human_to_bytes(size)
            self._control("fd_dev_name=%s,fd_dev_size=%d" % (dev, size))
        else:
            # it is a block device or a disk partition
            if size is not None:
                raise RTSLibError("You cannot specify a size for a "
                                  + "block device.")
            if block_type != 0 and block_type is not None:
                raise RTSLibError("Device %s is a block device, " % dev
                                  + "but not of TYPE_DISK.")
            if is_dev_in_use(rdev):
                raise RTSLibError("Cannot configure StorageObject "
                                  + "because device "
                                  + "%s is already in use." % dev)
            if is_disk_partition(rdev):
                size = get_disk_size(rdev)
                print "fd_dev_name=%s,fd_dev_size=%d" % (dev, size)
                self._control("fd_dev_name=%s,fd_dev_size=%d" % (dev, size))
            else:
                self._control("fd_dev_name=%s" % dev)

        self._set_udev_path(dev)

        if buffered_mode:
            self._set_buffered_mode()

        self._enable()

        if wwn:
            self.wwn = generate_wwn('unit_serial')
Esempio n. 6
0
    def _configure(self, dev, size, wwn, buffered_mode):
        self._check_self()
        rdev = os.path.realpath(dev)
        if not os.path.isdir(os.path.dirname(rdev)):
            raise RTSLibError("The dev parameter must be a path to a " +
                              "file inside an existing directory, " +
                              "not %s." % str(os.path.dirname(dev)))
        if os.path.isdir(rdev):
            raise RTSLibError("The dev parameter must be a path to a " +
                              "file or block device not a directory:" +
                              "%s." % dev)

        block_type = get_block_type(rdev)
        if block_type is None and not is_disk_partition(rdev):
            if os.path.exists(rdev) and not os.path.isfile(dev):
                raise RTSLibError("Device %s is neither a file, " % dev +
                                  "a disk partition or a block device.")
            # It is a file
            if size is None:
                raise RTSLibError("The size parameter is mandatory " +
                                  "when using a file.")
            size = convert_human_to_bytes(size)
            self._control("fd_dev_name=%s,fd_dev_size=%d" % (dev, size))
        else:
            # it is a block device or a disk partition
            if size is not None:
                raise RTSLibError("You cannot specify a size for a " +
                                  "block device.")
            if block_type != 0 and block_type is not None:
                raise RTSLibError("Device %s is a block device, " % dev +
                                  "but not of TYPE_DISK.")
            if is_dev_in_use(rdev):
                raise RTSLibError("Cannot configure StorageObject " +
                                  "because device " +
                                  "%s is already in use." % dev)
            if is_disk_partition(rdev):
                size = get_disk_size(rdev)
                self._control("fd_dev_name=%s,fd_dev_size=%d" % (dev, size))
            else:
                self._control("fd_dev_name=%s" % dev)

        self._set_udev_path(dev)

        if buffered_mode:
            self._set_buffered_mode()

        self._enable()

        if wwn:
            self.wwn = generate_wwn('unit_serial')
Esempio n. 7
0
    def _configure(self, dev, wwn, readonly, write_back):
        self._check_self()
        if get_blockdev_type(dev) != 0:
            raise RTSLibError("Device is not a TYPE_DISK block device.")
        if is_dev_in_use(dev):
            raise RTSLibError("Cannot configure StorageObject because "
                              + "device %s is already in use." % dev)
        self._set_udev_path(dev)
        self._control("udev_path=%s" % dev)
        self._control("readonly=%d" % readonly)
        self._enable()

        if write_back:
            self.set_attribute("emulate_write_cache", 1)

        super(BlockStorageObject, self)._configure(wwn)
Esempio n. 8
0
    def _configure(self, dev, wwn, readonly, write_back):
        self._check_self()
        if get_blockdev_type(dev) != 0:
            raise RTSLibError("Device is not a TYPE_DISK block device.")
        if is_dev_in_use(dev):
            raise RTSLibError("Cannot configure StorageObject because " +
                              "device %s is already in use." % dev)
        self._set_udev_path(dev)
        self._control("udev_path=%s" % dev)
        self._control("readonly=%d" % readonly)
        self._enable()

        if write_back:
            self.set_attribute("emulate_write_cache", 1)

        super(BlockStorageObject, self)._configure(wwn)
Esempio n. 9
0
    def _configure(self, dev):
        self._check_self()

        # Use H:C:T:L format or preserve the path given by the user.
        try:
            (hostid, channelid, targetid, lunid) = \
                    convert_scsi_path_to_hctl(dev)
        except TypeError:
            try:
                (hostid, channelid, targetid, lunid) = dev.split(':')
                hostid = int(hostid)
                channelid = int(channelid)
                targetid = int(targetid)
                lunid = int(lunid)
            except ValueError:
                raise RTSLibError("Cannot find SCSI device by "
                                  + "path, and dev "
                                  + "parameter not in H:C:T:L "
                                  + "format: %s" % dev)
            else:
                udev_path = convert_scsi_hctl_to_path(hostid,
                                                            channelid,
                                                            targetid,
                                                            lunid)
            if not udev_path:
                raise RTSLibError("SCSI device does not exist")
        else:
            udev_path = dev.strip()

        if is_dev_in_use(udev_path):
            raise RTSLibError("Cannot configure StorageObject because "
                              + "device %s (SCSI %d:%d:%d:%d) "
                              % (udev_path, hostid, channelid,
                                 targetid, lunid)
                              + "is already in use")

        self._control("scsi_host_id=%d," % hostid \
                      + "scsi_channel_id=%d," % channelid \
                      + "scsi_target_id=%d," % targetid \
                      + "scsi_lun_id=%d" % lunid)
        self._set_udev_path(udev_path)
        self._enable()

        super(PSCSIStorageObject, self)._configure()
Esempio n. 10
0
    def _configure(self, dev):
        self._check_self()

        # Use H:C:T:L format or preserve the path given by the user.
        try:
            (hostid, channelid, targetid, lunid) = \
                    convert_scsi_path_to_hctl(dev)
        except TypeError:
            try:
                (hostid, channelid, targetid, lunid) = dev.split(':')
                hostid = int(hostid)
                channelid = int(channelid)
                targetid = int(targetid)
                lunid = int(lunid)
            except ValueError:
                raise RTSLibError("Cannot find SCSI device by "
                                  + "path, and dev "
                                  + "parameter not in H:C:T:L "
                                  + "format: %s" % dev)
            else:
                udev_path = convert_scsi_hctl_to_path(hostid,
                                                            channelid,
                                                            targetid,
                                                            lunid)
            if not udev_path:
                raise RTSLibError("SCSI device does not exist")
        else:
            udev_path = dev.strip()

        if is_dev_in_use(udev_path):
            raise RTSLibError("Cannot configure StorageObject because "
                              + "device %s (SCSI %d:%d:%d:%d) "
                              % (udev_path, hostid, channelid,
                                 targetid, lunid)
                              + "is already in use")

        self._control("scsi_host_id=%d," % hostid \
                      + "scsi_channel_id=%d," % channelid \
                      + "scsi_target_id=%d," % targetid \
                      + "scsi_lun_id=%d" % lunid)
        self._set_udev_path(udev_path)
        self._enable()

        super(PSCSIStorageObject, self)._configure()
Esempio n. 11
0
 def _configure(self, dev, wwn):
     self._check_self()
     if get_block_type(dev) != 0:
         raise RTSLibError("Device is not a TYPE_DISK block device.")
     if is_dev_in_use(dev):
         raise RTSLibError("Cannot configure StorageObject because "
                           + "device %s is already in use." % dev)
     self._set_udev_path(dev)
     if self._backstore.version.startswith("v3."):
         # For 3.x, use the fd method
         file_fd = os.open(dev, os.O_RDWR)
         try:
             self._write_fd(file_fd)
         finally:
             os.close(file_fd)
     else:
         # For 4.x and above, use the generic udev_path method
         self._control("udev_path=%s" % dev)
         self._enable()
     if wwn:
         self.wwn = generate_wwn('unit_serial')
Esempio n. 12
0
 def _configure(self, dev, wwn):
     self._check_self()
     if get_block_type(dev) != 0:
         raise RTSLibError("Device is not a TYPE_DISK block device.")
     if is_dev_in_use(dev):
         raise RTSLibError("Cannot configure StorageObject because " +
                           "device %s is already in use." % dev)
     self._set_udev_path(dev)
     if self._backstore.version.startswith("v3."):
         # For 3.x, use the fd method
         file_fd = os.open(dev, os.O_RDWR)
         try:
             self._write_fd(file_fd)
         finally:
             os.close(file_fd)
     else:
         # For 4.x and above, use the generic udev_path method
         self._control("udev_path=%s" % dev)
         self._enable()
     if wwn:
         self.wwn = generate_wwn('unit_serial')
Esempio n. 13
0
    def _configure(self, dev):
        self._check_self()
        parent_hostid = self.backstore.index
        legacy = self.backstore.legacy_mode
        if legacy:
            try:
                (hostid, channelid, targetid, lunid) = \
                        convert_scsi_path_to_hctl(dev)
            except TypeError:
                try:
                    (channelid, targetid, lunid) = dev.split(':')
                    channelid = int(channelid)
                    targetid = int(targetid)
                    lunid = int(lunid)
                except ValueError:
                    raise RTSLibError("Cannot find SCSI device by " +
                                      "path, and dev parameter not " +
                                      "in C:T:L format: %s." % dev)
                else:
                    udev_path = convert_scsi_hctl_to_path(
                        parent_hostid, channelid, targetid, lunid)
                if not udev_path:
                    raise RTSLibError("SCSI device does not exist.")
            else:
                if hostid != parent_hostid:
                    raise RTSLibError("The specified SCSI device does " +
                                      "not belong to the backstore.")
                else:
                    udev_path = dev.strip()
        else:
            # The Backstore is not in legacy mode.
            # Use H:C:T:L format or preserve the path given by the user.
            try:
                (hostid, channelid, targetid, lunid) = \
                        convert_scsi_path_to_hctl(dev)
            except TypeError:
                try:
                    (hostid, channelid, targetid, lunid) = dev.split(':')
                    hostid = int(hostid)
                    channelid = int(channelid)
                    targetid = int(targetid)
                    lunid = int(lunid)
                except ValueError:
                    raise RTSLibError("Cannot find SCSI device by " +
                                      "path, and dev " +
                                      "parameter not in H:C:T:L " +
                                      "format: %s." % dev)
                else:
                    udev_path = convert_scsi_hctl_to_path(
                        hostid, channelid, targetid, lunid)
                if not udev_path:
                    raise RTSLibError("SCSI device does not exist.")
            else:
                udev_path = dev.strip()

        if is_dev_in_use(udev_path):
            raise RTSLibError("Cannot configure StorageObject because " +
                              "device %s (SCSI %d:%d:%d:%d) " %
                              (udev_path, hostid, channelid, targetid, lunid) +
                              "is already in use.")

        if legacy:
            self._control("scsi_channel_id=%d," % channelid \
                          + "scsi_target_id=%d," % targetid \
                          + "scsi_lun_id=%d" %  lunid)
        else:
            self._control("scsi_host_id=%d," % hostid \
                          + "scsi_channel_id=%d," % channelid \
                          + "scsi_target_id=%d," % targetid \
                          + "scsi_lun_id=%d" % lunid)
        self._set_udev_path(udev_path)
        self._enable()
Esempio n. 14
0
    def _configure(self, dev):
        self._check_self()
        parent_hostid = self.backstore.index
        legacy = self.backstore.legacy_mode
        if legacy:
            try:
                (hostid, channelid, targetid, lunid) = \
                        convert_scsi_path_to_hctl(dev)
            except TypeError:
                try:
                    (channelid, targetid, lunid) = dev.split(':')
                    channelid = int(channelid)
                    targetid = int(targetid)
                    lunid = int(lunid)
                except ValueError:
                    raise RTSLibError("Cannot find SCSI device by "
                                      + "path, and dev parameter not "
                                      + "in C:T:L format: %s." % dev)
                else:
                    udev_path = convert_scsi_hctl_to_path(parent_hostid,
                                                                channelid,
                                                                targetid,
                                                                lunid)
                if not udev_path:
                    raise RTSLibError("SCSI device does not exist.")
            else:
                if hostid != parent_hostid:
                    raise RTSLibError("The specified SCSI device does "
                                      + "not belong to the backstore.")
                else:
                    udev_path = dev.strip()
        else:
            # The Backstore is not in legacy mode.
            # Use H:C:T:L format or preserve the path given by the user.
            try:
                (hostid, channelid, targetid, lunid) = \
                        convert_scsi_path_to_hctl(dev)
            except TypeError:
                try:
                    (hostid, channelid, targetid, lunid) = dev.split(':')
                    hostid = int(hostid)
                    channelid = int(channelid)
                    targetid = int(targetid)
                    lunid = int(lunid)
                except ValueError:
                    raise RTSLibError("Cannot find SCSI device by "
                                      + "path, and dev "
                                      + "parameter not in H:C:T:L "
                                      + "format: %s." % dev)
                else:
                    udev_path = convert_scsi_hctl_to_path(hostid,
                                                                channelid,
                                                                targetid,
                                                                lunid)
                if not udev_path:
                    raise RTSLibError("SCSI device does not exist.")
            else:
                udev_path = dev.strip()

        if is_dev_in_use(udev_path):
            raise RTSLibError("Cannot configure StorageObject because "
                              + "device %s (SCSI %d:%d:%d:%d) "
                              % (udev_path, hostid, channelid,
                                 targetid, lunid)
                              + "is already in use.")

        if legacy:
            self._control("scsi_channel_id=%d," % channelid \
                          + "scsi_target_id=%d," % targetid \
                          + "scsi_lun_id=%d" %  lunid)
        else:
            self._control("scsi_host_id=%d," % hostid \
                          + "scsi_channel_id=%d," % channelid \
                          + "scsi_target_id=%d," % targetid \
                          + "scsi_lun_id=%d" % lunid)
        self._set_udev_path(udev_path)
        self._enable()