def get_group(self, uuid): session = db.get_session() try: q = session.query(models.HashMapGroup) q = q.filter(models.HashMapGroup.group_id == uuid) res = q.one() return res except sqlalchemy.orm.exc.NoResultFound: raise api.NoSuchGroup(uuid=uuid)
def get_group(self, uuid=None, name=None): session = db.get_session() try: q = session.query(models.HashMapGroup) if uuid: q = q.filter(models.HashMapGroup.group_id == uuid) if name: q = q.filter(models.HashMapGroup.name == name) res = q.one() return res except sqlalchemy.orm.exc.NoResultFound: raise api.NoSuchGroup(name, uuid)
def delete_group(self, uuid, recurse=True): session = db.get_session() q = utils.model_query(models.HashMapGroup, session) q = q.filter(models.HashMapGroup.group_id == uuid) with session.begin(): try: r = q.with_lockmode('update').one() except sqlalchemy.orm.exc.NoResultFound: raise api.NoSuchGroup(uuid=uuid) if recurse: for mapping in r.mappings: session.delete(mapping) for threshold in r.thresholds: session.delete(threshold) q.delete()