• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python dispatch.pub函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中toughlib.dispatch.pub函数的典型用法代码示例。如果您正苦于以下问题:Python pub函数的具体用法?Python pub怎么用?Python pub使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: acctounting

    def acctounting(self):
        if not self.account:
            return dispatch.pub(logger.EVENT_ERROR,
                "[Acct] Received an accounting update request but user[%s] not exists"% self.request.account_number)  

        ticket = Storage(**self.request)
        _datetime = datetime.datetime.now() 
        online = self.get_online(ticket.nas_addr,ticket.acct_session_id)    
        if not online:
            session_time = ticket.acct_session_time 
            stop_time = _datetime.strftime( "%Y-%m-%d %H:%M:%S")
            start_time = (_datetime - datetime.timedelta(seconds=int(session_time))).strftime( "%Y-%m-%d %H:%M:%S")
            ticket.acct_start_time = start_time
            ticket.acct_stop_time = stop_time
            ticket.start_source= STATUS_TYPE_STOP
            ticket.stop_source = STATUS_TYPE_STOP
            self.add_ticket(ticket)
        else:
            self.del_online(ticket.nas_addr,ticket.acct_session_id)
            ticket.acct_start_time = online.acct_start_time
            ticket.acct_stop_time= _datetime.strftime( "%Y-%m-%d %H:%M:%S")
            ticket.start_source = online.start_source
            ticket.stop_source = STATUS_TYPE_STOP
            self.add_ticket(ticket)

        self.billing(online)
        dispatch.pub(logger.EVENT_INFO,'%s Accounting stop request, remove online'% self.account.account_number)
开发者ID:leigf,项目名称:ToughRADIUS,代码行数:27,代码来源:radius_acct_stop.py


示例2: error

def error(message,**kwargs):
    if not isinstance(message, unicode):
        message = safeunicode(message)
    if EVENT_ERROR in dispatch.dispatch.callbacks:
        dispatch.pub(EVENT_ERROR,message,**kwargs)
    else:
        default_log.error(message)
开发者ID:xvxieweilai,项目名称:toughlib,代码行数:7,代码来源:logger.py


示例3: render_json

 def render_json(self, **template_vars):
     if not template_vars.has_key("code"):
         template_vars["code"] = 0
     resp = json.dumps(template_vars, ensure_ascii=False)
     if self.settings.debug:
         dispatch.pub(logger.EVENT_DEBUG,"[api debug] :: %s response body: %s" % (self.request.path, utils.safeunicode(resp)))
     self.write(resp)
开发者ID:leigf,项目名称:ToughRADIUS,代码行数:7,代码来源:base.py


示例4: info

def info(message,**kwargs):
    if not isinstance(message, unicode):
        message = safeunicode(message)
    if EVENT_INFO in dispatch.dispatch.callbacks:
        dispatch.pub(EVENT_INFO,message,**kwargs)
    else:
        default_log.info(message)
开发者ID:xvxieweilai,项目名称:toughlib,代码行数:7,代码来源:logger.py


示例5: acctounting

    def acctounting(self):
        if not self.account:
            return dispatch.pub(logger.EVENT_ERROR,
                "[Acct] Received an accounting update request but user[%s] not exists"% self.request.account_number)     

        ticket = Storage(**self.request)
        online = self.get_online(ticket.nas_addr,ticket.acct_session_id)     
        if not online:         
            sessiontime = ticket.acct_session_time
            updatetime = datetime.datetime.now()
            _starttime = updatetime - datetime.timedelta(seconds=sessiontime)       
            online = Storage(
                account_number = self.account.account_number,
                nas_addr = ticket.nas_addr,
                acct_session_id = ticket.acct_session_id,
                acct_start_time = _starttime.strftime( "%Y-%m-%d %H:%M:%S"),
                framed_ipaddr = ticket.framed_ipaddr,
                mac_addr = ticket.mac_addr,
                nas_port_id = ticket.nas_port_id,
                billing_times = ticket.acct_session_time,
                input_total = self.get_input_total(),
                output_total = self.get_output_total(),
                start_source = STATUS_TYPE_UPDATE
            )
            self.add_online(online)

        self.billing(online)
        dispatch.pub(logger.EVENT_INFO,'%s Accounting update request, update online'% self.account.account_number)


        
        
