feat(labs): describe the lab task contract and the provisioner port
This commit is contained in:
1 parent
3de226b16c
commit
9fdaa62b9b
91 files changed
+19262
-155
No files matched your search
@@ -0,0 +1,15 @@
|
||||
get:
|
||||
operationId: GetLabdHealthz
|
||||
summary: Check whether the lab provisioner process is responding.
|
||||
security: []
|
||||
tags:
|
||||
- health
|
||||
responses:
|
||||
"200":
|
||||
description: The process is responding.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: ../components/schemas.yml#/LabdHealthResponse
|
||||
default:
|
||||
$ref: ../components/responses.yml#/Problem
|
||||
@@ -0,0 +1,31 @@
|
||||
parameters:
|
||||
- $ref: ../components/parameters.yml#/LabId
|
||||
post:
|
||||
operationId: CheckLab
|
||||
summary: Run the checker of the template against the nodes of a ready lab.
|
||||
description: |-
|
||||
The checker of the template connects from the host side of the lab
|
||||
management bridge to the nodes (SSH or the RouterOS API) and evaluates
|
||||
the criteria of the variant that the seed selected. It only reads the
|
||||
node state and never changes it, so a repeated call is harmless; the
|
||||
result is not stored by `labd`. The call is synchronous and bounded by
|
||||
the check timeout of the provisioner.
|
||||
|
||||
The result is checker state for the backend only: the backend scores the
|
||||
lab answer with it and never forwards it to the candidate.
|
||||
|
||||
A lab that is not `ready` answers 409 `state_conflict`. When the
|
||||
checker cannot reach a node or the template has no working checker, the
|
||||
provisioner answers 503 `lab_unavailable`: nothing was evaluated, and the
|
||||
outcome is never a failed check.
|
||||
tags:
|
||||
- checks
|
||||
responses:
|
||||
"200":
|
||||
description: The checker evaluated every criterion.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: ../components/schemas.yml#/LabCheckResult
|
||||
default:
|
||||
$ref: ../components/responses.yml#/Problem
|
||||
@@ -0,0 +1,46 @@
|
||||
parameters:
|
||||
- $ref: ../components/parameters.yml#/LabId
|
||||
post:
|
||||
operationId: CreateLabConsoleToken
|
||||
summary: Issue a short-lived console token for one node of a ready lab.
|
||||
description: |-
|
||||
The token lets the console gateway of the backend attach to the serial
|
||||
console of one node. It is random, single-use, bound to the lab and the
|
||||
node, and valid for at most 120 seconds; `labd` keeps only its SHA-256
|
||||
digest in memory, so a restart invalidates every unused token. The token
|
||||
is never a node password or an SSH key, and the response carries no node
|
||||
address.
|
||||
|
||||
Attaching: the gateway opens a WebSocket to `attach_path` on the same
|
||||
`labd` origin with the service bearer token and sends the console token
|
||||
in the `X-Lab-Console-Token` header. The WebSocket attach is described
|
||||
here as the planned interface; until it is implemented, `labd` answers
|
||||
the attach path with 501 and issuing a token changes nothing else.
|
||||
|
||||
A lab that is not `ready` answers 409 `state_conflict`; an unknown node
|
||||
answers 400 `validation_failed` with the pointer `/node`.
|
||||
tags:
|
||||
- consoles
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: ../components/schemas.yml#/ConsoleTokenRequest
|
||||
responses:
|
||||
"201":
|
||||
description: The token was issued.
|
||||
headers:
|
||||
Cache-Control:
|
||||
description: The token must not be stored by any cache.
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
enum:
|
||||
- no-store
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: ../components/schemas.yml#/ConsoleToken
|
||||
default:
|
||||
$ref: ../components/responses.yml#/Problem
|
||||
@@ -0,0 +1,119 @@
|
||||
parameters:
|
||||
- $ref: ../components/parameters.yml#/LabId
|
||||
put:
|
||||
operationId: CreateLab
|
||||
summary: Create a lab from a template and a variant seed.
|
||||
description: |-
|
||||
Idempotent by `lab_id`:
|
||||
|
||||
- a new ID that fits the capacity reserves it, stores the lab, and answers 202 with `state: provisioning`; the nodes are cloned and booted in the background;
|
||||
- the same ID with the same payload answers 200 with the current state of that lab, including `deleted` or `failed`, and never creates a second one;
|
||||
- the same ID with a different payload answers 422 `idempotency_key_reused` and changes nothing;
|
||||
- a new ID that does not fit the memory budget or the lab limit, or arrives while the provisioner is draining, answers 503 `lab_pool_busy` with Retry-After; nothing is stored, so the caller retries with the same ID.
|
||||
|
||||
Payloads are compared by a SHA-256 fingerprint of the decoded request.
|
||||
An unknown template or template version, or a lifetime above the
|
||||
configured maximum, answers 400 `validation_failed` with a pointer such
|
||||
as `/template_id` or `/ttl_seconds`.
|
||||
|
||||
The lab is deleted at `expires_at` = creation time + `ttl_seconds`, also
|
||||
when it is still provisioning. A lab that fails to provision or does not
|
||||
answer within the provisioning timeout becomes `failed` and its
|
||||
resources are deleted; its capacity returns when they are gone.
|
||||
|
||||
A record of a deleted or failed lab is kept for a bounded retention time;
|
||||
after it, the ID is unknown again and a CreateLab with it starts a new
|
||||
lab.
|
||||
tags:
|
||||
- labs
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: ../components/schemas.yml#/LabCreateRequest
|
||||
examples:
|
||||
two_routers:
|
||||
summary: A lab of a networking template for one attempt item
|
||||
value:
|
||||
template_id: mikrotik-ospf-pair
|
||||
template_version: 1
|
||||
seed: 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08
|
||||
ttl_seconds: 3600
|
||||
responses:
|
||||
"200":
|
||||
description: A lab with this ID and the same payload already exists.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: ../components/schemas.yml#/LabStatus
|
||||
"202":
|
||||
description: The lab was accepted and is provisioning.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: ../components/schemas.yml#/LabStatus
|
||||
examples:
|
||||
provisioning:
|
||||
summary: A lab that is being cloned and booted
|
||||
value:
|
||||
lab_id: 2f1c7a52-0d3e-4b8e-9b61-3c7b1f2e9a40
|
||||
state: provisioning
|
||||
template_id: mikrotik-ospf-pair
|
||||
template_version: 1
|
||||
created_at: "2026-10-11T09:00:00Z"
|
||||
expires_at: "2026-10-11T10:00:00Z"
|
||||
nodes:
|
||||
- name: r1
|
||||
kind: mikrotik
|
||||
- name: r2
|
||||
kind: mikrotik
|
||||
"503":
|
||||
$ref: ../components/responses.yml#/LabPoolBusy
|
||||
default:
|
||||
$ref: ../components/responses.yml#/Problem
|
||||
get:
|
||||
operationId: GetLab
|
||||
summary: Read the state of a lab.
|
||||
description: >-
|
||||
Answers 404 `not_found` for an ID the provisioner does not hold,
|
||||
including a lab whose `deleted` record outlived its retention time. The
|
||||
response never contains an address, a key, or an LXD object name.
|
||||
tags:
|
||||
- labs
|
||||
responses:
|
||||
"200":
|
||||
description: The current state of the lab.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: ../components/schemas.yml#/LabStatus
|
||||
default:
|
||||
$ref: ../components/responses.yml#/Problem
|
||||
delete:
|
||||
operationId: DeleteLab
|
||||
summary: Delete a lab before its timer.
|
||||
description: >-
|
||||
Marks the lab for deletion and answers 202 with `state: deleting`; the
|
||||
provisioner removes its instances and bridges in the background and
|
||||
retries until LXD confirms that they are gone, also across its own
|
||||
restarts. Deleting a lab that is already `deleting` or `deleted`
|
||||
answers 200 with its state and changes nothing. An unknown ID answers
|
||||
404 `not_found`.
|
||||
tags:
|
||||
- labs
|
||||
responses:
|
||||
"200":
|
||||
description: The lab was already being deleted or is deleted.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: ../components/schemas.yml#/LabStatus
|
||||
"202":
|
||||
description: The lab is being deleted.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: ../components/schemas.yml#/LabStatus
|
||||
default:
|
||||
$ref: ../components/responses.yml#/Problem
|
||||
@@ -0,0 +1,26 @@
|
||||
get:
|
||||
operationId: GetLabdReadyz
|
||||
summary: Check whether the provisioner can create and delete labs.
|
||||
description: >-
|
||||
Ready means that the lab records were loaded, the startup reconciliation
|
||||
with LXD finished, the LXD API answered the latest probe, and the process
|
||||
is not draining. A provisioner without free capacity is still ready;
|
||||
capacity is reported by CreateLab.
|
||||
security: []
|
||||
tags:
|
||||
- health
|
||||
responses:
|
||||
"200":
|
||||
description: The provisioner is ready.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: ../components/schemas.yml#/LabdReadinessResponse
|
||||
"503":
|
||||
description: The provisioner is not ready or is draining.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: ../components/schemas.yml#/LabdReadinessResponse
|
||||
default:
|
||||
$ref: ../components/responses.yml#/Problem
|
||||
Reference in new issue
Block a user