Ejemplo n.º 1
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')
Ejemplo n.º 2
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')
Ejemplo n.º 3
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')
Ejemplo n.º 4
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')