def get(self, *args, **kwargs): if "rtid" in self.kwargs: try: data = ReplicaTrail.objects.get(id=self.kwargs["rtid"]) serialized_data = ReplicaTrailSerializer(data) return Response(serialized_data.data) except: return Response()
def post(self, request, rid): replica = Replica.objects.get(id=rid) snap_name = request.data['snap_name'] ts = datetime.utcnow().replace(tzinfo=utc) rt = ReplicaTrail(replica=replica, snap_name=snap_name, status='pending', snapshot_created=ts) rt.save() return Response(ReplicaTrailSerializer(rt).data)
def put(self, request, rtid): rt = ReplicaTrail.objects.get(id=rtid) new_status = request.DATA['status'] if ('error' in request.DATA): rt.error = request.DATA['error'] if ('kb_sent' in request.DATA): rt.kb_sent = request.DATA['kb_sent'] if ('end_ts' in request.DATA): rt.end_ts = request.DATA['end_ts'] rt.status = new_status rt.save() return Response(ReplicaTrailSerializer(rt).data)
def post(self, request, rid): with self._handle_exception(request): replica = Replica.objects.get(id=rid) snap_name = request.data["snap_name"] ts = datetime.utcnow().replace(tzinfo=utc) rt = ReplicaTrail( replica=replica, snap_name=snap_name, status="pending", snapshot_created=ts, ) rt.save() return Response(ReplicaTrailSerializer(rt).data)
def put(self, request, rtid): with self._handle_exception(request): rt = ReplicaTrail.objects.get(id=rtid) new_status = request.data['status'] if ('error' in request.data): rt.error = request.data['error'] if ('kb_sent' in request.data): rt.kb_sent = request.data['kb_sent'] if ('end_ts' in request.data): rt.end_ts = datetime.strptime(request.data['end_ts'], settings.SNAP_TS_FORMAT).replace(tzinfo=utc) rt.status = new_status rt.save() return Response(ReplicaTrailSerializer(rt).data)
def put(self, request, rtid): with self._handle_exception(request): rt = ReplicaTrail.objects.get(id=rtid) rt.status = request.data["status"] if "error" in request.data: rt.error = request.data["error"] if "kb_sent" in request.data: rt.kb_sent = request.data["kb_sent"] if rt.status in ("failed", "succeeded",): ts = datetime.utcnow().replace(tzinfo=utc) rt.end_ts = ts if rt.status == "failed": rt.send_failed = ts rt.save() return Response(ReplicaTrailSerializer(rt).data)
def put(self, request, rtid): with self._handle_exception(request): rt = ReplicaTrail.objects.get(id=rtid) rt.status = request.data['status'] if ('error' in request.data): rt.error = request.data['error'] if ('kb_sent' in request.data): rt.kb_sent = request.data['kb_sent'] if (rt.status in ( 'failed', 'succeeded', )): ts = datetime.utcnow().replace(tzinfo=utc) rt.end_ts = ts if (rt.status == 'failed'): rt.send_failed = ts rt.save() return Response(ReplicaTrailSerializer(rt).data)