开发者ID:kozora,项目名称:ToughRADIUS,代码行数:28,代码来源:radius_acct_update.py


示例6: process

    def process(self, *args, **kwargs):
        dispatch.pub(logger.EVENT_INFO, "process ddns update task..")
        with make_db(self.db) as db:
            try:
                nas_list = db.query(models.TrBas)
                for nas in nas_list:
                    if not nas.dns_name:
                        continue
                    results, _, _ = yield client.lookupAddress(nas.dns_name)
                    if not results:
                        dispatch.pub(logger.EVENT_INFO, "domain {0} resolver empty".format(nas.dns_name))

                    if results[0].type == dns.A:
                        ipaddr = ".".join(str(i) for i in struct.unpack("BBBB", results[0].payload.address))
                        if ipaddr:
                            nas.ip_addr = ipaddr
                            db.commit()
                            dispatch.pub(
                                logger.EVENT_INFO, "domain {0} resolver {1}  success".format(nas.dns_name, ipaddr)
                            )
                    else:
                        dispatch.pub(
                            logger.EVENT_INFO, "domain {0} no ip address,{1}".format(nas.dns_name, repr(results))
                        )

            except Exception as err:
                dispatch.pub(logger.EVENT_ERROR, "ddns process error %s" % utils.safeunicode(err.message))
        defer.returnValue(60)
开发者ID:leigf,项目名称:ToughRADIUS,代码行数:28,代码来源:ddns_update.py


示例7: debug

def debug(message,**kwargs):
    if not isinstance(message, unicode):
        message = safeunicode(message)
    if EVENT_DEBUG in dispatch.dispatch.callbacks:
        dispatch.pub(EVENT_DEBUG,message,**kwargs)
        if EVENT_TRACE in dispatch.dispatch.callbacks:
            dispatch.pub(EVENT_TRACE,"debug",message,**kwargs)
开发者ID:fozzmarc,项目名称:toughlib,代码行数:7,代码来源:logger.py


示例8: error

def error(message,**kwargs):
    if not isinstance(message, unicode):
        message = safeunicode(message)
    if EVENT_ERROR in dispatch.dispatch.callbacks:
        dispatch.pub(EVENT_ERROR,message,**kwargs)
        if EVENT_TRACE in dispatch.dispatch.callbacks:
            dispatch.pub(EVENT_TRACE,"error",message,**kwargs)
开发者ID:fozzmarc,项目名称:toughlib,代码行数:7,代码来源:logger.py


示例9: post

    def post(self):
        account_number = self.get_argument("account_number")
        account = self.db.query(models.TrAccount).get(account_number)
        if account.status != 2:
            return self.render_json(code=1, msg=u"用户当前状态不允许复机")

        account.status = 1
        _datetime = datetime.datetime.now()
        _pause_time = datetime.datetime.strptime(account.last_pause, "%Y-%m-%d %H:%M:%S")
        _expire_date = datetime.datetime.strptime(account.expire_date + ' 23:59:59', "%Y-%m-%d %H:%M:%S")
        days = (_expire_date - _pause_time).days
        new_expire = (_datetime + datetime.timedelta(days=int(days))).strftime("%Y-%m-%d")
        account.expire_date = new_expire

        accept_log = models.TrAcceptLog()
        accept_log.accept_type = 'resume'
        accept_log.accept_source = 'console'
        accept_log.accept_desc = u"用户复机:上网账号:%s" % (account_number)
        accept_log.account_number = account.account_number
        accept_log.accept_time = utils.get_currtime()
        accept_log.operator_name = self.current_user.username
        self.db.add(accept_log)

        self.db.commit()
        dispatch.pub(db_cache.CACHE_DELETE_EVENT,account_cache_key(account.account_number), async=True)
        return self.render_json(msg=u"操作成功")
开发者ID:Evan-hu,项目名称:ToughRADIUS,代码行数:26,代码来源:account_resume.py


示例10: info

def info(message,trace="info",**kwargs):
    if not isinstance(message, unicode):
        message = safeunicode(message)
    if EVENT_INFO in dispatch.dispatch.callbacks:
        dispatch.pub(EVENT_INFO,message,**kwargs)
        if EVENT_TRACE in dispatch.dispatch.callbacks:
            dispatch.pub(EVENT_TRACE,trace,message,**kwargs)
开发者ID:fozzmarc,项目名称:toughlib,代码行数:7,代码来源:logger.py


