Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: @rest endpoints are now run by starlette/uvicorn instead of flask/werkzeug #94

Merged
merged 8 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Fixed
- In ``PUT /trace`` and ``PUT /traces``, field ``switch``` is defined as required, as well as its parameters ``dpid``` and ``in_port``.
- Check that an interface has been found with ``find_endpoint`` given ``switch`` and ``port`` at each ``trace_step``.

General Information
===================
- ``@rest`` endpoints are now run by ``starlette/uvicorn`` instead of ``flask/werkzeug``.

[2022.3.1] - 2023-02-27
***********************

Expand Down
16 changes: 9 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import pathlib
from datetime import datetime

from flask import jsonify
from kytos.core import KytosNApp, log, rest
from kytos.core.helpers import load_spec, validate_openapi
from kytos.core.rest_api import (HTTPException, JSONResponse, Request,
get_json_or_400)
from napps.amlight.sdntrace_cp import settings
from napps.amlight.sdntrace_cp.automate import Automate
from napps.amlight.sdntrace_cp.utils import (convert_entries,
Expand Down Expand Up @@ -59,27 +60,28 @@ def shutdown(self):

@rest('/v1/trace', methods=['PUT'])
@validate_openapi(spec)
def trace(self, data):
def trace(self, request: Request) -> JSONResponse:
"""Trace a path."""
result = []
data = get_json_or_400(request, self.controller.loop)
entries = convert_entries(data)
if not entries:
return "Bad request", 400
raise HTTPException(400, "Empty entries")
stored_flows = get_stored_flows()
result = self.tracepath(entries, stored_flows)
return jsonify(prepare_json(result))
return JSONResponse(prepare_json(result))

@rest('/v1/traces', methods=['PUT'])
@validate_openapi(spec)
def get_traces(self, data):
def get_traces(self, request: Request) -> JSONResponse:
"""For bulk requests."""
data = get_json_or_400(request, self.controller.loop)
entries = convert_list_entries(data)
stored_flows = get_stored_flows()
results = []
for entry in entries:
results.append(self.tracepath(entry, stored_flows))
temp = prepare_json(results)
return jsonify(temp)
return JSONResponse(prepare_json(results))

def tracepath(self, entries, stored_flows):
"""Trace a path for a packet represented by entries."""
Expand Down
7 changes: 4 additions & 3 deletions openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ info:
title: amlight/sdntrace_cp
version: '0.1'
description: An OpenFlow Path Tracing on Control Plane
servers:
- url: /api/amlight/sdntrace_cp
paths:
/api/amlight/sdntrace_cp/v1/trace:
/v1/trace:
put:
summary: Trace a path
description: Trace a path starting with the switch given with the parameters given. The trace is done entirely in control plane.
Expand Down Expand Up @@ -130,7 +132,7 @@ paths:
schema:
type: string
example: Bad request
/api/amlight/sdntrace_cp/v1/traces:
/v1/traces:
put:
summary: Trace paths given switches
description: Trace a path starting with each switch given in a list as parameter.
Expand Down Expand Up @@ -250,4 +252,3 @@ paths:
type: integer
description: VLAN ID
example: 100

9 changes: 2 additions & 7 deletions requirements/dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,5 @@
# pip-compile --output-file requirements/dev.txt requirements/dev.in
#
-e git+https://github.com/kytos-ng/python-openflow.git#egg=python-openflow
-e git+https://github.com/kytos-ng/kytos.git#egg=kytos
-e git+https://github.com/kytos-ng/of_core.git#egg=kytos_of_core
-e git+https://github.com/kytos-ng/sdntrace.git#egg=amlight_sdntrace
-e git+https://github.com/kytos-ng/flow_stats.git#egg=amlight_flow_stats
-e .[dev]
pytest-asyncio==0.18.3
black==22.3.0
-e git+https://github.com/kytos-ng/kytos.git#egg=kytos[dev]
-e .
Loading