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:
parent
707f84ae79
commit
0f749a5547
2 changed files with 31 additions and 1 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue