Name the sizes a node can ask for
Raw cpus and gpus are a property of the machines an installation has, so a node written against a cluster quietly stops meaning anything when the cluster is replaced. A node says "gpu-small" instead, and what that is stored here — editable, and read again every time the node is built, so changing the flavor changes what the next run gets. Memory joins the schema properly (`ram`, in MB, accepting "2G"), along with `duration_s` for how long a node is expected to take. That one is recorded and shown and nothing else yet: a statement for whoever is planning around the node, not a limit — the limit is still `timeout`. A flavor and a number for the same thing is refused, compared by value so an editor writing the whole object back with its defaults still round-trips. A name nothing stores is refused at the save, which covers the canvas and `fluksio sync` at once, and deleting one a node still asks for says which node. Four sizes are seeded on an installation that has none, and never re-seeded: re-adding one somebody deliberately removed is an argument nobody wins. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6HeySA27EkGANZN95QySW
This commit is contained in:
@@ -20,7 +20,7 @@ from sqlmodel import Session, SQLModel, create_engine, select
|
||||
|
||||
from fluksio import crud
|
||||
from fluksio.core.config import settings
|
||||
from fluksio.models import User, UserCreate
|
||||
from fluksio.models import Flavor, User, UserCreate
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -110,8 +110,40 @@ def init_db(session: Session) -> None:
|
||||
user = crud.create_user(session=session, user_create=user_in)
|
||||
|
||||
|
||||
#: The sizes an installation starts with. Written once, when there are none,
|
||||
#: and editable from there — what a name means is a property of the machines
|
||||
#: this installation has, and nothing here knows what those are.
|
||||
SEED_FLAVORS: tuple[dict[str, Any], ...] = (
|
||||
{"name": "small", "cpus": 1, "ram": 2048, "description": "A poll, a threshold"},
|
||||
{"name": "medium", "cpus": 4, "ram": 8192, "description": "A step that computes"},
|
||||
{"name": "large", "cpus": 8, "ram": 16384, "description": "A heavy step"},
|
||||
{
|
||||
"name": "gpu-small",
|
||||
"cpus": 4,
|
||||
"gpus": 1,
|
||||
"ram": 16384,
|
||||
"description": "One card, and cores to feed it",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def seed_flavors(session: Session) -> None:
|
||||
"""Give a new installation sizes to pick from, once.
|
||||
|
||||
Only when there are none at all: they are editable, and re-adding one that
|
||||
somebody deliberately removed would be an argument nobody can win.
|
||||
"""
|
||||
if session.exec(select(Flavor)).first() is not None:
|
||||
return
|
||||
for row in SEED_FLAVORS:
|
||||
session.add(Flavor(**row))
|
||||
session.commit()
|
||||
logger.info("seeded %d resource flavors", len(SEED_FLAVORS))
|
||||
|
||||
|
||||
def prepare(engine: Engine) -> None:
|
||||
"""Everything that has to be true before the app serves a request."""
|
||||
migrate(engine)
|
||||
with Session(engine) as session:
|
||||
init_db(session)
|
||||
seed_flavors(session)
|
||||
|
||||
Reference in New Issue
Block a user