예제 #1
0
 def set_metadata(self, name, metadata):
     session = db.get_session()
     try:
         db_state = utils.model_query(models.StateInfo, session).filter_by(
             name=name, ).with_lockmode('update').one()
         db_state.s_metadata = metadata
     except sqlalchemy.orm.exc.NoResultFound:
         db_state = models.StateInfo(name=name, s_metadata=metadata)
         session.add(db_state)
     finally:
         session.flush()
예제 #2
0
 def set_metadata(self, name, metadata):
     session = db.get_session()
     with session.begin():
         try:
             q = utils.model_query(models.StateInfo, session)
             q = q.filter(models.StateInfo.name == name)
             q = q.with_lockmode('update')
             db_state = q.one()
             db_state.s_metadata = metadata
         except sqlalchemy.orm.exc.NoResultFound:
             db_state = models.StateInfo(name=name, s_metadata=metadata)
             session.add(db_state)
예제 #3
0
 def set_state(self, name, state):
     session = db.get_session()
     with session.begin():
         try:
             q = utils.model_query(models.StateInfo, session).filter_by(
                 name=name, ).with_lockmode('update')
             db_state = q.one()
             db_state.state = state
         except sqlalchemy.orm.exc.NoResultFound:
             db_state = models.StateInfo(name=name, state=state)
             session.add(db_state)
     return bool(db_state.state)
예제 #4
0
파일: api.py 프로젝트: openstack/cloudkitty
 def set_state(self, name, state):
     session = db.get_session()
     with session.begin():
         try:
             q = utils.model_query(models.StateInfo, session)
             q = q.filter(models.StateInfo.name == name)
             q = q.with_for_update()
             db_state = q.one()
             db_state.state = state
         except sqlalchemy.orm.exc.NoResultFound:
             db_state = models.StateInfo(name=name, state=state)
             session.add(db_state)
     return db_state.state