Example #1
0
 def clone(self, parent_img_name, parent_snap_name, clone_img_name):
     try:
         parent_context = child_context = self.context
         self.rbd.clone(parent_context,
                        parent_img_name,
                        parent_snap_name,
                        child_context,
                        clone_img_name,
                        features=1)
         return True
     except rbd.ImageNotFound:
         # Can be raised if the img or snap is not found
         if parent_img_name not in self.list_images():
             img_name = parent_img_name
         else:
             img_name = parent_snap_name
         raise file_system_exceptions.ImageNotFoundException(img_name)
     except rbd.ImageExists:
         raise file_system_exceptions.ImageExistsException(clone_img_name)
     # No Clue when will this be raised so not testing
     except rbd.FunctionNotSupported:
         raise file_system_exceptions.FunctionNotSupportedException()
     # No Clue when will this be raised so not testing
     except rbd.ArgumentOutOfRange:
         raise file_system_exceptions.ArgumentsOutOfRangeException()
Example #2
0
    def read(self, img_id, offset, length):
        """
        Read data from the image

        :param img_id: what the image is called
        :param offset: the offset to start reading at
        :param length: how many bytes to read
        :return: str - a string of the data read
        """
        try:
            with self.__open_image(img_id) as img:
                return img.read(offset, length)
        except rbd.ImageNotFound:
            raise file_system_exceptions.ImageNotFoundException(img_id)
        except rbd.InvalidArgument:
            raise file_system_exceptions.ArgumentsOutOfRangeException()
Example #3
0
    def write(self, img_id, data, offset):
        """
        Write data to the image

        :param img_id: what the image is called
        :param data: the data to be written
        :param offset: where to start writing data
        :return: int - the number of bytes written
        """
        try:
            with self.__open_image(img_id) as img:
                return img.write(data, offset)
        except rbd.ImageNotFound:
            raise file_system_exceptions.ImageNotFoundException(img_id)
        except rbd.InvalidArgument:
            raise file_system_exceptions.ArgumentsOutOfRangeException()