api

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package api is a thin client for the Aquanode control API. Today it covers the device-login (pairing) endpoints used by `aq login`.

Index

Constants

View Source
const SSHPort = 22

SSHPort is the internal logical port a box's sshd is published on. Deployment rows key their service_urls entries by this port on every provider.

Variables

View Source
var Version = "0.0.0-dev"

Version is the aq build version. `main` overwrites it at startup from its own ldflags-injected `version`, so this package can label its requests without importing main.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Status  int
	Message string
	Data    json.RawMessage
}

APIError carries a non-success orchestrator response.

func (*APIError) Error

func (e *APIError) Error() string

type Client

type Client struct {
	BaseURL string
	HTTP    *http.Client
	APIKey  string // x-api-key (the aq_sk_… token from `aq login`)
	TeamID  string // x-team-id (required by team-scoped routes like /deployments)
}

Client talks to the Aquanode API base (e.g. https://server.aquanode.io/api/v1).

The device-login endpoints are public; the funnel endpoints (`up`, status, ssh-keys) require auth. When APIKey/TeamID are set they are sent as the `x-api-key` / `x-team-id` headers the orchestrator expects.

func New

func New(baseURL string) *Client

New returns a Client for the given base URL with a sane default timeout.

func NewAuthed

func NewAuthed(baseURL, apiKey, teamID string) *Client

NewAuthed returns a Client that sends the API key + team id on every request.

func (*Client) CloseDeployment

func (c *Client) CloseDeployment(deploymentID int) (*CloseResult, error)

CloseDeployment requests termination of a deployment (`aq down`). The orchestrator validates team ownership and tears the box down asynchronously.

func (*Client) CreateSSHKey

func (c *Client) CreateSSHKey(name, publicKey string) (*SSHKey, error)

CreateSSHKey registers a public key and returns the created row (with its id).

func (*Client) CreateSnapshot added in v0.3.0

func (c *Client) CreateSnapshot(deploymentID int, req CreateSnapshotRequest) (CreateSnapshotResult, error)

CreateSnapshot takes a one-shot snapshot of a managed deployment. This is the managed path: the orchestrator drives the box's ogre agent and records the snapshot against the deployment. It is deliberately NOT the standalone `ogre snapshot` CLI, which is for boxes with no Aquanode deployment.

func (*Client) Deploy

func (c *Client) Deploy(req DeployRequest) (*UpResult, error)

Deploy rents the cheapest matching GPU and restores the given snapshot onto it.

func (*Client) DeploymentStatus

func (c *Client) DeploymentStatus(deploymentID int) (*DeploymentStatusResult, error)

DeploymentStatus fetches the current status of a deployment.

func (*Client) GetIdlePolicy added in v0.3.0

func (c *Client) GetIdlePolicy(deploymentID int) (*IdlePolicy, error)

GetIdlePolicy fetches a deployment's merged idle-auto-stop policy and its current live verdict.

func (*Client) GetProjectDeployment

func (c *Client) GetProjectDeployment(projectID string) (*Deployment, error)

GetProjectDeployment returns the current (active or paused) deployment under a project, via GET /deployments/project/:projectId. `aq down`/`aq status` use it to accept a project id (the UUID in the console URL) in place of the numeric deployment id (#209). A project with no live deployment yields a 404 APIError.

func (*Client) ListDeployments added in v0.2.0

func (c *Client) ListDeployments() ([]Deployment, error)

ListDeployments returns every deployment on the caller's team, newest first.

Two properties of GET /deployments to keep in mind: it takes no filters (the documented `type`/`provider`/`sortByTime` query params are parsed by a schema the controller never reads), and it returns the team's FULL history including CLOSED and FAILED rows. Callers must filter client-side, and should only call it where a list is genuinely needed — on a long-lived team it is a large response.

func (*Client) ListSSHKeys

func (c *Client) ListSSHKeys() ([]SSHKey, error)

ListSSHKeys returns the caller's registered SSH keys.

func (*Client) PollDevice

func (c *Client) PollDevice(deviceCode string) (*DevicePoll, error)

PollDevice polls a pairing by its device code.

func (*Client) SetIdlePolicy added in v0.3.0

func (c *Client) SetIdlePolicy(deploymentID int, req IdlePolicyUpdate) (*IdlePolicy, error)

SetIdlePolicy updates a deployment's idle-auto-stop policy and returns the resulting merged policy plus live verdict. The orchestrator is the real authority on validity (e.g. warnAfterMinutes < actAfterMinutes) — this only shapes the request.

func (*Client) SnapshotHistory added in v0.3.0

func (c *Client) SnapshotHistory() ([]SnapshotHistoryItem, error)

SnapshotHistory lists every snapshot the account owns, including external/CLI ones with no source deployment.

func (*Client) StartDevice

func (c *Client) StartDevice(clientName string, scopes []string) (*DeviceStart, error)

StartDevice begins a pairing.

func (*Client) Up

func (c *Client) Up(req UpRequest) (*UpResult, error)

Up rents the cheapest matching GPU and brings up the requested template env.

type CloseResult

type CloseResult struct {
	Status string `json:"status"`
}

CloseResult mirrors POST /deployments/close.

type CreateSnapshotRequest added in v0.3.0

type CreateSnapshotRequest struct {
	BackupID         string `json:"backup_id"`
	WorkspaceDir     string `json:"workspace_dir"`
	IncludeProcess   bool   `json:"include_process"`
	IncludeWorkspace bool   `json:"include_workspace"`
}

CreateSnapshotRequest is the body of POST /snapshots/:deploymentId/create — the managed one-shot save path. BackupID identifies the backup row this snapshot belongs to (the orchestrator creates one on first use if it doesn't already exist); it is not a deployment id.

type CreateSnapshotResult added in v0.3.0

type CreateSnapshotResult struct {
	SnapshotID string `json:"snapshot_id"`
	Size       int64  `json:"size"`
	Message    string `json:"message"`
}

CreateSnapshotResult is the data returned by POST /snapshots/:deploymentId/create. SnapshotID is the underlying restic snapshot id (a string, not a database row id) — it identifies the capture, but restoring it goes through `aq deploy --snapshot <deploymentId>` (the SOURCE deployment id), never through this string.

type DeployRequest

type DeployRequest struct {
	// SnapshotSource is a numeric deployment id or a synthetic `ext-<backupId>`
	// for a standalone-CLI snapshot (#177).
	SnapshotSource string  `json:"snapshotSource"`
	SSHKeyID       string  `json:"sshKeyId"`
	Template       string  `json:"template,omitempty"`
	GPUModel       string  `json:"gpuModel,omitempty"`
	MaxPrice       float64 `json:"maxPrice,omitempty"`
	Provider       string  `json:"provider,omitempty"`
	// Name sets the deployment's display name; empty → orchestrator-generated.
	// A stable `ticket-<N>-<label>` makes the throwaway box reapable (#310).
	Name string `json:"name,omitempty"`
}

DeployRequest is the body of POST /deployments/deploy-snapshot — the OSS→compute bridge. It rents the cheapest matching GPU and restores a snapshot onto it, optionally relaunching an app template on the restored data (#180).

type Deployment

type Deployment struct {
	ID                 int                 `json:"id"`
	Name               string              `json:"name"`
	Status             string              `json:"status"`
	AppURL             string              `json:"app_url"`
	ServiceCredentials *ServiceCredentials `json:"service_credentials"`
	// ServiceURLs stays raw so a malformed or unexpectedly-shaped value (the
	// column is a free-form Json defaulting to "[]") can never fail the whole
	// row's decode. SSHServiceURL parses it on demand.
	ServiceURLs json.RawMessage `json:"service_urls"`
	// RestoreStatus/RestoreError carry the server-side snapshot restore outcome
	// for `aq deploy` (#235): SUCCESS / PARTIAL / FAILED, plus a detail string.
	// Empty for a plain `aq up` (no restore) or a backend that predates the field.
	RestoreStatus string `json:"restore_status"`
	RestoreError  string `json:"restore_error"`
}

Deployment is the subset of the deployment row `aq up` polling cares about.

Every tag MUST stay in snake_case form. GET /deployments/:id/status runs rows through transformDeploymentData and so carries snake_case *plus* camelCase duplicates, but GET /deployments (the list) does not transform — its rows are snake_case only. A camelCase tag would decode the status endpoint and silently yield zero values for every list row.

func (Deployment) SSHServiceURL added in v0.2.0

func (d Deployment) SSHServiceURL() (string, bool)

SSHServiceURL returns the deployment's port-22 service URL.

This is authoritative for SSH in a way app_url is not: simplepod silently publishes the ogre agent's HTTP port as app_url when the box maps no SSH port, so dialing app_url there reaches an HTTP server rather than sshd. The service_urls entry is keyed by the *internal* port, so port 22 is unambiguous and simply absent on a box with no SSH.

type DeploymentStatusResult

type DeploymentStatusResult struct {
	DeploymentID int        `json:"deploymentId"`
	Status       string     `json:"status"`
	Deployment   Deployment `json:"deployment"`
}

DeploymentStatusResult mirrors GET /deployments/:id/status.

type DevicePoll

type DevicePoll struct {
	Status string `json:"status"` // pending | approved | denied | expired | consumed | slow_down
	// Interval, when > 0, is the cadence (seconds) the server wants the CLI to
	// poll at from now on (RFC 8628 §3.5). The CLI only ever slows down to it.
	Interval int      `json:"interval"`
	Token    string   `json:"token"`
	Scopes   []string `json:"scopes"`
	TeamID   string   `json:"teamId"`
	KeyName  string   `json:"keyName"`
}

DevicePoll is the result of POST /api-keys/device/token.

type DeviceStart

type DeviceStart struct {
	DeviceCode              string   `json:"deviceCode"`
	UserCode                string   `json:"userCode"`
	Scopes                  []string `json:"scopes"`
	VerificationURI         string   `json:"verificationUri"`
	VerificationURIComplete string   `json:"verificationUriComplete"`
	Interval                int      `json:"interval"`
	ExpiresIn               int      `json:"expiresIn"`
}

DeviceStart is the result of POST /api-keys/device/start.

type IdlePolicy added in v0.3.0

type IdlePolicy struct {
	WarnAfterMinutes        int  `json:"warnAfterMinutes"`
	ActAfterMinutes         int  `json:"actAfterMinutes"`
	GPUIdleThresholdPercent int  `json:"gpuIdleThresholdPercent"`
	AutoStopEnabled         bool `json:"autoStopEnabled"`
	// State is one of UNKNOWN | ACTIVE | IDLE_WARN | IDLE_ACT. UNKNOWN means the
	// box has reported no usable usage data yet — render it as unknown, never as
	// active or idle: presenting a no-data verdict as either extreme is a lie the
	// user could act on.
	State string `json:"state"`
	// IdleMinutes is only meaningful once State is IDLE_WARN or IDLE_ACT.
	IdleMinutes int `json:"idleMinutes"`
}

IdlePolicy mirrors GET /deployments/:deploymentId/idle-policy: the deployment's merged idle-auto-stop policy plus a live verdict computed from its current usage data.

type IdlePolicyUpdate added in v0.3.0

type IdlePolicyUpdate struct {
	WarnAfterMinutes        *int  `json:"warnAfterMinutes,omitempty"`
	ActAfterMinutes         *int  `json:"actAfterMinutes,omitempty"`
	GPUIdleThresholdPercent *int  `json:"gpuIdleThresholdPercent,omitempty"`
	AutoStopEnabled         *bool `json:"autoStopEnabled,omitempty"`
}

IdlePolicyUpdate is the body of PUT /deployments/:deploymentId/idle-policy. Every field is optional and a nil field is omitted from the request entirely (via `omitempty` on the pointer), so a flag the user never passed can never round-trip as a zero-value that silently overwrites one of their other settings.

type SSHKey

type SSHKey struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	PublicKey string `json:"public_key"`
}

SSHKey mirrors a row from GET /settings/ssh-keys.

type ServiceCredentials

type ServiceCredentials struct {
	Template string `json:"template"`
	URL      string `json:"url"`
	Username string `json:"username"`
	Password string `json:"password"`
	Status   string `json:"status"`
}

ServiceCredentials is the running template service's reachable URL + auth, as surfaced on the deployment row once ogre has started the service.

type ServiceURL added in v0.2.0

type ServiceURL struct {
	URL  string `json:"url"`
	Port portID `json:"port"`
}

ServiceURL is one entry of a deployment's service_urls array: a reachable URL keyed by the internal logical port it maps.

type SnapshotHistoryBackup added in v0.3.0

type SnapshotHistoryBackup struct {
	DeploymentID int    `json:"deployment_id"`
	Path         string `json:"path"`
}

SnapshotHistoryBackup is the `backups` object nested on a history item, carrying the source deployment this snapshot belongs to. It is nil for an external/CLI snapshot (no Aquanode deployment).

type SnapshotHistoryItem added in v0.3.0

type SnapshotHistoryItem struct {
	ID        int                    `json:"id"`
	BackupID  int                    `json:"backup_id"`
	Path      string                 `json:"path"`
	Status    string                 `json:"status"`
	Size      int64                  `json:"size"`
	Type      string                 `json:"type"`
	CreatedAt string                 `json:"created_at"`
	Backups   *SnapshotHistoryBackup `json:"backups"`
}

SnapshotHistoryItem mirrors one row of GET /snapshots/history. The top-level BackupID is the internal backup ROW id — NOT a deployment id; a snapshot is associated with its owning deployment via Backups.DeploymentID instead.

type UpRequest

type UpRequest struct {
	Template string  `json:"template"`
	SSHKeyID string  `json:"sshKeyId"`
	GPUModel string  `json:"gpuModel,omitempty"`
	MaxPrice float64 `json:"maxPrice,omitempty"`
	Provider string  `json:"provider,omitempty"`
	// Name sets the deployment's display name. When empty the orchestrator
	// falls back to a generated "<Adjective> <GPU> from <Region>" name. Passing
	// a stable `ticket-<N>-<label>` here lets the session-scoped reaper attribute
	// and clean up a throwaway box that would otherwise bill as an orphan (#310).
	Name string `json:"name,omitempty"`
	// IdlePolicy opts a fresh deployment into idle-auto-stop at creation time.
	// Nil (the Go zero value for a pointer) omits the key entirely — the console
	// shows a visible, pre-checked box a user can see and untick, but the CLI has
	// no such surface, so silence here must mean "no opinion, use the
	// orchestrator's defaults," never "explicitly off."
	IdlePolicy *IdlePolicyUpdate `json:"idlePolicy,omitempty"`
}

UpRequest is the body of POST /deployments/up.

type UpResult

type UpResult struct {
	DeploymentID int    `json:"deploymentId"`
	ProjectID    string `json:"projectId"`
	Status       string `json:"status"`
	Message      string `json:"message"`
}

UpResult is the data returned by POST /deployments/up.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL