本文整理汇总了Python中model.Model.getLvsManagerPublishLastRev方法的典型用法代码示例。如果您正苦于以下问题:Python Model.getLvsManagerPublishLastRev方法的具体用法?Python Model.getLvsManagerPublishLastRev怎么用?Python Model.getLvsManagerPublishLastRev使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Model
的用法示例。
在下文中一共展示了Model.getLvsManagerPublishLastRev方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import getLvsManagerPublishLastRev [as 别名]
def get(self):
'''
获取 lvs集群的信息
@parm id= cluster的id
返回 lvscluterid vip:port 业务用途 负责人 机房 邮件地址 协议
'''
id = self.get_argument('id',None)
if not id: raise tornado.web.HTTPError(500, 'please provide cluster id')
handler = Model('LvsManagerPublish')
_clusters = handler.getLvsManagerPublishLastRev(id)
if not _clusters: raise tornado.web.HTTPError(500, 'cluster id is not exsits')
cluster_keys = ['area','cluster_id']
server_keys = ['mailto','owners','protocol','vip_group','descript']
def _update(server):
my_dict = {}
for key in server_keys:
my_dict[key] = server[key]
return my_dict
_server = map(_update,_clusters['server'])
cluster = dict(map(lambda x: (x,_clusters[x]) ,cluster_keys))
cluster['server'] = _server
self.write(json.dumps(cluster,sort_keys=False, indent=4, separators=(',', ': ')))
self.finish()
示例2: get
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import getLvsManagerPublishLastRev [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)
示例3: post
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import getLvsManagerPublishLastRev [as 别名]
def post(self):
'''
run roll back action
'''
data = tornado.escape.json_decode(self.request.body)
id = data['id']
message = data['mess']
time_now = time.time()
handler = Model('LvsManagerPublish')
#获取需要rollbak的版本的记录
rollback_record = handler.getLvsManagerPublishOne(id)
cluster_id = rollback_record['cluster_id']
vipinstancelist = rollback_record['server']
area = search_cluster(cluster_id)['area']
admin_mail_group = search_cluster(cluster_id)['admin_mail_group']
#把rollbak的版本替换到现在的配置信息上
##把此集群现有的配置信息先清空
handler.removeLvsManagerConifghForCluster(cluster_id)
##把rollback的配置信息insert进去
for vipinstance in vipinstancelist:
vipinstance["_id"] = ObjectId(vipinstance["_id"])
handler.insertLvsManagerConfigVipInstance(vipinstance)
#获取最新的版本号,如果没有则为1
last_rev = handler.getLvsManagerPublishLastRev(cluster_id)
if last_rev:
rev = last_rev['rev'] + 1
else:
rev = 1
#insert发布记录
for i in vipinstancelist:
i['_id'] = str(i['_id'])
lvsmanagerpublish = {"time":time_now,"message":message,"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
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)