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


Python DBSession.add方法代码示例

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


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

示例1: update_avail

# 需要导入模块: from convirt.model import DBSession [as 别名]
# 或者: from convirt.model.DBSession import add [as 别名]
def update_avail(node, new_state, monit_state, timestamp, reason, logger, update=True, auth=None):
    sv_point = transaction.savepoint()
    try:
        strt = p_task_timing_start(logger, "UpdateAvailability", node.id, log_level="DEBUG")
        #there is a status change, update and send event
        #update current availability,
        #we only update avail-state, monit_state is updated
        #only by user actions
        node.current_state.avail_state = new_state
        node.current_state.timestamp = timestamp
        node.current_state.description = reason
        avh=DBSession.query(AvailHistory).filter(AvailHistory.entity_id==node.id).\
            order_by(AvailHistory.timestamp.desc()).first()
        if avh is not None:
            avh.endtime=timestamp
            time_diff=timestamp-avh.timestamp
            avh.period=time_diff.days*24*60+time_diff.seconds/60
            DBSession.add(avh)
        #insert availability history
        ah = AvailHistory(node.id, new_state, monit_state, timestamp, reason)
        DBSession.add(ah)
        if update==True:
            ent = DBSession.query(Entity).filter(Entity.entity_id==node.id).first()
            from convirt.model.ManagedNode import ManagedNode
            if ent.type.name == constants.MANAGED_NODE:
                if new_state == ManagedNode.DOWN:
                    notify_node_down(ent.name, reason)
                else:
                    node_up_action(auth, node.id)
    except Exception, e:
        #defer to next time
        import traceback
        traceback.print_exc()
        logger.error(e)
        sv_point.rollback()
开发者ID:RDTeam,项目名称:openconvirt,代码行数:37,代码来源:availability.py

示例2: setup

# 需要导入模块: from convirt.model import DBSession [as 别名]
# 或者: from convirt.model.DBSession import add [as 别名]
 def setup(self):
     try:
         new_attrs = {}
         new_attrs.update(self.attrs)
         new_attrs.update(self.do_get_dependencies())
         self.obj = self.klass(**new_attrs)
         DBSession.add(self.obj)
         DBSession.flush()
         return self.obj
     except:
         DBSession.rollback()
         raise
开发者ID:RDTeam,项目名称:openconvirt,代码行数:14,代码来源:__init__.py

示例3: add_site_defn

# 需要导入模块: from convirt.model import DBSession [as 别名]
# 或者: from convirt.model.DBSession import add [as 别名]
 def add_site_defn(self, site_id, def_id, def_type, status, oos_count):
     #Check whether the record is already present...
     row = DBSession.query(DCDefLink).filter_by(site_id = site_id, def_id = def_id).first()
     if not row:
         DCDL = DCDefLink()
         DCDL.site_id = site_id
         DCDL.def_type = def_type
         DCDL.def_id = def_id
         DCDL.status = to_unicode(status)
         DCDL.oos_count = oos_count
         DCDL.dt_time = datetime.utcnow()
         DBSession.add(DCDL)
开发者ID:RDTeam,项目名称:openconvirt,代码行数:14,代码来源:SyncDefinition.py

示例4: add_group_defn

# 需要导入模块: from convirt.model import DBSession [as 别名]
# 或者: from convirt.model.DBSession import add [as 别名]
 def add_group_defn(self, group_id, def_id, def_type, status, oos_count):
     #Check whether the record is already present...
     row = DBSession.query(SPDefLink).filter_by(group_id = group_id, def_id = def_id).first()
     if not row:
         SPDL = SPDefLink()
         SPDL.group_id = group_id
         SPDL.def_type = def_type
         SPDL.def_id = def_id
         SPDL.status = status
         SPDL.oos_count = oos_count
         SPDL.dt_time = datetime.utcnow()
         DBSession.add(SPDL)
开发者ID:RDTeam,项目名称:openconvirt,代码行数:14,代码来源:SyncDefinition.py

示例5: add_node_defn

# 需要导入模块: from convirt.model import DBSession [as 别名]
# 或者: from convirt.model.DBSession import add [as 别名]
 def add_node_defn(self, node_id, def_id, def_type, status, details):
     #Check whether the record is already present...
     row = DBSession.query(ServerDefLink).filter_by(server_id = node_id, def_id = def_id).first()
     if not row:
         node_defn = ServerDefLink()
         node_defn.server_id = to_unicode(node_id)
         node_defn.def_type = to_unicode(def_type)
         node_defn.def_id = def_id
         node_defn.status = to_unicode(status)
         node_defn.details = to_unicode(details)
         node_defn.dt_time = datetime.utcnow()
         DBSession.add(node_defn)
