@@ 54-71 (lines=18) @@ | ||
51 | If you have some cleanup procedure, insert it here. |
|
52 | """ |
|
53 | ||
54 | @rest('/v1/trace', methods=['PUT']) |
|
55 | @validate_openapi(spec) |
|
56 | def trace(self, request: Request) -> JSONResponse: |
|
57 | """Trace a path.""" |
|
58 | result = [] |
|
59 | data = get_json_or_400(request, self.controller.loop) |
|
60 | entries = convert_entries(data) |
|
61 | if not entries: |
|
62 | raise HTTPException(400, "Empty entries") |
|
63 | try: |
|
64 | stored_flows = get_stored_flows() |
|
65 | except tenacity.RetryError as exc: |
|
66 | raise HTTPException(424, "It couldn't get stored_flows") from exc |
|
67 | try: |
|
68 | result = self.tracepath(entries, stored_flows) |
|
69 | except ValueError as exc: |
|
70 | raise HTTPException(409, str(exc)) from exc |
|
71 | return JSONResponse(prepare_json(result)) |
|
72 | ||
73 | @rest('/v1/traces', methods=['PUT']) |
|
74 | @validate_openapi(spec) |
|
@@ 73-89 (lines=17) @@ | ||
70 | raise HTTPException(409, str(exc)) from exc |
|
71 | return JSONResponse(prepare_json(result)) |
|
72 | ||
73 | @rest('/v1/traces', methods=['PUT']) |
|
74 | @validate_openapi(spec) |
|
75 | def get_traces(self, request: Request) -> JSONResponse: |
|
76 | """For bulk requests.""" |
|
77 | data = get_json_or_400(request, self.controller.loop) |
|
78 | entries = convert_list_entries(data) |
|
79 | results = [] |
|
80 | try: |
|
81 | stored_flows = get_stored_flows() |
|
82 | except tenacity.RetryError as exc: |
|
83 | raise HTTPException(424, "It couldn't get stored_flows") from exc |
|
84 | for entry in entries: |
|
85 | try: |
|
86 | results.append(self.tracepath(entry, stored_flows)) |
|
87 | except ValueError as exc: |
|
88 | raise HTTPException(409, str(exc)) from exc |
|
89 | return JSONResponse(prepare_json(results)) |
|
90 | ||
91 | def tracepath(self, entries, stored_flows): |
|
92 | """Trace a path for a packet represented by entries.""" |