示例#1
0
    def post(self, request, *args, **kwargs):
        """
        批量操作服务
        ---
        parameters:
            - name: tenantName
              description: 租户名
              required: true
              type: string
              paramType: path
            - name: action
              description: 操作名称 stop| start|restart
              required: true
              type: string
              paramType: form
            - name: service_ids
              description: 批量操作的服务ID 多个以英文逗号分隔
              required: true
              type: string
              paramType: form

        """
        try:
            action = request.data.get("action", None)
            service_ids = request.data.get("service_ids", None)
            if action not in ("stop", "start", "restart"):
                return Response(general_message(400, "param error", "操作类型错误"),
                                status=400)
            identitys = team_services.get_user_perm_identitys_in_permtenant(
                user_id=self.user.user_id, tenant_name=self.tenant_name)
            perm_tuple = team_services.get_user_perm_in_tenant(
                user_id=self.user.user_id, tenant_name=self.tenant_name)

            if action == "stop":
                if "stop_service" not in perm_tuple and "owner" not in identitys and "admin" not in identitys and "developer" not in identitys:
                    return Response(general_message(400, "Permission denied",
                                                    "没有关闭应用权限"),
                                    status=400)
            if action == "start":
                if "start_service" not in perm_tuple and "owner" not in identitys and "admin" not in identitys and "developer" not in identitys:
                    return Response(general_message(400, "Permission denied",
                                                    "没有启动应用权限"),
                                    status=400)
            if action == "restart":
                if "restart_service" not in perm_tuple and "owner" not in identitys and "admin" not in identitys and "developer" not in identitys:
                    return Response(general_message(400, "Permission denied",
                                                    "没有重启应用权限"),
                                    status=400)

            service_id_list = service_ids.split(",")
            code, msg = app_manage_service.batch_action(
                self.tenant, self.user, action, service_id_list)
            if code != 200:
                result = general_message(code, "batch manage error", msg)
            else:
                result = general_message(200, "success", "操作成功")
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
        return Response(result, status=result["code"])
    def post(self, request, *args, **kwargs):
        """
        批量操作组件
        ---
        parameters:
            - name: tenantName
              description: 租户名
              required: true
              type: string
              paramType: path
            - name: action
              description: 操作名称 stop| start|restart|delete|move|upgrade|deploy
              required: true
              type: string
              paramType: form
            - name: service_ids
              description: 批量操作的组件ID 多个以英文逗号分隔
              required: true
              type: string
              paramType: form

        """
        action = request.data.get("action", None)
        service_ids = request.data.get("service_ids", None)
        move_group_id = request.data.get("move_group_id", None)
        if action not in ("stop", "start", "restart", "move", "upgrade",
                          "deploy"):
            return Response(general_message(400, "param error", "操作类型错误"),
                            status=400)
        if action == "stop":
            self.has_perms([400008])
        if action == "start":
            self.has_perms([400006])
        if action == "restart":
            self.has_perms([400007])
        if action == "move":
            self.has_perms([400003])
        if action == "upgrade":
            self.has_perms([400009])
        if action == "deploy":
            self.has_perms([400010])
        service_id_list = service_ids.split(",")
        code, msg = app_manage_service.batch_action(self.region_name,
                                                    self.tenant, self.user,
                                                    action, service_id_list,
                                                    move_group_id,
                                                    self.oauth_instance)
        if code != 200:
            result = general_message(code, "batch manage error", msg)
        else:
            result = general_message(200, "success", "操作成功")
        return Response(result, status=result["code"])
示例#3
0
 def post(self, request, team_id, region_name, *args, **kwargs):
     serializers = TeamAppsCloseSerializers(data=request.data)
     serializers.is_valid(raise_exception=True)
     service_id_list = serializers.data.get("service_ids", None)
     services = service_repo.get_tenant_region_services(self.region_name, self.team.tenant_id)
     if not services:
         return Response(None, status=200)
     service_ids = services.values_list("service_id", flat=True)
     if service_id_list:
         service_ids = list(set(service_ids) & set(service_id_list))
     code, msg = app_manage_service.batch_action(self.region_name, self.team, self.user, "stop", service_ids, None,
                                                 self.oauth_instance)
     if code != 200:
         raise ServiceHandleException(status_code=code, msg="batch manage error", msg_show=msg)
     return Response(None, status=200)
