Пример #1
0
    def create(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        site = serializer.validated_data.get("site")
        oper_version = serializer.validated_data.get("oper_version")

        if site.deploy_status:
            return response.Response(status=409)

        if oper_version == site.online_version:
            return response.Response(status=400)

        #
        oper = serializer.save()

        site.deploy_status = True
        site.save()

        oper.deploy_status = 1
        oper.save()

        #
        threading.Thread(target=Action().publish, args=(oper, site)).start()

        headers = self.get_success_headers(serializer.data)
        return response.Response(serializer.data,
                                 status=status.HTTP_201_CREATED,
                                 headers=headers)
Пример #2
0
    def destroy(self, request, *args, **kwargs):
        instance = self.get_object()
        site = instance.site
        self.perform_destroy(instance)

        threading.Thread(target=Action().webserver_offline, args=(site,)).start()

        return response.Response(status=status.HTTP_204_NO_CONTENT)
Пример #3
0
    def partial_update(self, request, *args, **kwargs):
        oper = self.get_object()
        if not oper.oper_status == 1:
            return response.Response(status=400)

        if oper.deploy_status:
            return response.Response(status=409)

        oper.deploy_status = 2
        oper.save()

        #
        threading.Thread(target=Action().rollback,
                         args=(oper, oper.site)).start()

        return response.Response(status=status.HTTP_202_ACCEPTED)
Пример #4
0
    def create(self, request, *args, **kwargs):
        project_name = request.data.get("project", {}).get("name")
        if not project_name:
            return response.Response(status=400)

        site = Site.objects.filter(project=project_name).first()
        if not site:
            return response.Response(status=404)

        commits = request.data.get("commits", [])
        if not commits or not isinstance(commits, list):
            return response.Response(status=400)

        try:
            Action().flush_commits(site, commits)
        except Exception as e:
            return response.Response(status=400)

        return response.Response()
Пример #5
0
    def destroy(self, request, *args, **kwargs):
        oper = self.get_object()
        if not oper.oper_status == 2:
            return response.Response(status=400)

        site = oper.site
        if site.deploy_status:
            return response.Response(status=409)

        if oper.deploy_status:
            return response.Response(status=409)

        oper.deploy_status = 2
        oper.save()

        site.deploy_status = True
        site.save()

        #
        threading.Thread(target=Action().rollback,
                         args=(oper, site, True)).start()

        return response.Response(status=status.HTTP_202_ACCEPTED)
Пример #6
0
    def create(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        # 判断项目是否存在
        project_name = serializer.validated_data.get("project")
        project = gl.get_project(project_name)
        if not project:
            return response.Response(
                "Project '{}' does not exist.".format(project_name),
                status=status.HTTP_400_BAD_REQUEST)

        site = serializer.save()

        # 初始化项目
        threading.Thread(target=Action().init_project,
                         args=(site, project)).start()

        #
        headers = self.get_success_headers(serializer.data)
        return response.Response(serializer.data,
                                 status=status.HTTP_201_CREATED,
                                 headers=headers)