开发者ID:RDTeam,项目名称:openconvirt,代码行数:14,代码来源:SyncDefinition.py

示例6: update_execution_context

# 需要导入模块: from convirt.model import DBSession [as 别名]
# 或者: from convirt.model.DBSession import add [as 别名]
 def update_execution_context(self):
     """
     storing context in task for resume process
     """
     tid = TaskUtil.get_task_context()
     WRK_LOGGER.debug("in update_execution_context Parent task : "+str(tid)+" : child tasks :"+str(self.worker_ids))
     task=Task.get_task(tid)
     if task is not None:
         self.execution_context["start_time"]=self.start_time
         self.execution_context["worker_ids"]=self.worker_ids
         task.context["execution_context"]=self.execution_context
         DBSession.add(task)
         WRK_LOGGER.debug("in update_execution_context updated Parent task : "+str(tid))
开发者ID:RDTeam,项目名称:openconvirt,代码行数:15,代码来源:WorkManager.py

示例7: get_lock

# 需要导入模块: from convirt.model import DBSession [as 别名]
# 或者: from convirt.model.DBSession import add [as 别名]
    def get_lock(self,sub_system,entity_id,operation,table_name):
        # select query with lock 
        lock_m=DBSession.query(CMS_Locks).with_lockmode("update").\
            filter(CMS_Locks.sub_system==sub_system).\
            filter(CMS_Locks.entity_id==entity_id).\
            filter(CMS_Locks.operation==operation).\
            filter(CMS_Locks.table_name==table_name).all()
#        lock_m=DBSession.query(CMS_Locks).with_lockmode("update").\
#            filter(CMS_Locks.table_name==table_name).first()

        if len(lock_m) == 0:
            lm=CMS_Locks(sub_system,entity_id,operation,table_name)
            DBSession.add(lm)
开发者ID:RDTeam,项目名称:openconvirt,代码行数:15,代码来源:LockManager.py

示例8: send_deployment_stats

# 需要导入模块: from convirt.model import DBSession [as 别名]
# 或者: from convirt.model.DBSession import add [as 别名]
    def send_deployment_stats(self):
        #task_service = self.svc_central.get_service(self.task_service_id)

        t = SendDeploymentStatsTask(u'Send Deployment Stats', {'quiet':True}, [],\
                        dict(), None, u'admin')
        dc_ent = DBSession.query(Entity).filter(Entity.type_id==1).first()
        t.set_entity_info(dc_ent)
        t.set_interval(TaskInterval(interval=None,
                                       next_execution=datetime.utcnow()))
        DBSession.add(t)
        import transaction
        transaction.commit()
        logger.debug("SendDeploymentStatsTask Submitted")
        return t.task_id
开发者ID:RDTeam,项目名称:openconvirt,代码行数:16,代码来源:TaskCreator.py

示例9: exec_task

# 需要导入模块: from convirt.model import DBSession [as 别名]
# 或者: from convirt.model.DBSession import add [as 别名]
 def exec_task(self, auth, ctx):
     manager = Basic.getGridManager()
     groups = manager.getGroupList(auth)
     for group in groups:
         nodes = manager.getNodeList(auth, group.id)
         for n in nodes:
             try:
                 transaction.begin()
                 n=DBSession.query(ManagedNode).filter(ManagedNode.id==n.id).one()
                 n.refresh_environ()
                 n.get_running_vms()
                 n.socket=n.get_socket_info()
                 DBSession.add(n)
                 transaction.commit()
             except Exception, e:
                 LOGGER.error(to_str(e))
                 DBSession.rollback()
开发者ID:RDTeam,项目名称:openconvirt,代码行数:19,代码来源:tasks.py

示例10: save_email_setup_details

