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


Python Model.getLvsManagerConfigVipInstanceList方法代码示例

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


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

示例1: get

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import getLvsManagerConfigVipInstanceList [as 别名]
 def get(self):
     '''
     run publish action
     '''
     time_now = time.time()
     cluster_id = self.get_argument("id",None)
     mess = self.get_argument("mess",None)
     area = search_cluster(cluster_id)['area']
     admin_mail_group = search_cluster(cluster_id)['admin_mail_group']
     handler = Model('LvsManagerConfig')
     vipinstancelist = handler.getLvsManagerConfigVipInstanceList(cluster_id)
     _vipinstancelist = handler.getLvsManagerConfigVipInstanceList(cluster_id)
     for i in _vipinstancelist:
         i["_id"] = str(i["_id"])
     if len(vipinstancelist) == 0:
         self.write('不存配置文件,停止发布')
     else:
         handler = Model('LvsManagerPublish')
         #获取最新的版本号,如果没有则为1
         last_rev = handler.getLvsManagerPublishLastRev(cluster_id)
         if last_rev:
             rev = last_rev['rev'] + 1
         else:
             rev = 1
         #insert发布记录
         lvsmanagerpublish = {"time":time_now,"message":mess,"cluster_id":cluster_id,"rev":rev,"server":_vipinstancelist,"area":area,"admin_mail_group":admin_mail_group}
         context = yaml.dump(lvsmanagerpublish)
         new_publish_id = handler.insertLvsManagerPublish(lvsmanagerpublish)
         #创建keepalived配置文件
         keepalived_config = self.template('keepalived.tpl',vip_instance_list = vipinstancelist, cluster_id = cluster_id)
         publishdir = options.publishdir
         keepalived_config_file = os.path.join(publishdir,new_publish_id)
         f = codecs.open(keepalived_config_file,'w+','utf-8')
         f.write(keepalived_config)
         f.close()
         #调用saltstack,传送配置
         config = yaml.load(open(options.config))
         tgt = search_cluster(cluster_id)['agent']
         source_file = keepalived_config_file
         dst_file = '/etc/keepalived/keepalived.conf'
         runsalt = saltstackwork()
         result = runsalt.run_publish_keepalived(tgt, source_file,dst_file)
         #publish info.yaml
         info_source_file = 'info.yaml'
         info_dst_file = '/etc/keepalived/info.yaml'
         result2 = runsalt.run_cp_file(tgt, info_source_file, info_dst_file, context)
         ret_html = ''
         ret_result = True
         print result2
         print result
         for lb in tgt:
             if result.has_key(lb) & result2.has_key(lb):
                 ret_html += '%s ok\n' %(lb)
             else:
                 ret_html += '%s failed\n' %(lb)
                 ret_result = False
         #更新发布结构
         handler.updateLvsManagerPublishResult(new_publish_id,ret_result)
         self.write(ret_html)
开发者ID:sjqzhang,项目名称:lvs-manager,代码行数:61,代码来源:control.py

示例2: post

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import getLvsManagerConfigVipInstanceList [as 别名]
    def post(self):
        id = self.get_argument("id",None)
        keyword = self.get_argument("keyword","")
        handler = Model('LvsManagerConfig')
        vipinstanceinfo = handler.getLvsManagerConfigVipInstanceList(id)

        def build(vipinstanceinfo):
            for row in vipinstanceinfo:
                for k,v in row.items():
                    if k=='vip_group':
                        rs=[]
                        for r in v:
                            rs.append(r['vip']+':'+r['port'])
                        row[k]="<br>".join(rs)
                    else:
                        if isinstance(v,unicode):
                            row[k]=str(v.encode('utf-8'))
                        else:
                            row[k]=str(v)
            return  json.dumps(vipinstanceinfo)

        result=[]
        for row in vipinstanceinfo:
            if str(row['descript']).find(keyword)!=-1:
                result.append(row)
        ret=""
        if len(result)>0:
            ret=build(result)
        else:
            ret=build(vipinstanceinfo)
        self.write(ret)
开发者ID:sjqzhang,项目名称:lvs-manager,代码行数:33,代码来源:control.py

示例3: getLvsList

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import getLvsManagerConfigVipInstanceList [as 别名]
 def getLvsList(self,result):
     lvs=Model('LvsManagerConfig')
     result['data']=lvs.getLvsManagerConfigVipInstanceList(self.get_argument('id'))
开发者ID:sjqzhang,项目名称:lvs-manager,代码行数:5,代码来源:webapi.py


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