# Path: HPCStats/Exceptions.py
# class HPCStatsDBIntegrityError(HPCStatsException):
# 
#     """Class for DB intregrity errors exceptions in HPCStats"""
# 
#     def __init__(self, msg):
# 
#         super(HPCStatsDBIntegrityError, self).__init__(msg)
# 
# class HPCStatsRuntimeError(HPCStatsException):
# 
#     """Class for runtime errors exceptions in HPCStats"""
# 
#     def __init__(self, msg):
# 
#         super(HPCStatsRuntimeError, self).__init__(msg)


import logging
from HPCStats.Exceptions import HPCStatsDBIntegrityError, HPCStatsRuntimeError
                SELECT cluster_id
                  FROM Cluster
                 WHERE cluster_name = %s
              """
        params = ( self.name, )
        db.execute(req, params)
        nb_rows = db.cur.rowcount
        if nb_rows == 0:
            logger.debug("cluster %s not found in DB", str(self))
            return None
        elif nb_rows > 1:
            raise HPCStatsDBIntegrityError(
                    "several cluster_id found in DB for cluster %s" \
                      % (str(self)))
        else:
            self.cluster_id = db.cur.fetchone()[0]
            logger.debug("cluster %s found in DB with id %d",
                         str(self),
                         self.cluster_id )
            return self.cluster_id

    def save(self, db):
        """Insert Cluster in database. You must make sure that the Cluster does
           not already exist in database yet (typically using Cluster.find()
           method else there is a risk of future integrity errors because of
           duplicated clusters. If cluster_id attribute is set, it raises
           HPCStatsRuntimeError.
        """

        if self.cluster_id is not None:

# Path: HPCStats/Exceptions.py
# class HPCStatsDBIntegrityError(HPCStatsException):
# 
#     """Class for DB intregrity errors exceptions in HPCStats"""
# 
#     def __init__(self, msg):
# 
#         super(HPCStatsDBIntegrityError, self).__init__(msg)
# 
# class HPCStatsRuntimeError(HPCStatsException):
# 
#     """Class for runtime errors exceptions in HPCStats"""
# 
#     def __init__(self, msg):
# 
#         super(HPCStatsRuntimeError, self).__init__(msg)


# Path: HPCStats/Model/Cluster.py
import logging
from HPCStats.Exceptions import HPCStatsDBIntegrityError, HPCStatsRuntimeError

                SELECT cluster_id
                  FROM Cluster
                 WHERE cluster_name = %s
              """
        params = ( self.name, )
        db.execute(req, params)
        nb_rows = db.cur.rowcount
        if nb_rows == 0:
            logger.debug("cluster %s not found in DB", str(self))
            return None
        elif nb_rows > 1:
            raise HPCStatsDBIntegrityError(
                    "several cluster_id found in DB for cluster %s" \
                      % (str(self)))
        else:
            self.cluster_id = db.cur.fetchone()[0]
            logger.debug("cluster %s found in DB with id %d",
                         str(self),
                         self.cluster_id )
            return self.cluster_id

    def save(self, db):
        """Insert Cluster in database. You must make sure that the Cluster does
           not already exist in database yet (typically using Cluster.find()
           method else there is a risk of future integrity errors because of
           duplicated clusters. If cluster_id attribute is set, it raises
           HPCStatsRuntimeError.
        """

        if self.cluster_id is not None:

            raise HPCStatsRuntimeError(