# 需要导入模块: from convirt.model import DBSession [as 别名]
# 或者: from convirt.model.DBSession import add [as 别名]
    def save_email_setup_details(self, desc, servername, port, useremail, password, secure):
        SiteRecord = DBSession.query(Site).filter(Site.name == "Data Center").first()
        if SiteRecord:
            site_id = SiteRecord.id
            # check if record for same server name avoid duplicate records of same name
            EmailRecord = (
                DBSession.query(EmailSetup)
                .filter(EmailSetup.site_id == site_id)
                .filter(EmailSetup.mail_server == servername)
                .first()
            )
            if EmailRecord:
                return dict(success=True, msg="Duplicaate Record found in list")

            else:
                # Add record in EmailSetup table for site id queried
                email_setup_obj = EmailSetup(servername, desc, port, secure, site_id, useremail, password)
                DBSession.add(email_setup_obj)
                emailsetupid = email_setup_obj.getEmailSetupId()
                EmailManager().add_entity(to_unicode(servername), emailsetupid, to_unicode(constants.EMAIL), None)
                return dict(success=True, msg="New Record Added Sucessfully")
开发者ID:hewei-chn,项目名称:openconvirt,代码行数:23,代码来源:EmailService.py

示例11: update

# 需要导入模块: from convirt.model import DBSession [as 别名]
# 或者: from convirt.model.DBSession import add [as 别名]
 def update(self,obj):
     DBSession.add(obj)
开发者ID:RDTeam,项目名称:openconvirt,代码行数:4,代码来源:DBHelper.py

示例12: add

# 需要导入模块: from convirt.model import DBSession [as 别名]
# 或者: from convirt.model.DBSession import add [as 别名]
 def add(self,obj):
     DBSession.add(obj)
开发者ID:RDTeam,项目名称:openconvirt,代码行数:4,代码来源:DBHelper.py

示例13: add_defn

# 需要导入模块: from convirt.model import DBSession [as 别名]
# 或者: from convirt.model.DBSession import add [as 别名]
    def add_defn(self, defn, site, group, node, auth, defType, op, action_op, def_manager, grid_manager, op_level, sp_ids=None, scan_result=None):
        #Get definition scope here
        scope = op_level

        #Check privileges
        if scope == constants.SCOPE_S:
            entityId = node.id
        elif scope == constants.SCOPE_SP:
            entityId = group.id
        elif scope == constants.SCOPE_DC:
            entityId = site.id
        
        ent = auth.get_entity(entityId)
        if not auth.has_privilege(action_op, ent):
            raise Exception(constants.NO_PRIVILEGE)

        #Save definition
        DBSession.add(defn)
        #update storage stats and storage disks table with the disks here
        #The change is for following issue.
        #Exception: The transaction is inactive due to a rollback in a subtransaction.  Issue rollback() to cancel the transaction.
        def_manager.SaveScanResult(defn.id, grid_manager, scan_result, site.id)
        #remove scan result from session
        def_manager.RemoveScanResult(scan_result)
        
        errs = []
        details = None
        status = to_unicode(constants.OUT_OF_SYNC)
        
        #Save server and network definition link details
        if scope == constants.SCOPE_DC:               #data center level
            #Add definition to dcdeflinks table since the definition scope is DC.
            #there is no server linked with this definition so the oos_count is zero.
            #since oos_count is zero, we need to keep status as IN_SYNC
            oos_count = 0
            status = to_unicode(constants.IN_SYNC)
            self.add_site_defn(site.id, defn.id, defType, status, oos_count)
            
            #associate definition to selected server pools. 
            def_manager.manage_defn_to_groups(site, group, sp_ids, defn, defType, op, def_manager, auth, errs, grid_manager)
        elif scope == constants.SCOPE_SP:               #server pool level
            node_entities = auth.get_entities(to_unicode(constants.MANAGED_NODE), ent)
            for eachnode in node_entities:
                self.add_node_defn(eachnode.entity_id, defn.id, defType, status, details)
            
            #Add definition to deflinks table only when the definition scope is SP.
            oos_count = len(node_entities)
            status = to_unicode(constants.OUT_OF_SYNC)
            self.add_group_defn(group.id, defn.id, defType, status, oos_count)
        elif scope == constants.SCOPE_S:            
            self.add_node_defn(node.id, defn.id, defType, status, details)
            op = constants.ATTACH
            update_status=True
            errs=[]
            def_manager.sync_node_defn(node, group.id, site.id, defn, defType, op, def_manager, update_status, errs)
            
        #compute storage stats
        def_manager.Recompute(defn)

        if errs:
            if len(errs) > 0:
                LOGGER.error("Error:" + to_str(errs))
        
        return errs
开发者ID:RDTeam,项目名称:openconvirt,代码行数:66,代码来源:SyncDefinition.py


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