Exemple #1
0
    def __get_ceph_image_name(self, name):
        img_id = self.db.image.fetch_id_with_name_from_project(name, self.proj)
        if img_id is None:
            logger.info("Raising Image Not Found Exception for %s", name)
            raise db_exceptions.ImageNotFoundException(name)

        return str(self.cfg.bmi.uid) + "img" + str(img_id)
Exemple #2
0
    def copy_image(self, src_project_name, name, dest_pid, new_name=None):
        try:

            project = self.connection.session.query(Project).filter_by(
                name=src_project_name).one_or_none()

            if project is None:
                raise db_exceptions.ProjectNotFoundException(src_project_name)

            image = self.connection.session.query(Image). \
                filter(Image.project.has(name=src_project_name)).filter_by(
                name=name).one_or_none()

            if image is None:
                raise db_exceptions.ImageNotFoundException(name)

            new_image = Image()
            if new_name is not None:
                new_image.name = new_name
            else:
                new_image.name = name

            new_image.project_id = dest_pid
            new_image.is_public = image.is_public
            if project.id == dest_pid:
                new_image.is_snapshot = image.is_snapshot
                new_image.parent_id = image.parent_id
            else:
                new_image.is_snapshot = False
                new_image.parent_id = None
            self.connection.session.add(new_image)
            self.connection.session.commit()
        except SQLAlchemyError as e:
            self.connection.session.rollback()
            raise db_exceptions.ORMException(e.message)
Exemple #3
0
    def fetch_id_with_name_from_project(self, name, project_name):
        """
        Searches for image by name and returns image id

        :param name: name of the image
        :param project_name: name of the project
        :return: the id of the image.
        """

        try:
            image = self.connection.session.query(Image). \
                filter(Image.project.has(name=project_name)).filter_by(
                name=name).one_or_none()
            if image is None:
                raise db_exceptions.ImageNotFoundException(name)
            return image.id
        except SQLAlchemyError as e:
            raise db_exceptions.ORMException(e.message)
Exemple #4
0
    def delete_with_name_from_project(self, name, project_name):
        try:
            image = self.connection.session.query(Image). \
                filter(Image.project.has(name=project_name)).filter_by(
                name=name).one_or_none()
            if image is not None:

                if self.__image_has_clones(image):
                    raise db_exceptions.ImageHasClonesException(image)

                for child in image.children:
                    child.parent_id = None
                    child.is_snapshot = False
                self.connection.session.delete(image)
                self.connection.session.commit()
            else:
                raise db_exceptions.ImageNotFoundException(name)
        except SQLAlchemyError as e:
            self.connection.session.rollback()
            raise db_exceptions.ORMException(e.message)