Internals
Architecture
This page explains runtime flow from CLI/SDK input to typed service responses and persisted runtime state.
Runtime Data Flow
flowchart LR
A["CLI (Typer) or Python caller"] --> B["SpotClient / AsyncSpotClient"]
B --> C["Config resolution + migration"]
B --> D["StateStore (sqlite)"]
B --> E["SpotTransport"]
E --> F["Auth/token lifecycle"]
E --> G["Retry + cache policies"]
G --> H["Rackspace Spot APIs"]
H --> I["JSON response"]
I --> J["Pydantic model validation"]
J --> K["CLI output renderer or SDK return value"]
Package Layout
src/rsspot/clientasync_client.py: async core runtimesync_client.py: unified sync/async wrappersingleton.py: global configure/singleton/context helpers
src/rsspot/config- model definitions, loader precedence, legacy migration
src/rsspot/state- sqlite-backed preferences/cache/history/registration ledger
src/rsspot/http- transport, retry policy, cache policy
src/rsspot/services- typed API domain facades
src/rsspot/workflows- VM registration orchestration primitives
Config and State Resolution
Config path resolution:
- Runtime config dict/model
- Explicit
config_path - Env path (
RSSPOT_CONFIG*) - Default
~/.config/rsspot/config.* - Legacy
~/.spot_configmigration fallback
State path resolution:
- Explicit
state_path - Config
state_path <resolved-config-dir>/state.db~/.config/rsspot/state.dbfallback
Unified Client Contract
SpotClient provides:
- sync grouped APIs:
organizations,regions,server_classes,pricing,cloudspaces,spot_nodepools,ondemand_nodepools,inventory - async grouped APIs with
aprefix:aorganizations,aregions, …
Constraint:
- Sync methods raise a runtime error when called inside an active event loop.
Retry, Auth, and Cache Model
- Auth token lifecycle:
- reuse valid id token
- refresh via
POST <oauth_url>/oauth/tokenwhen needed
- Retry policy:
- status- and exception-based retries with jittered backoff
- Cache policy:
- GET-only caching by default
- in-memory front cache + sqlite backend
- mutation-triggered invalidation by API path prefix
Persistent State Schema
state.db tables:
preferenceshttp_cachecommand_historyregistration_ledger
Extension Points
- Add endpoint coverage:
- add/extend method in
services/* - add model in
models/* - expose CLI command where needed
- Tune runtime behavior:
- retry/cache defaults in config models
- env aliases in
settings.py
- Compose registration automation:
- use
RegistrationWorkflow+StateStore - orchestrate external Omni integration without direct dependency