示例11: post

    def post(self):
        account_number = self.get_argument("account_number")
        account = self.db.query(models.TrAccount).get(account_number)

        if account.status != 1:
            return self.render_json(code=1, msg=u"用户当前状态不允许停机")

        _datetime = utils.get_currtime()
        account.last_pause = _datetime
        account.status = 2

        accept_log = models.TrAcceptLog()
        accept_log.accept_type = "pause"
        accept_log.accept_source = "console"
        accept_log.accept_desc = u"用户停机:上网账号:%s" % (account_number)
        accept_log.account_number = account.account_number
        accept_log.accept_time = _datetime
        accept_log.operator_name = self.current_user.username
        self.db.add(accept_log)

        self.db.commit()

        dispatch.pub(ACCOUNT_PAUSE_EVENT, account.account_number, async=True)
        dispatch.pub(db_cache.CACHE_DELETE_EVENT, account_cache_key(account.account_number), async=True)

        return self.render_json(msg=u"操作成功")
开发者ID:lxyjyy,项目名称:ToughRADIUS,代码行数:26,代码来源:account_pause.py


示例12: bill_botimes

    def bill_botimes(self,online, product):
        #买断时长
        logger.info('%s > Buyout long time billing ' % self.account.account_number)
        time_length = self.get_user_time_length()
        sessiontime = self.request.acct_session_time
        billing_times = online.billing_times
        acct_times = sessiontime - billing_times
        if acct_times < 0:
            acct_times = 0
        user_time_length = time_length - acct_times
        if user_time_length < 0 :
            user_time_length = 0

        self.update_billing(Storage(
            account_number = online.account_number,
            nas_addr = online.nas_addr,
            acct_session_id = online.acct_session_id,
            acct_start_time = online.acct_start_time,
            acct_session_time = self.request.acct_session_time,
            input_total = self.get_input_total(),
            output_total = self.get_output_total(),
            acct_times = acct_times,
            acct_flows = 0,
            acct_fee = 0,
            actual_fee = 0,
            balance = 0,
            time_length = user_time_length,
            flow_length = 0,
            is_deduct = 1,
            create_time = datetime.datetime.now().strftime( "%Y-%m-%d %H:%M:%S")
        ))
    
        if user_time_length == 0 :
            dispatch.pub(UNLOCK_ONLINE_EVENT,
                online.account_number,online.nas_addr, online.acct_session_id,async=True)
开发者ID:WyattShao,项目名称:ToughRADIUS,代码行数:35,代码来源:radius_billing.py


示例13: debug

def debug(message,**kwargs):
    if not isinstance(message, unicode):
        message = safeunicode(message)
    if EVENT_DEBUG in dispatch.dispatch.callbacks:
        dispatch.pub(EVENT_DEBUG,message,**kwargs)
    else:
        default_log.debug(message)
开发者ID:xvxieweilai,项目名称:toughlib,代码行数:7,代码来源:logger.py


示例14: post

    def post(self):
        try:
            request = self.parse_form_request()
            account_number = request.get('account_number')

            if not account_number:
                raise Exception("account_number is empty")

            account = self.db.query(models.TrAccount).filter_by(account_number=account_number).first()
            if not account:
                raise Exception("account is not exists")

            self.db.query(models.TrAcceptLog).filter_by(account_number=account.account_number).delete()
            self.db.query(models.TrAccountAttr).filter_by(account_number=account.account_number).delete()
            self.db.query(models.TrBilling).filter_by(account_number=account.account_number).delete()
            self.db.query(models.TrTicket).filter_by(account_number=account.account_number).delete()
            self.db.query(models.TrOnline).filter_by(account_number=account.account_number).delete()
            self.db.query(models.TrAccount).filter_by(account_number=account.account_number).delete()
            self.db.query(models.TrCustomerOrder).filter_by(account_number=account.account_number).delete()
            self.add_oplog(u'API删除用户账号%s' % (account.account_number))
            self.db.commit()
            dispatch.pub(ACCOUNT_DELETE_EVENT, account.account_number, async=True)
            dispatch.pub(cache.CACHE_DELETE_EVENT,account_cache_key(account.account_number), async=True) 
            return self.render_result(code=0, msg='success')
        except Exception as err:
            self.render_result(code=1, msg=utils.safeunicode(err.message))
            import traceback
            traceback.print_exc()
            return
