Beispiel #1
0
    def put(self, request, *args, **kwargs):
        """
        服务端口自定义二级域名
        ---
        parameters:
            - name: tenantName
              description: 团队名
              required: true
              type: string
              paramType: path
            - name: serviceAlias
              description: 服务别名
              required: true
              type: string
              paramType: path
            - name: domain_name
              description: 域名
              required: true
              type: string
              paramType: form
            - name: container_port
              description: 服务端口
              required: true
              type: string
              paramType: form

        """
        try:
            container_port = request.data.get("container_port", None)
            domain_name = request.data.get("domain_name", None)
            if not container_port or not domain_name:
                return Response(general_message(400, "params error", "参数错误"), status=400)
            container_port = int(container_port)
            sld_domains = domain_service.get_sld_domains(self.service, container_port)
            if not sld_domains:

                code, msg = domain_service.bind_domain(self.tenant, self.user, self.service, domain_name, container_port,
                                                       "http", None, DomainType.SLD_DOMAIN)
                if code != 200:
                    return Response(general_message(code, "bind domain error", msg), status=code)
            else:
                # 先解绑 再绑定
                code, msg = domain_service.unbind_domain(self.tenant, self.service, container_port, sld_domains[0].domain_name, is_tcp=False)
                if code != 200:
                    return Response(general_message(code, "unbind domain error", msg), status=code)
                domain_service.bind_domain(self.tenant, self.user, self.service, domain_name, container_port,
                                           "http", None, DomainType.SLD_DOMAIN)

            result = general_message(200, "success", "二级域名修改成功")
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
        return Response(result, status=result["code"])
    def delete(self, request, *args, **kwargs):
        """
        服务端口解绑域名
        ---
        parameters:
            - name: tenantName
              description: 团队名
              required: true
              type: string
              paramType: path
            - name: serviceAlias
              description: 服务别名
              required: true
              type: string
              paramType: path
            - name: domain_name
              description: 域名
              required: true
              type: string
              paramType: form
            - name: container_port
              description: 服务端口
              required: true
              type: string
              paramType: form

        """
        try:
            container_port = request.data.get("container_port", None)
            domain_name = request.data.get("domain_name", None)
            is_tcp = request.data.get("is_tcp", False)
            if not container_port or not domain_name:
                return Response(general_message(400, "params error", "参数错误"),
                                status=400)
            code, msg = domain_service.unbind_domain(self.tenant, self.service,
                                                     container_port,
                                                     domain_name, is_tcp)
            if code != 200:
                return Response(general_message(code, "delete domain error",
                                                msg),
                                status=code)
            result = general_message(200, "success", "域名解绑成功")
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
        return Response(result, status=result["code"])