Пример #1
0
 def post(self, request, app_id, *args, **kwargs):
     sos = ServiceGroupOperationsSerializer(data=request.data)
     sos.is_valid(raise_exception=True)
     app = group_service.get_app_by_id(self.team, self.region_name, app_id)
     if not app:
         raise ErrAppNotFound
     service_ids = sos.data.get("service_ids", None)
     if not service_ids or len(service_ids) == 0:
         service_ids = app_service.get_group_services_by_id(app_id)
     # TODO: Check the amount of resources used
     action = sos.data.get("action")
     if action == "stop":
         self.has_perms([300006, 400008])
     if action == "start":
         self.has_perms([300005, 400006])
     if action == "upgrade":
         self.has_perms([300007, 400009])
     if action == "deploy":
         self.has_perms([300008, 400010])
     code, msg = app_manage_service.batch_operations(self.team, request.user, action, service_ids, None)
     if code != 200:
         result = {"msg": "batch operation error"}
         rst_serializer = FailSerializer(data=result)
         rst_serializer.is_valid()
         return Response(rst_serializer.data, status=status.HTTP_400_BAD_REQUEST)
     else:
         result = {"msg": msg}
         rst_serializer = SuccessSerializer(data=result)
         rst_serializer.is_valid()
         return Response(rst_serializer.data, status=status.HTTP_200_OK)
Пример #2
0
 def post(self, request, app_id, *args, **kwargs):
     try:
         serializers = ServiceGroupOperationsSerializer(data=request.data)
         serializers.is_valid(raise_exception=True)
     except ValidationError as e:
         logger.debug(e)
         result = {"msg": "请求参数错误"}
         rst_serializer = FailSerializer(data=result)
         rst_serializer.is_valid()
         return Response(rst_serializer.data,
                         status=status.HTTP_400_BAD_REQUEST)
     tenant, service_ids = app_service.get_group_services_by_id(app_id)
     if tenant:
         code, msg = app_service.group_services_operation(
             tenant, serializers.data.get("action"), service_ids)
         if code != 200:
             result = {"msg": "batch manage error"}
             rst_serializer = FailSerializer(data=result)
             rst_serializer.is_valid()
             return Response(rst_serializer.data,
                             status=status.HTTP_400_BAD_REQUEST)
         else:
             result = {"msg": "操作成功"}
             rst_serializer = SuccessSerializer(data=result)
             rst_serializer.is_valid()
             return Response(rst_serializer.data, status=status.HTTP_200_OK)
     else:
         result = {"msg": "该应用所属团队已被删除"}
         rst_serializer = FailSerializer(data=result)
         rst_serializer.is_valid()
     return Response(rst_serializer.data, status=status.HTTP_404_NOT_FOUND)