示例#1
0
 def validate_structure(self, attrs, source):
     """
     Check that the structure JSON dict has non-negative ints as its values.
     """
     value = attrs[source]
     models.validate_app_structure(value)
     return attrs
示例#2
0
 def validate_structure(self, attrs, source):
     """
     Check that the structure JSON dict has non-negative ints as its values.
     """
     value = attrs[source]
     models.validate_app_structure(value)
     return attrs
示例#3
0
 def scale(self, request, **kwargs):
     new_structure = {}
     app = self.get_object()
     try:
         for target, count in request.data.items():
             new_structure[target] = int(count)
         models.validate_app_structure(new_structure)
         app.scale(request.user, new_structure)
     except (TypeError, ValueError) as e:
         return Response({"detail": "Invalid scaling format: {}".format(e)}, status=status.HTTP_400_BAD_REQUEST)
     except (EnvironmentError, ValidationError) as e:
         return Response({"detail": str(e)}, status=status.HTTP_400_BAD_REQUEST)
     except RuntimeError as e:
         return Response({"detail": str(e)}, status=status.HTTP_503_SERVICE_UNAVAILABLE)
     return Response(status=status.HTTP_204_NO_CONTENT)
示例#4
0
 def scale(self, request, **kwargs):
     new_structure = {}
     app = self.get_object()
     try:
         for target, count in request.data.items():
             new_structure[target] = int(count)
         models.validate_app_structure(new_structure)
         app.scale(request.user, new_structure)
     except (TypeError, ValueError):
         return Response({'detail': 'Invalid scaling format'},
                         status=status.HTTP_400_BAD_REQUEST)
     except (EnvironmentError, ValidationError) as e:
         return Response({'detail': str(e)}, status=status.HTTP_400_BAD_REQUEST)
     except RuntimeError as e:
         return Response({'detail': str(e)}, status=status.HTTP_503_SERVICE_UNAVAILABLE)
     return Response(status=status.HTTP_204_NO_CONTENT)
示例#5
0
 def scale(self, request, **kwargs):
     new_structure = {}
     try:
         for target, count in request.DATA.items():
             new_structure[target] = int(count)
     except (TypeError, ValueError):
         return Response('Invalid scaling format',
                         status=status.HTTP_400_BAD_REQUEST)
     app = self.get_object()
     try:
         models.validate_app_structure(new_structure)
         app.scale(request.user, new_structure)
     except (EnvironmentError, ValidationError) as e:
         return Response(str(e), status=status.HTTP_400_BAD_REQUEST)
     return Response(status=status.HTTP_204_NO_CONTENT,
                     content_type='application/json')
示例#6
0
文件: views.py 项目: Mistobaan/deis
 def scale(self, request, **kwargs):
     new_structure = {}
     try:
         for target, count in request.DATA.items():
             new_structure[target] = int(count)
     except (TypeError, ValueError):
         return Response('Invalid scaling format',
                         status=status.HTTP_400_BAD_REQUEST)
     app = self.get_object()
     try:
         models.validate_app_structure(new_structure)
         app.scale(request.user, new_structure)
     except (EnvironmentError, ValidationError) as e:
         return Response(str(e), status=status.HTTP_400_BAD_REQUEST)
     return Response(status=status.HTTP_204_NO_CONTENT,
                     content_type='application/json')