示例#4
0
    def post(self, request, *args, **kwargs):
        """
        批量操作服务
        ---
        parameters:
            - name: tenantName
              description: 租户名
              required: true
              type: string
              paramType: path
            - name: action
              description: 操作名称 stop| start|restart
              required: true
              type: string
              paramType: form
            - name: service_ids
              description: 批量操作的服务ID 多个以英文逗号分隔
              required: true
              type: string
              paramType: form

        """
        try:
            action = request.data.get("action", None)
            service_ids = request.data.get("service_ids", None)
            if action not in ("stop", "start", "restart"):
                return Response(general_message(400, "param error", "操作类型错误"),
                                status=400)
            service_id_list = service_ids.split(",")
            code, msg = app_manage_service.batch_action(
                self.tenant, self.user, action, service_id_list)
            if code != 200:
                result = general_message(code, "batch manage error", msg)
            else:
                result = general_message(200, "success", "操作成功")
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
        return Response(result, status=result["code"])
示例#5
0
    def post(self, request, *args, **kwargs):
        """
        ---
        parameters:
            - name: tenantName
              description: 租户名
              required: true
              type: string
              paramType: path
            - name: action
              description: 操作名称 stop| start|restart|deploy
              required: true
              type: string
              paramType: form
            - name: group_id
              description: 组id
              required: true
              type: string
              paramType: path

        """
        try:
            action = request.data.get("action", None)

            group_id = int(kwargs.get("group_id", None))
            services = group_service_relation_repo.get_services_obj_by_group(
                group_id)
            if not services:
                result = general_message(400, "not service", "当前组内无应用,无法操作")
                return Response(result)

            if action not in ("stop", "start", "restart", "deploy"):
                return Response(general_message(400, "param error", "操作类型错误"),
                                status=400)
            # 校验权限
            identitys = team_services.get_user_perm_identitys_in_permtenant(
                user_id=self.user.user_id, tenant_name=self.tenant_name)
            perm_tuple = team_services.get_user_perm_in_tenant(
                user_id=self.user.user_id, tenant_name=self.tenant_name)

            if action == "stop":
                if "stop_service" not in perm_tuple and "owner" not in identitys and "admin" not in identitys and "developer" not in identitys:
                    return Response(general_message(400, "Permission denied",
                                                    "没有关闭应用权限"),
                                    status=400)
            if action == "start":
                if "start_service" not in perm_tuple and "owner" not in identitys and "admin" not in identitys and "developer" not in identitys:
                    return Response(general_message(400, "Permission denied",
                                                    "没有启动应用权限"),
                                    status=400)
            if action == "restart":
                if "restart_service" not in perm_tuple and "owner" not in identitys and "admin" not in identitys and "developer" not in identitys:
                    return Response(general_message(400, "Permission denied",
                                                    "没有重启应用权限"),
                                    status=400)
            if action == "deploy":
                if "deploy_service" not in perm_tuple and "owner" not in identitys and "admin" not in identitys and "developer" not in identitys:
                    return Response(general_message(400, "Permission denied",
                                                    "没有重新构建权限"),
                                    status=400)
            # 构建service_ids列表
            service_id_list = []
            for service in services:
                service_id_list.append(service.service_id)
                # 批量操作
            code, msg = app_manage_service.batch_action(self.tenant,
                                                        self.user,
                                                        action,
                                                        service_id_list,
                                                        move_group_id=None)
            if code != 200:
                result = general_message(code, "batch manage error", msg)
            else:
                result = general_message(200, "success", "操作成功")

        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
        return Response(result, status=result["code"])