Skip to content
Snippets Groups Projects
Commit d42eb366 authored by Erik Reid's avatar Erik Reid
Browse files

Finished feature get-routers.

parents cdf21878 d13db393
No related branches found
No related tags found
No related merge requests found
from typing import List
from fastapi import APIRouter, HTTPException from fastapi import APIRouter, HTTPException
import pydantic import pydantic
...@@ -35,6 +37,14 @@ class NextPhysicalInterface(pydantic.BaseModel): ...@@ -35,6 +37,14 @@ class NextPhysicalInterface(pydantic.BaseModel):
name: str name: str
class RouterDetails(pydantic.BaseModel):
fqdn: str
class ListOfRouters(pydantic.BaseModel):
routers: List[RouterDetails]
@router.post('/initialize-router/{fqdn}') @router.post('/initialize-router/{fqdn}')
async def load_new_router_interfaces(fqdn: str) -> InterfacesSummary: async def load_new_router_interfaces(fqdn: str) -> InterfacesSummary:
...@@ -74,6 +84,13 @@ async def reconcile_current_router_interfaces(fqdn: str): ...@@ -74,6 +84,13 @@ async def reconcile_current_router_interfaces(fqdn: str):
detail='not implemented') detail='not implemented')
@router.get('/routers')
async def get_known_routers() -> ListOfRouters:
with db.session_scope() as session:
rows = session.query(model.Router.fqdn).all()
return {'routers': [{'fqdn': r[0]} for r in rows]}
@router.post('/next-lag/{fqdn}') @router.post('/next-lag/{fqdn}')
async def reserve_next_lag(fqdn: str) -> NextLAG: async def reserve_next_lag(fqdn: str) -> NextLAG:
""" """
......
...@@ -76,3 +76,19 @@ def test_next_physical(client, resources_db, mocked_router, router_name): ...@@ -76,3 +76,19 @@ def test_next_physical(client, resources_db, mocked_router, router_name):
join(model.LAG). \ join(model.LAG). \
filter_by(name=lag_name).one() filter_by(name=lag_name).one()
assert ifc_row.availability == model.AvalabilityStates.RESERVED.name assert ifc_row.availability == model.AvalabilityStates.RESERVED.name
def test_list_of_routers(client, resources_db):
with db.session_scope() as session:
for idx in range(10):
row = db.model.Router(fqdn=f'router-{idx}.xyz.com')
session.add(row)
rv = client.get('/api/interfaces/routers')
assert rv.status_code == 200
response = rv.json()
jsonschema.validate(response, interfaces.ListOfRouters.schema())
for r in response['routers']:
assert r['fqdn'].endswith('.xyz.com')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment