中文日本語

Docs · 1.0

HTTP API

The keelOS web page is itself built on the HTTP API: whatever the web page does, scripts and other programs can do through the API. This chapter covers authentication, how to use tokens, the most common endpoints and where the full description is.

1. Address and authentication

  • The API is at the same address as the web page: https://<host address>/v1/… (HTTPS, port 443).
  • Every request carries a token: Authorization: Bearer keel_…. Tokens are made under System → Tokens or with keel token create on the host; see Accounts, tokens and permissions.
  • By default the host uses keel's own self-signed certificate. With curl, skip the check with -k, or pin the certificate: its SHA-256 fingerprint is on the System → Manager page. Once you have imported your own certificate (Configuration → Network → Certificate), that certificate is served for its names.
  • Requests and answers are JSON. On an error the HTTP status is not 2xx and the answer is {"error": "reason"}; an invalid token gives 401, a missing permission 403.
curl -k -H "Authorization: Bearer keel_…" https://192.168.1.10/v1/vms

2. Tokens and permissions

Each endpoint needs one permission (vm:read, vm:power, host:write …, the same ones you tick under New token in the web page; see Accounts, tokens and permissions). A token without it gets 403.

  • Give a script's token only what it needs: monitoring needs only Monitoring, scripts (read-only); power actions add vm:power.
  • Only from these addresses (CIDR) limits where the token may be used; from any other address it is as good as no token.
  • A token made with keel token create --vm ID or --tag K=V sees and touches only those virtual machines.
  • Every write request goes into the audit log (System → Audit log) with the token's name and the source address.
  • A token that is lost or leaked: revoke it under System → Tokens; it stops working at once.

3. The endpoints

The full description is an OpenAPI document: GET /v1/openapi.json (any valid token can read it). For each endpoint it gives the permission it needs (x-keel-permission), the parameters and the answer. The most common ones:

Virtual machines

Endpoint What it does Permission
GET /v1/vms lists the virtual machines (a token limited to some sees only those) vm:read
GET /v1/vms/{id} one virtual machine's configuration and state vm:read
POST /v1/vms creates one (the body is the configuration; ?dry_run=1 only checks) vm:write
PUT /v1/vms/{id} changes the configuration vm:write
DELETE /v1/vms/{id} deletes it vm:delete
POST /v1/vms/{id}/start, /stop, /reset, /kill, /suspend, /resume power actions vm:power
GET /v1/vms/{id}/snapshots, POST /v1/vms/{id}/snapshots, POST /v1/vms/{id}/rollback, POST /v1/vms/{id}/clone snapshots, rollback, clones vm:snapshot
GET /v1/vms/{id}/screenshot a screenshot of the virtual machine's screen vm:console
POST /v1/vms/{id}/input types and clicks in the virtual machine (automation) vm:input
GET /v1/vms/{id}/rdp an .rdp file for this virtual machine vm:console

{id} is the UUID, the virtual machine's name, or a unique beginning of the UUID (at least 4 characters).

The host

Endpoint What it does Permission
GET /v1/version keel's version any token
GET /v1/host host summary: version, CPUs, memory, pools, addresses host:read
GET /v1/host/hardware hardware: board, memory modules, disks and SMART, sensors host:read
GET /v1/host/temps, GET /v1/host/perf temperatures, performance data host:read
GET /v1/host/problems configuration problems (the notes on the Overview) host:read
GET /v1/storage/pools storage pools host:read
GET /v1/host/upgrade the versions in both slots, download and write progress host:read
POST /v1/host/restart, POST /v1/host/shutdown restart (keel decides between a reload and a full restart), shut down host:write
GET /v1/isos, POST /v1/isos the ISO library: list, download from a URL image:read / image:write
GET /v1/logs, GET /v1/logs/host?file=… log files, read one log log:read
GET /v1/support-bundle downloads a support bundle log:read
GET /v1/audit the audit log log:read
GET /v1/tokens, POST /v1/tokens, DELETE /v1/tokens/{id} tokens token:admin

4. Waiting and background jobs

  • Power actions wait until they are done before answering. With ?wait=SECONDS (1–50) they wait only that long: if not done by then, the answer is 202 with a job id and the work goes on in the background.
  • Slow work such as downloads, imports and exports runs as background jobs: GET /v1/jobs lists them, GET /v1/jobs/{id} shows the progress, DELETE /v1/jobs/{id} cancels one.

5. The event stream

GET /v1/events is a Server-Sent Events stream (text/event-stream): changes on the host are sent as they happen, for example vm.state (a virtual machine started, stopped, suspended), vm.added, vm.removed. The web page and the keel manager use it to stay current without polling. After a dropped connection, Last-Event-ID continues where it left off.

curl -k -N -H "Authorization: Bearer keel_…" https://192.168.1.10/v1/events

6. Limits in 1.0

  • The version running on the host is what counts: after an upgrade, look at /v1/openapi.json again.
  • The cookies and the CSRF header of a web login are for the web page itself; scripts should use tokens.
  • Some endpoints are only on the host's local Unix socket (the one the keel command line uses), some only on HTTPS; the OpenAPI document marks the latter with x-keel-https-only.