1
0
Fork 1
mirror of https://github.com/thatmattlove/hyperglass.git synced 2026-01-17 08:48:05 +00:00

add informational API routes

This commit is contained in:
checktheroads 2020-02-01 02:24:52 -10:00
parent 707f84ae79
commit 0f749a5547
2 changed files with 31 additions and 1 deletions

View file

@ -20,7 +20,9 @@ from hyperglass.api.error_handlers import validation_handler
from hyperglass.api.events import on_shutdown
from hyperglass.api.events import on_startup
from hyperglass.api.routes import docs
from hyperglass.api.routes import queries
from hyperglass.api.routes import query
from hyperglass.api.routes import routers
from hyperglass.configuration import URL_DEV
from hyperglass.configuration import params
from hyperglass.constants import __version__
@ -99,6 +101,12 @@ app.add_middleware(
allow_headers=["*"],
)
app.add_api_route(
path="/api/devices", endpoint=routers, methods=["GET"], response_class=UJSONResponse
)
app.add_api_route(
path="/api/queries", endpoint=queries, methods=["GET"], response_class=UJSONResponse
)
app.add_api_route(
path="/api/query/",
endpoint=query,

View file

@ -12,6 +12,7 @@ from starlette.requests import Request
# Project Imports
from hyperglass.configuration import REDIS_CONFIG
from hyperglass.configuration import devices
from hyperglass.configuration import params
from hyperglass.exceptions import HyperglassError
from hyperglass.execution.execute import Execute
@ -74,4 +75,25 @@ async def docs():
raise HTTPException(detail="Not found", status_code=404)
endpoints = [query, docs]
async def routers():
"""Serve list of configured routers and attributes."""
return [
d.dict(
include={
"name": ...,
"network": ...,
"location": ...,
"display_name": ...,
"vrfs": {-1: {"name", "display_name"}},
}
)
for d in devices.routers
]
async def queries():
"""Serve list of enabled query types."""
return params.queries.list
endpoints = [query, docs, routers]