Example #1
0
    def snap_protect(self, img_id, snap_name):
        try:

            snaps = self.list_snapshots(img_id)
            if snap_name not in snaps:
                raise file_system_exceptions.ImageNotFoundException(snap_name)

            with self.__open_image(img_id) as img:
                img.protect_snap(snap_name)
                return True
        except rbd.ImageNotFound:
            raise file_system_exceptions.ImageNotFoundException(img_id)
Example #2
0
 def get_parent_info(self, img_id):
     try:
         with self.__open_image(img_id) as img:
             return img.parent_info()
     except rbd.ImageNotFound:
         # Should be changed to special exception
         raise file_system_exceptions.ImageNotFoundException(img_id)
Example #3
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 #4
0
    def flatten(self, img_id):
        try:

            with self.__open_image(img_id) as img:
                img.flatten()
                return True
        except rbd.ImageNotFound:
            raise file_system_exceptions.ImageNotFoundException(img_id)
Example #5
0
 def remove_snapshot(self, img_id, name):
     try:
         with self.__open_image(img_id) as img:
             img.remove_snap(name)
             return True
     except rbd.ImageNotFound:
         raise file_system_exceptions.ImageNotFoundException(img_id)
     except rbd.ImageBusy:
         raise file_system_exceptions.SnapshotBusyException(name)
Example #6
0
 def remove(self, img_id):
     try:
         self.rbd.remove(self.context, img_id)
         return True
     except rbd.ImageNotFound:
         raise file_system_exceptions.ImageNotFoundException(img_id)
     # Don't know how to raise this
     except rbd.ImageBusy:
         raise file_system_exceptions.ImageBusyException(img_id)
     # Forgot to test this
     except rbd.ImageHasSnapshots:
         raise file_system_exceptions.ImageHasSnapshotException(img_id)
Example #7
0
    def is_snap_protected(self, img_id, snap_name):
        """
        Find out whether a snapshot is protected from deletion
        Required only for tests

        :param img_id: what the image is called
        :param snap_name: the snapshot to check
        :return: bool- whether the snapshot is protected
        """
        try:
            with self.__open_image(img_id) as img:
                return img.is_protected_snap(snap_name)
        except rbd.ImageNotFound:
            raise file_system_exceptions.ImageNotFoundException(img_id)
Example #8
0
    def snap_image(self, img_id, name):
        try:
            # Work around for Ceph problem
            snaps = self.list_snapshots(img_id)
            if name in snaps:
                raise file_system_exceptions.ImageExistsException(name)

            with self.__open_image(img_id) as img:
                img.create_snap(name)
                return True
        # Was having issue with ceph implemented work around (stack dump issue)
        except rbd.ImageExists:
            raise file_system_exceptions.ImageExistsException(img_id)
        except rbd.ImageNotFound:
            raise file_system_exceptions.ImageNotFoundException(img_id)
Example #9
0
    def list_children(self, img_id, parent_snap):
        """
        The snapshot of image whose children will be returned.
        Used only by tests.

        :param img_id: what the image is called
        :param parent_snap: the snapshot to read from
        :return: a list of (pool name, image name) tuples
        """
        try:
            with self.__open_image(img_id) as img:
                img.set_snap(parent_snap)
                return img.list_children()
        except rbd.ImageNotFound:
            raise file_system_exceptions.ImageNotFoundException(img_id)
Example #10
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 #11
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()
Example #12
0
 def get_image(self, img_id):
     try:
         return rbd.Image(self.context, img_id)
     except rbd.ImageNotFound:
         raise file_system_exceptions.ImageNotFoundException(img_id)
Example #13
0
 def list_snapshots(self, img_id):
     try:
         with self.__open_image(img_id) as img:
             return [snap['name'] for snap in img.list_snaps()]
     except rbd.ImageNotFound:
         raise file_system_exceptions.ImageNotFoundException(img_id)