本文整理汇总了Python中stackone.model.DBSession.add_all方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.add_all方法的具体用法?Python DBSession.add_all怎么用?Python DBSession.add_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stackone.model.DBSession
的用法示例。
在下文中一共展示了DBSession.add_all方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_vm_states
# 需要导入模块: from stackone.model import DBSession [as 别名]
# 或者: from stackone.model.DBSession import add_all [as 别名]
def add_vm_states(self, vm_ids):
try:
transaction.begin()
avail_states = DBSession.query(AvailState).filter(AvailState.entity_id.in_(vm_ids)).all()
from stackone.model.VM import VM
(vshs, avails) = ([], [])
for avail in avail_states:
vsh = DBSession.query(VMStateHistory).filter(VMStateHistory.node_id == self.node_id).filter(VMStateHistory.vm_id == avail.entity_id).first()
if vsh is None:
vsh = VMStateHistory(self.node_id, avail.entity_id, avail.avail_state, avail.monit_state, avail.transient_state, avail.transient_state_time, avail.owner)
else:
vsh.avail_state = avail.avail_state
vsh.monit_state = avail.monit_state
vsh.transient_state = avail.transient_state
vsh.transient_state_time = avail.transient_state_time
vsh.owner = avail.owner
vsh.timestamp = datetime.now()
vshs.append(vsh)
avails.append(avail)
DBSession.add_all(vshs)
DBSession.add_all(avails)
transaction.commit()
except Exception as e:
LOGGER.error(to_str(e))
DBSession.rollback()
transaction.begin()
traceback.print_exc()
raise e
示例2: add_vm_states
# 需要导入模块: from stackone.model import DBSession [as 别名]
# 或者: from stackone.model.DBSession import add_all [as 别名]
def add_vm_states(cls, node_id):
try:
node_ent = DBSession.query(Entity).filter(Entity.entity_id == node_id).first()
if node_ent is None:
msg = 'Entity can not be found for ' + node_id
logger.error(msg)
raise Exception(msg)
vm_ents = node_ent.children
vm_ids = [vm.entity_id for vm in vm_ents]
transaction.begin()
avail_states = DBSession.query(AvailState).filter(AvailState.entity_id.in_(vm_ids)).all()
from stackone.model.VM import VM
vshs,avails = [],[]
for avail in avail_states:
vsh = DBSession.query(cls).filter(cls.node_id == node_id).filter(cls.vm_id == avail.entity_id).first()
if vsh is None:
vsh = VMStateHistory(node_id,avail.entity_id,avail.avail_state,avail.monit_state,avail.transient_state,avail.transient_state_time,avail.owner)
else:
vsh.avail_state = avail.avail_state
vsh.monit_state = avail.monit_state
vsh.transient_state = avail.transient_state
vsh.transient_state_time = avail.transient_state_time
vsh.owner = avail.owner
vsh.timestamp = datetime.now()
avail.avail_state = VM.SHUTDOWN
vshs.append(vsh)
avails.append(avail)
DBSession.add_all(vshs)
DBSession.add_all(avails)
transaction.commit()
except Exception as e:
logger.error(to_str(e))
DBSession.rollback()
transaction.begin()
traceback.print_exc()
raise e
示例3: save_dwm_details
# 需要导入模块: from stackone.model import DBSession [as 别名]
# 或者: from stackone.model.DBSession import add_all [as 别名]
def save_dwm_details(self, auth, group_id, policy_object, enabled, offset):
try:
self.tc = TaskCreator()
self.utcoffset = timedelta(milliseconds=long(offset))
group = self.get_group(auth, group_id)
if enabled == 'true':
dwm_list = DBSession.query(DWM).filter(DWM.sp_id == group_id).all()
task_ids = []
interval_task_ids = []
dwmelems = {}
for dwmelem in dwm_list:
interval_task_ids.append(dwmelem.interval_task_id)
if dwmelem.calendar_task_ids:
task_ids.extend(dwmelem.calendar_task_ids)
dwmelem.enabled = False
dwmelems[dwmelem.policy] = dwmelem
if task_ids:
self.tc.delete_task(task_ids)
policy_obj = json.loads(policy_object)
policies = policy_obj['policy_object']['policies']
freq = 5
dwms = []
schedules = []
for policy in policies:
dwmelem = dwmelems.get(policy['policy_name'])
if dwmelem != None:
dwmelem.enabled = True
(dwm, policy_schedules) = self.save_dwm_policy(auth, group_id, policy['threshold'], policy['frequency'], policy['data_period'], policy['upper_threshold'], policy['policy_name'], policy['schedule_object'])
freq = policy['frequency']
dwms.append(dwm)
schedules.extend(policy_schedules)
sp_dwm = SPDWMPolicy(group_id, None)
DBSession.merge(sp_dwm)
if interval_task_ids:
self.tc.delete_task(interval_task_ids)
interval_task_id = self.tc.dwm_task(auth, group_id, freq)
for d in dwms:
d.interval_task_id = interval_task_id
DBSession.add(d)
group.dwm_enabled = True
DBSession.add(group)
transaction.commit()
DBSession.add_all(schedules)
transaction.commit()
DBSession.query(DWM).filter(DWM.sp_id == group_id).update(dict(interval_task_id=interval_task_id))
pol = DWM.find_current_policy(group_id)
if pol and pol.is_enabled():
sp_dwm = SPDWMPolicy.set_sp_current_policy(group_id, pol.policy, SPDWMPolicy.ON)
return True
result = self.delete_dwm_tasks(auth, group_id)
DBSession.query(DWM).filter(DWM.sp_id == group_id).update(dict(interval_task_id=None, calendar_task_ids=None))
group.dwm_enabled = False
DBSession.add(group)
sp_dwm = SPDWMPolicy(group_id, None)
DBSession.merge(sp_dwm)
return result
except Exception as ex:
traceback.print_exc()
raise ex
示例4: add_all
# 需要导入模块: from stackone.model import DBSession [as 别名]
# 或者: from stackone.model.DBSession import add_all [as 别名]
def add_all(self, obj_list):
DBSession.add_all(obj_list)