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
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)
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)
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')