Skip to content
Snippets Groups Projects
Commit d7580eae authored by JORGE SASIAIN's avatar JORGE SASIAIN
Browse files

Fix missing config.load in get_known_routers; add size to string-type columns...

Fix missing config.load in get_known_routers; add size to string-type columns in db; read alembic db uri from settings file
parent 4a19dc6a
No related branches found
No related tags found
No related merge requests found
...@@ -7,3 +7,5 @@ coverage.xml ...@@ -7,3 +7,5 @@ coverage.xml
docs/build docs/build
.vscode .vscode
config.json
{
"openapi": "3.0.2",
"info": {
"title": "FastAPI",
"version": "0.1.0"
},
"paths": {
"/api/version": {
"get": {
"summary": "Version",
"operationId": "version_api_version_get",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Version"
}
}
}
}
}
}
},
"/api/interfaces/initialize-router/{fqdn}": {
"post": {
"summary": "Load New Router Interfaces",
"operationId": "load_new_router_interfaces_api_interfaces_initialize_router__fqdn__post",
"parameters": [
{
"required": true,
"schema": {
"title": "Fqdn",
"type": "string"
},
"name": "fqdn",
"in": "path"
}
],
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/InterfacesSummary"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/api/interfaces/reconcile-router/{fqdn}": {
"post": {
"summary": "Reconcile Current Router Interfaces",
"operationId": "reconcile_current_router_interfaces_api_interfaces_reconcile_router__fqdn__post",
"parameters": [
{
"required": true,
"schema": {
"title": "Fqdn",
"type": "string"
},
"name": "fqdn",
"in": "path"
}
],
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/api/interfaces/routers": {
"get": {
"summary": "Get Known Routers",
"operationId": "get_known_routers_api_interfaces_routers_get",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ListOfRouters"
}
}
}
}
}
}
},
"/api/interfaces/next-lag/{fqdn}": {
"post": {
"summary": "Reserve Next Lag",
"description": "compute the next available lag name for the given router\n\nTODO: _next_lag_name is a placeholder for\n whatever logic turns out to be right",
"operationId": "reserve_next_lag_api_interfaces_next_lag__fqdn__post",
"parameters": [
{
"required": true,
"schema": {
"title": "Fqdn",
"type": "string"
},
"name": "fqdn",
"in": "path"
}
],
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NextLAG"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/api/interfaces/next-physical/{fqdn}/{lag_name}": {
"post": {
"summary": "Reserve Physical Bundle Member",
"description": "compute the next available lag name for the given router\n\nTODO: _find_available_physical is a placeholder for\n whatever logic turns out to be right (e.g. speeds, etc)",
"operationId": "reserve_physical_bundle_member_api_interfaces_next_physical__fqdn___lag_name__post",
"parameters": [
{
"required": true,
"schema": {
"title": "Fqdn",
"type": "string"
},
"name": "fqdn",
"in": "path"
},
{
"required": true,
"schema": {
"title": "Lag Name",
"type": "string"
},
"name": "lag_name",
"in": "path"
}
],
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NextPhysicalInterface"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"HTTPValidationError": {
"title": "HTTPValidationError",
"type": "object",
"properties": {
"detail": {
"title": "Detail",
"type": "array",
"items": {
"$ref": "#/components/schemas/ValidationError"
}
}
}
},
"InterfaceCounts": {
"title": "InterfaceCounts",
"required": [
"total",
"available"
],
"type": "object",
"properties": {
"total": {
"title": "Total",
"type": "integer"
},
"available": {
"title": "Available",
"type": "integer"
}
}
},
"InterfacesSummary": {
"title": "InterfacesSummary",
"required": [
"fqdn",
"lag",
"physical"
],
"type": "object",
"properties": {
"fqdn": {
"title": "Fqdn",
"type": "string"
},
"lag": {
"title": "Lag",
"type": "integer"
},
"physical": {
"$ref": "#/components/schemas/InterfaceCounts"
}
}
},
"ListOfRouters": {
"title": "ListOfRouters",
"required": [
"routers"
],
"type": "object",
"properties": {
"routers": {
"title": "Routers",
"type": "array",
"items": {
"$ref": "#/components/schemas/RouterDetails"
}
}
}
},
"NextLAG": {
"title": "NextLAG",
"required": [
"fqdn",
"name"
],
"type": "object",
"properties": {
"fqdn": {
"title": "Fqdn",
"type": "string"
},
"name": {
"title": "Name",
"type": "string"
}
}
},
"NextPhysicalInterface": {
"title": "NextPhysicalInterface",
"required": [
"fqdn",
"lag",
"name"
],
"type": "object",
"properties": {
"fqdn": {
"title": "Fqdn",
"type": "string"
},
"lag": {
"title": "Lag",
"type": "string"
},
"name": {
"title": "Name",
"type": "string"
}
}
},
"RouterDetails": {
"title": "RouterDetails",
"required": [
"fqdn"
],
"type": "object",
"properties": {
"fqdn": {
"title": "Fqdn",
"type": "string"
}
}
},
"ValidationError": {
"title": "ValidationError",
"required": [
"loc",
"msg",
"type"
],
"type": "object",
"properties": {
"loc": {
"title": "Location",
"type": "array",
"items": {
"anyOf": [
{
"type": "string"
},
{
"type": "integer"
}
]
}
},
"msg": {
"title": "Message",
"type": "string"
},
"type": {
"title": "Error Type",
"type": "string"
}
}
},
"Version": {
"title": "Version",
"required": [
"api",
"module"
],
"type": "object",
"properties": {
"api": {
"title": "Api",
"pattern": "\\d+\\.\\d+",
"type": "string"
},
"module": {
"title": "Module",
"pattern": "\\d+\\.\\d+",
"type": "string"
}
}
}
}
}
}
\ No newline at end of file
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
# make sure the right line is un / commented depending on which schema you want # make sure the right line is un / commented depending on which schema you want
# a migration for # a migration for
script_location = migrations script_location = migrations
sqlalchemy.url = sqlite:////absolute/path/to/foo.db sqlalchemy.url = %(DB_URI)s
# or here is an example of a mysql dsn # or here is an example of a mysql dsn
# sqlalchemy.url = mysql://dummy:dummy-pass@localhost/resources_db_name # sqlalchemy.url = mysql://dummy:dummy-pass@localhost/resources_db_name
...@@ -5,6 +5,8 @@ from sqlalchemy import pool ...@@ -5,6 +5,8 @@ from sqlalchemy import pool
from alembic import context from alembic import context
from resource_management import config as _app_config
# this is the Alembic Config object, which provides # this is the Alembic Config object, which provides
# access to the values within the .ini file in use. # access to the values within the .ini file in use.
config = context.config config = context.config
...@@ -25,6 +27,11 @@ target_metadata = None ...@@ -25,6 +27,11 @@ target_metadata = None
# my_important_option = config.get_main_option("my_important_option") # my_important_option = config.get_main_option("my_important_option")
# ... etc. # ... etc.
app_config = _app_config.load()
db_uri = app_config["db"]
section = config.config_ini_section
config.set_section_option(section, "DB_URI", db_uri)
def run_migrations_offline() -> None: def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode. """Run migrations in 'offline' mode.
......
...@@ -26,7 +26,7 @@ def upgrade() -> None: ...@@ -26,7 +26,7 @@ def upgrade() -> None:
op.create_table( op.create_table(
'lags', 'lags',
sa.Column('id', sa.Integer, primary_key=True), sa.Column('id', sa.Integer, primary_key=True),
sa.Column('name', sa.String, nullable=False), sa.Column('name', sa.String(256), nullable=False),
sa.Column( sa.Column(
'availability', 'availability',
sa.Enum('AVAILABLE', 'USED', 'RESERVED', name='lag_availability'), sa.Enum('AVAILABLE', 'USED', 'RESERVED', name='lag_availability'),
...@@ -40,7 +40,7 @@ def upgrade() -> None: ...@@ -40,7 +40,7 @@ def upgrade() -> None:
op.create_table( op.create_table(
'physical_interfaces', 'physical_interfaces',
sa.Column('id', sa.Integer, primary_key=True), sa.Column('id', sa.Integer, primary_key=True),
sa.Column('name', sa.String, nullable=False), sa.Column('name', sa.String(256), nullable=False),
sa.Column( sa.Column(
'availability', 'availability',
sa.Enum('AVAILABLE', 'USED', 'RESERVED', name='lag_availability'), sa.Enum('AVAILABLE', 'USED', 'RESERVED', name='lag_availability'),
...@@ -59,7 +59,7 @@ def upgrade() -> None: ...@@ -59,7 +59,7 @@ def upgrade() -> None:
op.create_table( op.create_table(
'logical_interfaces', 'logical_interfaces',
sa.Column('id', sa.Integer, primary_key=True), sa.Column('id', sa.Integer, primary_key=True),
sa.Column('name', sa.String, nullable=False), sa.Column('name', sa.String(256), nullable=False),
sa.Column( sa.Column(
'physical_id', 'physical_id',
sa.Integer, sa.Integer,
......
...@@ -86,6 +86,10 @@ async def reconcile_current_router_interfaces(fqdn: str): ...@@ -86,6 +86,10 @@ async def reconcile_current_router_interfaces(fqdn: str):
@router.get('/routers') @router.get('/routers')
async def get_known_routers() -> ListOfRouters: async def get_known_routers() -> ListOfRouters:
params = config.load()
db.init_db_model(params['db'])
with db.session_scope() as session: with db.session_scope() as session:
rows = session.query(model.Router.fqdn).all() rows = session.query(model.Router.fqdn).all()
return {'routers': [{'fqdn': r[0]} for r in rows]} return {'routers': [{'fqdn': r[0]} for r in rows]}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment