本文整理汇总了Python中model.DBSession.rollback方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.rollback方法的具体用法?Python DBSession.rollback怎么用?Python DBSession.rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.DBSession
的用法示例。
在下文中一共展示了DBSession.rollback方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DetailforEachOid
# 需要导入模块: from model import DBSession [as 别名]
# 或者: from model.DBSession import rollback [as 别名]
#.........这里部分代码省略.........
''' get eth detail '''
tmpEthDict = {}
for key,value in tmpEthInfo.items():
if key == 'eth0':
getSearchofeth = DBSession.query(Ethdetail).filter(Ethdetail.ip == value['ip'], Ethdetail.mask == value['mask']).first()
if getSearchofeth:
tmpEthDict['eth0'] = getSearchofeth.eid
else:
getethcount = DBSession.query(Ethdetail).count()
getethcount = (getethcount + 1)
DBSession.add(Ethdetail(getethcount,value['status'],value['ip'],value['mask'],'eth0'))
tmpEthDict['eth0'] = getethcount
elif key == 'eth1':
getSearchofethone = DBSession.query(Ethdetail).filter(Ethdetail.ip == value['ip'], Ethdetail.mask == value['mask']).first()
if getSearchofethone:
tmpEthDict['eth1'] = getSearchofethone.eid
else:
getethcountone = DBSession.query(Ethdetail).count()
getethcountone = (getethcountone + 1)
DBSession.add(Ethdetail(getethcountone,value['status'],value['ip'],value['mask'],'eth1'))
tmpEthDict['eth1'] = getethcountone
''' Step 2. check server information exist. '''
getSearchofHardware = DBSession.query(AssetForAgent).filter(AssetForAgent.ZCBM == tmpZCBM).first()
if getSearchofHardware:
try:
if int(getSearchofHardware.Timestamp) < message['SendTime']:
DBSession.delete(getSearchofHardware)
DBSession.commit()
tmpeth0 = ""
tmpeth1 = ""
for key,value in tmpEthDict.items():
if key == 'eth0':
tmpeth0 = value
elif key == 'eth1':
tmpeth1 = value
getCountofeth = DBSession.query(EthInfo).count()
getCountofeth = (getCountofeth + 1)
DBSession.add(EthInfo(getCountofeth,tmpeth0,tmpeth1,'None','None'))
DBSession.add(AssetForAgent(tmpProjectName, tmpProjectFunc, tmpKernel, tmpCpuCoreNum, tmpSerialNum, tmpZCBM, tmpMemory, tmpCpuType, tmpModel, tmpHostName, tmpOS, tmpManufacturer, message['SendTime']))
DBSession.commit()
getTmpid = DBSession.query(AssetForAgent).filter_by(ZCBM = tmpZCBM).first()
if getTmpid:
Tmpid = getTmpid.Hid
else:
DBSession.rollback()
return dict(Status='False', msg='flush assetforagent Error.')
getCountofrelation = DBSession.query(AssetidtoEid).count()
getCountofrelation = int(getCountofrelation + 1)
DBSession.add(AssetidtoEid(getCountofrelation, Tmpid, getCountofeth))
DBSession.commit()
return dict(Status='Success')
else:
return dict(Status='Success', msg='Input Hostname Need not fresh.')
except Exception, e:
DBSession.commit()
return dict(Status='False', msg=str(e))
else:
try:
tmpHidforinsert = ""
''' insert into table'''
DBSession.add(AssetForAgent(tmpProjectName, tmpProjectFunc, tmpKernel, tmpCpuCoreNum, tmpSerialNum, tmpZCBM, tmpMemory, tmpCpuType, tmpModel, tmpHostName, tmpOS, tmpManufacturer, message['SendTime']))
DBSession.commit()
getHid = DBSession.query(AssetForAgent).filter_by(ZCBM = tmpZCBM).first()
if getHid:
tmpHidforinsert = getHid.Hid
else:
DBSession.rollback()
return dict(Status='False', msg='insert into assetforagent error.')
for key,value in tmpEthDict.items():
if key == 'eth0':
tmpeth0 = value
elif key == 'eth1':
tmpeth1 = value
getCountofeth = DBSession.query(EthInfo).count()
getCountofeth = (getCountofeth + 1)
DBSession.add(EthInfo(getCountofeth,tmpeth0,tmpeth1,'None','None'))
getCountofrelation = DBSession.query(AssetidtoEid).count()
getCountofrelation = int(getCountofrelation + 1)
DBSession.add(AssetidtoEid(getCountofrelation, tmpHidforinsert, getCountofeth))
except Exception, e:
DBSession.rollback()
return dict(Status='False', msg=str(e))
DBSession.commit()
return dict(Status='Success')
示例2: searchdoingeventofall
# 需要导入模块: from model import DBSession [as 别名]
# 或者: from model.DBSession import rollback [as 别名]
def searchdoingeventofall(self):
tmpArray = []
try:
getsearchofdoingeventall = DBSession.query(EventAlarmDoing).order_by(desc(EventAlarmDoing.Eid)).all()
if getsearchofdoingeventall:
if len(getsearchofdoingeventall) > 10:
for eachline in range(10):
# GamePYname
tmpGamePYname = EventSearch().searchGamelistAboutPYname(getsearchofdoingeventall[eachline].GameID)
if tmpGamePYname['Status'] != 'Success':
GamePYname = 'None'
else:
GamePYname = tmpGamePYname['FullName']
# OidPYname
tmpOidPYname = EventSearch().searchOIDdetailinTemplate(getsearchofdoingeventall[eachline].Oid)
if tmpOidPYname['Status'] != 'Success':
OidPYname = 'None'
else:
OidPYname = tmpOidPYname['TemplateName']
# Data
newData = base64Data().decode64(getsearchofdoingeventall[eachline].Data)
newData = eval(newData)
newData = json.dumps(newData)
# EventName
newEventName = base64Data().decode64(getsearchofdoingeventall[eachline].EventName)
# opTime
tmpOpTime = getsearchofdoingeventall[eachline].Timestamp
tmpOpPYTime = TimeBasic().timeControl(tmpOpTime, 5)
# OccurTime
tmpOccurTime = getsearchofdoingeventall[eachline].OccurTime
tmpOccurPYTime = TimeBasic().timeControl(tmpOccurTime, 5)
# ToUser
tmpUser = EventTransportExpand().searcheventindesigntoother(getsearchofdoingeventall[eachline].Eid)
if tmpUser['Status'] == 'Success':
tmpOpuser = tmpUser['ToUser']
else:
tmpOpuser = 'None'
tmpArray.append(dict(OperationTime = tmpOpTime, OperationPYTime = tmpOpPYTime, OccurTime = tmpOccurTime, OccurPYTime = tmpOccurPYTime, opUser = tmpOpuser, Eid = getsearchofdoingeventall[eachline].Eid, GameID = getsearchofdoingeventall[eachline].GameID, GamePYname = GamePYname, Oid = getsearchofdoingeventall[eachline].Oid, OidPYname = OidPYname, eventGrade = getsearchofdoingeventall[eachline].eventGrade, Data = newData, EventName = newEventName))
else:
for eachline in getsearchofdoingeventall:
# GamePYname
tmpGamePYname = EventSearch().searchGamelistAboutPYname(eachline.GameID)
if tmpGamePYname['Status'] != 'Success':
GamePYname = 'None'
else:
GamePYname = tmpGamePYname['FullName']
# OidPYname
tmpOidPYname = EventSearch().searchOIDdetailinTemplate(eachline.Oid)
if tmpOidPYname['Status'] != 'Success':
OidPYname = 'None'
else:
OidPYname = tmpOidPYname['TemplateName']
# Data
newData = base64Data().decode64(eachline.Data)
newData = eval(newData)
newData = json.dumps(newData)
# EventName
newEventName = base64Data().decode64(eachline.EventName)
# opTime
tmpOpTime = eachline.Timestamp
tmpOpPYTime = TimeBasic().timeControl(tmpOpTime, 5)
# OccurTime
tmpOccurTime = eachline.OccurTime
tmpOccurPYTime = TimeBasic().timeControl(tmpOccurTime, 5)
# ToUser
tmpUser = EventTransportExpand().searcheventindesigntoother(eachline.Eid)
if tmpUser['Status'] == 'Success':
tmpOpuser = tmpUser['ToUser']
else:
tmpOpuser = 'None'
tmpArray.append(dict(OperationTime = tmpOpTime, OperationPYTime = tmpOpPYTime, OccurTime = tmpOccurTime, OccurPYTime = tmpOccurPYTime, opUser = tmpOpuser, Eid = eachline.Eid, GameID = eachline.GameID, GamePYname = GamePYname, Oid = eachline.Oid, OidPYname = OidPYname, eventGrade = eachline.eventGrade, Data = newData, EventName = newEventName))
else:
return dict(Status='False', msg='MySQL could not found any thing in Eventalarmdoing.')
except Exception, e:
DBSession.rollback()
return dict(Status='False', msg=str(e))
示例3: searchfinisheddoingeventofbefore
# 需要导入模块: from model import DBSession [as 别名]
# 或者: from model.DBSession import rollback [as 别名]
def searchfinisheddoingeventofbefore(self, startpoint):
tmpArray = []
if type(startpoint).__name__ != 'int':
startpoint = int(startpoint)
try:
getsearchfinisheddoingeventofall = DBSession.query(EventFinished).filter((EventFinished.Eid < startpoint)).order_by(desc(EventFinished.Eid)).all()
if getsearchfinisheddoingeventofall:
if len(getsearchfinisheddoingeventofall) > 10:
for eachline in range(10):
# GamePYname
tmpGamePYname = EventSearch().searchGamelistAboutPYname(getsearchfinisheddoingeventofall[eachline].GameID)
if tmpGamePYname['Status'] != 'Success':
GamePYname = 'None'
else:
GamePYname = tmpGamePYname['FullName']
# OidPYname
tmpOidPYname = EventSearch().searchOIDdetailinTemplate(getsearchfinisheddoingeventofall[eachline].Oid)
if tmpOidPYname['Status'] != 'Success':
OidPYname = 'None'
else:
OidPYname = tmpOidPYname['TemplateName']
# Data
newData = base64Data().decode64(getsearchfinisheddoingeventofall[eachline].Data)
newData = eval(newData)
newData = json.dumps(newData)
# Timestamp
closeTime = getsearchfinisheddoingeventofall[eachline].CloseTime
newclosetime = TimeBasic().timeControl(getsearchfinisheddoingeventofall[eachline].CloseTime, 5)
# OccurTime
occurTime = getsearchfinisheddoingeventofall[eachline].OccurTime
newoccurTime = TimeBasic().timeControl(getsearchfinisheddoingeventofall[eachline].OccurTime, 5)
# DealTime
tmpDealTime = TimeBasic().TimeMinus(getsearchfinisheddoingeventofall[eachline].OccurTime, getsearchfinisheddoingeventofall[eachline].CloseTime)
# username
username = getsearchfinisheddoingeventofall[eachline].Username
# close information
Detail = getsearchfinisheddoingeventofall[eachline].Detail
tmpArray.append(dict(occurTime = occurTime, occurPYtime = newoccurTime, DealTime = tmpDealTime, closeTime = closeTime, closePYtime = newclosetime, Username = username, CloseDetail=Detail, Eid = getsearchfinisheddoingeventofall[eachline].Eid, GameID = getsearchfinisheddoingeventofall[eachline].GameID, GamePYname = GamePYname, Oid = getsearchfinisheddoingeventofall[eachline].Oid, OidPYname = OidPYname, Data = newData))
else:
for eachline in getsearchfinisheddoingeventofall:
# GamePYname
tmpGamePYname = EventSearch().searchGamelistAboutPYname(eachline.GameID)
if tmpGamePYname['Status'] != 'Success':
GamePYname = 'None'
else:
GamePYname = tmpGamePYname['FullName']
# OidPYname
tmpOidPYname = EventSearch().searchOIDdetailinTemplate(eachline.Oid)
if tmpOidPYname['Status'] != 'Success':
OidPYname = 'None'
else:
OidPYname = tmpOidPYname['TemplateName']
# Data
newData = base64Data().decode64(eachline.Data)
newData = eval(newData)
newData = json.dumps(newData)
# Timestamp
closeTime = eachline.CloseTime
newclosetime = TimeBasic().timeControl(eachline.CloseTime, 5)
# OccurTime
occurTime = eachline.OccurTime
newoccurTime = TimeBasic().timeControl(eachline.OccurTime, 5)
# DealTime
tmpDealTime = TimeBasic().TimeMinus(eachline.OccurTime, eachline.CloseTime)
# username
username = eachline.Username
# close information
Detail = eachline.Detail
tmpArray.append(dict(occurTime = occurTime, occurPYtime = newoccurTime, DealTime = tmpDealTime, closeTime = closeTime, closePYtime = newclosetime, Username = username, CloseDetail=Detail, Eid = eachline.Eid, GameID = eachline.GameID, GamePYname = GamePYname, Oid = eachline.Oid, OidPYname = OidPYname, Data = newData))
else:
return dict(Status='False', msg='MySQL could not found any thing in Eventfinshed.')
except Exception, e:
DBSession.rollback()
return dict(Status='False', msg=str(e))
示例4: teardownDatabase
# 需要导入模块: from model import DBSession [as 别名]
# 或者: from model.DBSession import rollback [as 别名]
def teardownDatabase():
DBSession.rollback()
metadata.drop_all(engine)