def promote_instances(self, request, queryset):
"""
Promote transmitted PostgreSQL replication instances to master state
"""
if request.POST.get('post') == 'yes':
for inst_id in request.POST.getlist(admin.ACTION_CHECKBOX_NAME):
inst = Instance.objects.get(pk=inst_id)
try:
util = PGUtility(inst)
util.promote()
except Exception, e:
self.message_user(request, "%s : %s" % (e, inst), messages.ERROR)
continue
self.message_user(request, "%s promoted to read/write!" % inst)
return
# Now go to the confirmation form. It's very basic, and only serves
# to disrupt the process and avoid accidental promotions that would
# necessitate a resync.
queryset = queryset.exclude(master_id__isnull=True)
if queryset.count() < 1:
self.message_user(request, "No valid replicas to promte!", messages.WARNING)
return
return render(request, 'admin/haas/instance/promote.html',
{'queryset' : queryset,
'opts': self.model._meta,
'action_checkbox_name': admin.ACTION_CHECKBOX_NAME,
}
)
评论列表
文章目录