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
No related branches found
No related tags found
No related merge requests found
......@@ -2,4 +2,57 @@
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 @@
# make sure the right line is un / commented depending on which schema you want
# a migration for
script_location = migrations
# change this to run migrations from the command line
sqlalchemy.url = mysql://dummy:dummy-pass@localhost/resources_test
sqlalchemy.url = sqlite:////absolute/path/to/foo.db
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):
# cf. https://docs.sqlalchemy.org/en
# /latest/orm/extensions/automap.html
engine = create_engine(
dsn, pool_size=10, pool_recycle=3600)
engine = create_engine(dsn)
# engine = create_engine(
# dsn, pool_size=10, pool_recycle=3600)
# engine = create_engine(
# dsn, pool_size=10, max_overflow=0, pool_recycle=3600)
......
"""create initial tables
"""initial tables
Revision ID: 1983660b3e64
Revises:
Create Date: 2022-12-18 14:16:34.695912
Revision ID: 1ec562888fd6
Revises: N/A
Create Date: 2023-03-20 07:05:18.984767
"""
from alembic import op
......@@ -10,58 +10,65 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '1983660b3e64'
revision = '1ec562888fd6'
down_revision = None
branch_labels = None
depends_on = None
def upgrade() -> None:
op.create_table(
'nodes',
'routers',
sa.Column('id', sa.Integer, primary_key=True),
sa.Column('fqdn', sa.String(256), nullable=False))
op.create_table(
'line_cards',
'lags',
sa.Column('id', sa.Integer, primary_key=True),
sa.Column('slot', sa.Integer, nullable=False),
sa.Column('model', sa.String(256), nullable=False),
sa.Column('serial', sa.String(256), nullable=False),
sa.Column('description', sa.String(256), nullable=False),
sa.Column('name', sa.String, nullable=False),
sa.Column(
'availability',
sa.Enum('AVAILABLE', 'USED', 'RESERVED', name='lag_availability'),
nullable=False),
sa.Column(
'node_id',
'router_id',
sa.Integer,
sa.ForeignKey('nodes.id'),
sa.ForeignKey('routers.id'),
nullable=False))
op.create_table(
'ports',
'physical_interfaces',
sa.Column('id', sa.Integer, primary_key=True),
sa.Column('pic', sa.Integer, nullable=False),
sa.Column('position', sa.Integer, nullable=False),
sa.Column('interface', sa.String(256), nullable=True),
sa.Column('cable', sa.String(256), nullable=True),
sa.Column('cable', sa.String(256), nullable=True),
sa.Column('name', sa.String, nullable=False),
sa.Column(
'availability',
sa.Enum('AVAILABLE', 'USED', 'RESERVED', name='lag_availability'),
nullable=False),
sa.Column(
'line_card_id',
'router_id',
sa.Integer,
sa.ForeignKey('line_cards.id'),
nullable=False))
sa.ForeignKey('routers.id'),
nullable=False),
sa.Column(
'lag_id',
sa.Integer,
sa.ForeignKey('lags.id'),
nullable=True))
op.create_table(
'port_speed_capabilities',
'logical_interfaces',
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(
'port_id',
'physical_id',
sa.Integer,
sa.ForeignKey('ports.id'),
sa.ForeignKey('physical_interfaces.id'),
nullable=False))
def downgrade() -> None:
op.drop_table('port_speed_capabilities')
op.drop_table('ports')
op.drop_table('line_cards')
op.drop_table('nodes')
op.drop_table('logical_interfaces')
op.drop_table('physical_interfaces')
op.drop_table('lags')
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