开发者ID:Evan-hu,项目名称:ToughRADIUS,代码行数:29,代码来源:api_account_delete.py


示例15: bill_boflows

 def bill_boflows(self, online, product):
     #买断流量
     dispatch.pub(logger.EVENT_INFO,'%s > Buyout flow billing ' % self.account.account_number)
     flow_length = self.get_user_flow_length()
     output_total = self.get_output_total()
     billing_output_total = online.output_total
     acct_flows = output_total - billing_output_total
     user_flow_length = flow_length - acct_flows
     if user_flow_length < 0 :
         user_flow_length = 0
         
     self.update_billing(Storage(
         account_number = online.account_number,
         nas_addr = online.nas_addr,
         acct_session_id = online.acct_session_id,
         acct_start_time = online.acct_start_time,
         acct_session_time = self.request.acct_session_time,
         input_total = self.get_input_total(),
         output_total = self.get_output_total(),
         acct_times = 0,
         acct_flows = acct_flows,
         acct_fee = 0,
         actual_fee = 0,
         balance = 0,
         time_length = 0,
         flow_length = user_flow_length,
         is_deduct = 1,
         create_time = datetime.datetime.now().strftime( "%Y-%m-%d %H:%M:%S")
     ))
     
     if user_flow_length == 0 :
         self.disconnect(online)
开发者ID:leigf,项目名称:ToughRADIUS,代码行数:32,代码来源:radius_billing.py


示例16: acctounting

    def acctounting(self):
        self.unlock_online(self.request.nas_addr,None)
        dispatch.pub(logger.EVENT_INFO,'bas accounting onoff success')


        
        
开发者ID:leigf,项目名称:ToughRADIUS,代码行数:3,代码来源:radius_acct_onoff.py


示例17: post

 def post(self):
     self.settings.config['syslog']['enable'] = int(self.get_argument("enable"))
     self.settings.config['syslog']['server'] = self.get_argument("server")
     self.settings.config['syslog']['port'] = int(self.get_argument("port",514))
     self.settings.config['syslog']['level'] = self.get_argument("level")
     self.settings.config.save()
     dispatch.pub(logger.EVENT_SETUP,self.settings.config)
     self.redirect("/admin/config?active=syslog")
开发者ID:YMXZ,项目名称:ToughRADIUS,代码行数:8,代码来源:config.py


示例18: post

 def post(self):
     backup_path = self.settings.config.database.backup_path
     backup_file = "toughradius_db_%s.json.gz" % utils.gen_backep_id()
     try:
         self.db_backup.dumpdb(os.path.join(backup_path, backup_file))
         return self.render_json(code=0, msg="backup done!")
     except Exception as err:
         dispatch.pub(logger.EVENT_EXCEPTION,err)
         return self.render_json(code=1, msg="backup fail! %s" % (err))
开发者ID:Evan-hu,项目名称:ToughRADIUS,代码行数:9,代码来源:backup.py


示例19: post

 def post(self):
     account_number = self.get_argument('account_number')  
     user = self.db.query(models.TrAccount).filter_by(account_number=account_number).first()
     user.mac_addr = ''
     user.vlan_id1 = 0
     user.vlan_id2 = 0
     self.add_oplog(u'释放用户账号(%s)绑定信息'%(account_number))
     self.db.commit()
     dispatch.pub(settings.CACHE_DELETE_EVENT,account_cache_key(account_number), async=True)
     return self.render_json(msg=u"解绑成功")
开发者ID:WyattShao,项目名称:ToughRADIUS,代码行数:10,代码来源:account_release.py


示例20: get

    def get(self):
        bas_id = self.get_argument("bas_id")
        basip = self.db.query(models.TrBas).get(form.d.id).ip_addr
        self.db.query(models.TrBas).filter_by(id=bas_id).delete()

        self.add_oplog(u'删除接入设备信息:%s' % bas_id)

        self.db.commit()
        dispatch.pub(redis_cache.CACHE_DELETE_EVENT,bas_cache_key(basip), async=True)
        self.redirect("/admin/bas",permanent=False)
开发者ID:LWHTarena,项目名称:ToughRADIUS,代码行数:10,代码来源:bas.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python logger.error函数代码示例发布时间:2022-05-27
下一篇:
Python dbengine.get_engine函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap