instance.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:elephaas 作者: peak6 项目源码 文件源码
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,
                }
        )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号