当前位置: 首页>>代码示例>>Python>>正文


Python DBSession.flush方法代码示例

本文整理汇总了Python中stackone.model.DBSession.flush方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.flush方法的具体用法?Python DBSession.flush怎么用?Python DBSession.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stackone.model.DBSession的用法示例。


在下文中一共展示了DBSession.flush方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update_node_defn

# 需要导入模块: from stackone.model import DBSession [as 别名]
# 或者: from stackone.model.DBSession import flush [as 别名]
    def update_node_defn(self, auth, node_id, group_id, site_id, def_id, def_type, status, dt_time, details, scope, defType, csep_id=None):
        LOGGER.info('Updating server definition status...')
        node_defn = DBSession.query(ServerDefLink).filter_by(server_id=node_id, def_id=def_id).first()
        if node_defn:
            if status:
                node_defn.status = status
            node_defn.dt_time = datetime.now()
            if details:
                node_defn.details = details
            transaction.commit()
            LOGGER.info('Server definition status is updated. Status is ' + to_str(status))
        LOGGER.info('Updating server pool definition status...')
        oos_count_g = 0
        g_status = to_unicode(constants.IN_SYNC)
        if group_id:
            group_entity = auth.get_entity(group_id)
            if group_entity is not None:
                group = DBSession.query(ServerGroup).filter_by(id=group_id).first()
                if group:
                    group.credential = None
                    for node in group.getNodeList(auth).itervalues():
                        rowNodeDefn = DBSession.query(ServerDefLink).filter_by(server_id=node.id, def_id=def_id, def_type=to_unicode(defType), status=to_unicode(constants.OUT_OF_SYNC))
                        if rowNodeDefn:
                            oos_count_g += rowNodeDefn.count()
        if oos_count_g > 0:
            g_status = to_unicode(constants.OUT_OF_SYNC)
        else:
            g_status = to_unicode(constants.IN_SYNC)
        group_sd = DBSession.query(SPDefLink).filter_by(group_id=group_id, def_id=def_id, def_type=to_unicode(defType)).first()
        if group_sd:
            group_sd.status = g_status
            group_sd.dt_time = datetime.now()
            group_sd.oos_count = oos_count_g
            transaction.commit()
            LOGGER.info('Server pool level definition status is updated')

        LOGGER.info('Updating data center definition status...')
        oos_count_dc = 0
        dc_status = to_unicode(constants.IN_SYNC)
        rowNodeDefn = DBSession.query(ServerDefLink).filter_by(def_id=def_id, def_type=to_unicode(defType), status=to_unicode(constants.OUT_OF_SYNC))
        if rowNodeDefn:
            oos_count_dc = rowNodeDefn.count()
        if oos_count_dc > 0:
            dc_status = to_unicode(constants.OUT_OF_SYNC)
        else:
            dc_status = to_unicode(constants.IN_SYNC)
        dc_sd = DBSession.query(DCDefLink).filter_by(site_id=site_id, def_id=def_id, def_type=to_unicode(defType)).first()
        if dc_sd:
            dc_sd.status = dc_status
            dc_sd.dt_time = datetime.now()
            dc_sd.oos_count = oos_count_dc
            DBSession.flush()
            transaction.commit()
            LOGGER.info('Data center level definition status is updated')

        if csep_id:
            csep_sd = DBSession.query(CSEPDefLink).filter_by(csep_id=csep_id, def_id=def_id, def_type=to_unicode(defType)).first()
            if csep_sd:
                csep_sd.status = dc_status
                csep_sd.dt_time = datetime.now()
                csep_sd.oos_count = oos_count_dc
                DBSession.flush()
                transaction.commit()
                LOGGER.info('CSEP level definition status is updated')
开发者ID:smarkm,项目名称:ovm,代码行数:66,代码来源:SyncDefinition.py


注:本文中的stackone.model.DBSession.flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。