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

Finished feature update-migrations.

parents 5e80096d 3c078d23
Branches
No related tags found
No related merge requests found
...@@ -2,4 +2,57 @@ ...@@ -2,4 +2,57 @@
resource management tooling & experiments resource management tooling & experiments
TODO ...
## running locally
*this is a quick setup version for running
standalone on your local machine (will be
merged into the full docs later)*
### database setup
* set the value of `sqlalchemy.url`
in `alembic.ini` to point to a writeable file, e.g.
```python
sqlalchemy.url = sqlite:////absolute/path/to/foo.db
```
* create the database by running the alembic
migration from the top-level directory
```bash
alembic upgrade head
```
### running the app
* create a settings filename
(see `config-example.json` for an example) ... something like:
```json
{
"db": "sqlite:////tmp/test.db",
"ssh": {
"username": "ro-username",
"private-key": "/absolute/path/to/private/key"
}
}
```
* run the app like this
(`app.py` starts the server on port 44444):
```bash
SETTINGS_FILENAME=/absolute/path/to/config.json python -m resource_management.app
```
### examples
* get the version
```bash
curl http://localhost:44444/api/version
```
* load interfaces from a router
```bash
curl -X POST http://localhost:44444/api/initialize-router/router.host.name
```
* view the docs by loading `http://localhost:44444/docs`
in your browser (there are requests for reserving
lags and physical lag interfaces)
{
"db": "sqlite:////tmp/test.db",
"ssh": {
"username": "ro-username",
"private-key": "/absolute/path/to/private/key"
}
}
\ No newline at end of file
...@@ -3,5 +3,7 @@ ...@@ -3,5 +3,7 @@
# 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
# change this to run migrations from the command line sqlalchemy.url = sqlite:////absolute/path/to/foo.db
sqlalchemy.url = mysql://dummy:dummy-pass@localhost/resources_test sqlalchemy.url = sqlite:////Users/reid/workspace/nat/resource-management/resource_management/foo.db
# or here is an example of a mysql dsn
# sqlalchemy.url = mysql://dummy:dummy-pass@localhost/resources_db_name
"""
default app creation
"""
import resource_management
app = resource_management.create_app()
if __name__ == "__main__":
import uvicorn
uvicorn.run(
'resource_management.app:app',
host='0.0.0.0',
port=44444,
log_level='debug')
...@@ -38,8 +38,9 @@ def init_db_model(dsn): ...@@ -38,8 +38,9 @@ def init_db_model(dsn):
# cf. https://docs.sqlalchemy.org/en # cf. https://docs.sqlalchemy.org/en
# /latest/orm/extensions/automap.html # /latest/orm/extensions/automap.html
engine = create_engine( engine = create_engine(dsn)
dsn, pool_size=10, pool_recycle=3600) # engine = create_engine(
# dsn, pool_size=10, pool_recycle=3600)
# engine = create_engine( # engine = create_engine(
# dsn, pool_size=10, max_overflow=0, pool_recycle=3600) # dsn, pool_size=10, max_overflow=0, pool_recycle=3600)
......
"""create initial tables """initial tables
Revision ID: 1983660b3e64 Revision ID: 1ec562888fd6
Revises: Revises: N/A
Create Date: 2022-12-18 14:16:34.695912 Create Date: 2023-03-20 07:05:18.984767
""" """
from alembic import op from alembic import op
...@@ -10,58 +10,65 @@ import sqlalchemy as sa ...@@ -10,58 +10,65 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '1983660b3e64' revision = '1ec562888fd6'
down_revision = None down_revision = None
branch_labels = None branch_labels = None
depends_on = None depends_on = None
def upgrade() -> None: def upgrade() -> None:
op.create_table( op.create_table(
'nodes', 'routers',
sa.Column('id', sa.Integer, primary_key=True), sa.Column('id', sa.Integer, primary_key=True),
sa.Column('fqdn', sa.String(256), nullable=False)) sa.Column('fqdn', sa.String(256), nullable=False))
op.create_table( op.create_table(
'line_cards', 'lags',
sa.Column('id', sa.Integer, primary_key=True), sa.Column('id', sa.Integer, primary_key=True),
sa.Column('slot', sa.Integer, nullable=False), sa.Column('name', sa.String, nullable=False),
sa.Column('model', sa.String(256), nullable=False), sa.Column(
sa.Column('serial', sa.String(256), nullable=False), 'availability',
sa.Column('description', sa.String(256), nullable=False), sa.Enum('AVAILABLE', 'USED', 'RESERVED', name='lag_availability'),
nullable=False),
sa.Column( sa.Column(
'node_id', 'router_id',
sa.Integer, sa.Integer,
sa.ForeignKey('nodes.id'), sa.ForeignKey('routers.id'),
nullable=False)) nullable=False))
op.create_table( op.create_table(
'ports', 'physical_interfaces',
sa.Column('id', sa.Integer, primary_key=True), sa.Column('id', sa.Integer, primary_key=True),
sa.Column('pic', sa.Integer, nullable=False), sa.Column('name', sa.String, nullable=False),
sa.Column('position', sa.Integer, nullable=False), sa.Column(
sa.Column('interface', sa.String(256), nullable=True), 'availability',
sa.Column('cable', sa.String(256), nullable=True), sa.Enum('AVAILABLE', 'USED', 'RESERVED', name='lag_availability'),
sa.Column('cable', sa.String(256), nullable=True), nullable=False),
sa.Column( sa.Column(
'line_card_id', 'router_id',
sa.Integer, sa.Integer,
sa.ForeignKey('line_cards.id'), sa.ForeignKey('routers.id'),
nullable=False)) nullable=False),
sa.Column(
'lag_id',
sa.Integer,
sa.ForeignKey('lags.id'),
nullable=True))
op.create_table( op.create_table(
'port_speed_capabilities', 'logical_interfaces',
sa.Column('id', sa.Integer, primary_key=True), sa.Column('id', sa.Integer, primary_key=True),
sa.Column('speed', sa.String(256), nullable=True), sa.Column('name', sa.String, nullable=False),
sa.Column( sa.Column(
'port_id', 'physical_id',
sa.Integer, sa.Integer,
sa.ForeignKey('ports.id'), sa.ForeignKey('physical_interfaces.id'),
nullable=False)) nullable=False))
def downgrade() -> None: def downgrade() -> None:
op.drop_table('port_speed_capabilities') op.drop_table('logical_interfaces')
op.drop_table('ports') op.drop_table('physical_interfaces')
op.drop_table('line_cards') op.drop_table('lags')
op.drop_table('nodes') op.drop_table('routers')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment