syntheses:vps-create-flow
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| syntheses:vps-create-flow [22/07/2026 00:29] – Expand VPS create flow with source-verified action sub-points bkirk | syntheses:vps-create-flow [03/08/2026 23:16] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== VPS Creation / Provisioning Flow ====== | ||
| - | This page traces the source-backed flow for creating a VPS from the customer/ | ||
| - | |||
| - | ===== Scope ===== | ||
| - | |||
| - | * Main repo: '' | ||
| - | * Main application area: '' | ||
| - | * Compute execution: HostDaemon and host command handlers | ||
| - | * Related repo: '' | ||
| - | |||
| - | ===== Short Version ===== | ||
| - | |||
| - | - The API accepts a create-server request and validates the customer, plan, OS, network, billing state, and requested options. | ||
| - | - Domain services create a '' | ||
| - | - Provisioning services assign the lease, host, network, primary interface/ | ||
| - | - '' | ||
| - | - HostDaemon polls the '' | ||
| - | - On success, HostDaemon sets the guest status to '' | ||
| - | - On failure, HostDaemon attempts cleanup/ | ||
| - | |||
| - | ===== API and Domain Flow ===== | ||
| - | |||
| - | ==== 1. API request ==== | ||
| - | |||
| - | '' | ||
| - | |||
| - | '' | ||
| - | |||
| - | * fetches the customer via '' | ||
| - | * checks '' | ||
| - | * calls '' | ||
| - | * calls '' | ||
| - | * wraps the guest creation inside '' | ||
| - | * calls '' | ||
| - | * flushes the NHibernate session (line 132) — forces an INSERT so the guest gets a database ID and generated '' | ||
| - | * after the transaction, | ||
| - | * returns an '' | ||
| - | |||
| - | ==== 2. Guest/ | ||
| - | |||
| - | '' | ||
| - | |||
| - | '' | ||
| - | |||
| - | * '' | ||
| - | * guest limit check (line 51) — compares '' | ||
| - | * private IP validation (line 54) — if a specific VPC private IP was requested, validates it belongs to the network via '' | ||
| - | * split NIC validation (line 57) — '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * applies customer-facing options (lines 64-68): sets '' | ||
| - | * referral handling (lines 69-70): looks up the referrer from '' | ||
| - | * '' | ||
| - | * if a specific private IP was requested, overrides the randomly assigned one (line 76): '' | ||
| - | * '' | ||
| - | * referral commit (line 81): if a referrer was found, creates and commits a referral record; | ||
| - | * fraud review gate (lines 87-91): if '' | ||
| - | * '' | ||
| - | |||
| - | ==== 3. Initial guest state ==== | ||
| - | |||
| - | '' | ||
| - | |||
| - | '' | ||
| - | |||
| - | * determines '' | ||
| - | * generates a unique name via '' | ||
| - | * sets initial placeholders: | ||
| - | * sets '' | ||
| - | * generates a rescue password via '' | ||
| - | * '' | ||
| - | * '' | ||
| - | |||
| - | ==== 4. Provisioning assignments ==== | ||
| - | |||
| - | '' | ||
| - | |||
| - | '' | ||
| - | |||
| - | - '' | ||
| - | - '' | ||
| - | - '' | ||
| - | - '' | ||
| - | - '' | ||
| - | - '' | ||
| - | - '' | ||
| - | |||
| - | ===== HostCommand / HostDaemon Flow ===== | ||
| - | |||
| - | ==== 5. CreateGuestCommand is queued ==== | ||
| - | |||
| - | '' | ||
| - | |||
| - | '' | ||
| - | |||
| - | * creates the '' | ||
| - | * attaches customer-facing options: '' | ||
| - | * calls '' | ||
| - | |||
| - | '' | ||
| - | |||
| - | The command declares six customer-visible build steps (lines 21-26): | ||
| - | |||
| - | - Requesting server resources — connects to host shell, validates banned status, checks disk doesn' | ||
| - | - Allocating virtual disk — creates the virtual disk on the compute host; issues licenses early so activation completes before OS install | ||
| - | - Installing operating system — triggers the OS installer on the compute host; configures time machine if enabled | ||
| - | - Starting server — boots the VM on the compute host | ||
| - | - Configuring operating system — waits for guest ping (guest is responsive), | ||
| - | - Processing invoice — finalises the build: sets status to Active, writes system actions, sends customer emails, updates network members | ||
| - | |||
| - | It implements '' | ||
| - | |||
| - | ==== 6. HostDaemon picks up the command ==== | ||
| - | |||
| - | '' | ||
| - | |||
| - | HostDaemon runs a polling loop that repeatedly: | ||
| - | |||
| - | - calls '' | ||
| - | - measures query duration via the transaction scope (lines 81-93) — if obtaining a database connection took longer than '' | ||
| - | - starts the command in a worker thread via '' | ||
| - | |||
| - | Adaptive rest behaviour (lines 58-66): after each iteration, the thread sleeps for a duration proportional to how long the database query took. If the database is responsive, threads spin up quickly. If the connection pool is contended, threads slow down. If no command was found, rests for at least '' | ||
| - | |||
| - | ==== 7. HostDaemon creates the guest ==== | ||
| - | |||
| - | '' | ||
| - | |||
| - | '' | ||
| - | |||
| - | '' | ||
| - | |||
| - | - Step 0 — invoice gate (line 72): calls '' | ||
| - | - Step 1 — Requesting server resources (lines 75-77): connects to the compute host's shell via '' | ||
| - | - Step 2 — Allocating virtual disk (line 80): calls '' | ||
| - | - Step 3 — Installing operating system (line 86): calls '' | ||
| - | - Step 4 — Starting server (line 94): calls '' | ||
| - | - Step 5 — Configuring operating system (line 97): calls '' | ||
| - | - Step 6 — Processing invoice (lines 100-102): calls '' | ||
| - | |||
| - | On success, '' | ||
| - | |||
| - | < | ||
| - | command.Guest.SetStatus(GuestStatus.Active); | ||
| - | _guestService.Commit(command.Guest); | ||
| - | </ | ||
| - | |||
| - | So the source-backed transition is '' | ||
| - | |||
| - | ==== 8. Command completion ==== | ||
| - | |||
| - | '' | ||
| - | |||
| - | '' | ||
| - | |||
| - | * loads the command from the database via '' | ||
| - | * resolves the correct handler via '' | ||
| - | * calls '' | ||
| - | * on success: calls '' | ||
| - | * calls '' | ||
| - | * calls '' | ||
| - | * if the command failed without throwing (succeeded=false), | ||
| - | * if any commit fails, enqueues a '' | ||
| - | |||
| - | There is no separate HTTP callback from HostDaemon to the API. HostDaemon updates the shared database directly via NHibernate/ | ||
| - | |||
| - | ===== Billing Behaviour ===== | ||
| - | |||
| - | Two separate billing concerns operate at different stages: | ||
| - | |||
| - | * **Immediate API-side payment attempt:** After the guest is created and the command queued, '' | ||
| - | * **HostDaemon invoice gate:** Before any build work begins, '' | ||
| - | |||
| - | '' | ||
| - | |||
| - | * refreshes the customer entity via '' | ||
| - | * returns '' | ||
| - | * marks the invoice ready for sending (line 97) — triggers the " | ||
| - | * for zero-dollar invoices, calls '' | ||
| - | * if insufficient customer credit and the customer has a stored card, generates a credit card deposit via '' | ||
| - | * if credit-only mode was requested and there' | ||
| - | * on success, calls '' | ||
| - | |||
| - | HostDaemon does not " | ||
| - | |||
| - | ===== Failure and Recovery Behaviour ===== | ||
| - | |||
| - | ==== Unpaid invoice / pending payment ==== | ||
| - | |||
| - | '' | ||
| - | |||
| - | If the blocking invoice is not paid: | ||
| - | |||
| - | * '' | ||
| - | * '' | ||
| - | * If should cancel: calls the handler' | ||
| - | * Otherwise: calls '' | ||
| - | |||
| - | For create guest cancellation, | ||
| - | |||
| - | * ends the lease via '' | ||
| - | * cancels the invoice via '' | ||
| - | * removes allocated resources via '' | ||
| - | * sets guest status to '' | ||
| - | * commits the guest; | ||
| - | * sends a guest-creation-cancelled email via '' | ||
| - | |||
| - | ==== Exception during provisioning ==== | ||
| - | |||
| - | '' | ||
| - | |||
| - | * logs the failure via '' | ||
| - | * writes a '' | ||
| - | * clears '' | ||
| - | * attempts cleanup (lines 280-284): calls '' | ||
| - | * inside a transaction (line 286): cancels and refunds the invoice via '' | ||
| - | * revokes any licenses via '' | ||
| - | |||
| - | The code comment (lines 307-310) explains that failed creates used to delete the guest entirely, but now leave it suspended so normal automatic termination can clean it up. | ||
| - | |||
| - | ==== Failure while recording command state ==== | ||
| - | |||
| - | '' | ||
| - | |||
| - | If command loading or committing fails, '' | ||
| - | |||
| - | * loads the command; | ||
| - | * runs handler abort logic; | ||
| - | * calls '' | ||
| - | * commits the state via '' | ||
| - | |||
| - | If the failure handler itself fails for non-database reasons, it logs and proceeds rather than retrying indefinitely. | ||
| - | |||
| - | ===== Data / State Transitions ===== | ||
| - | |||
| - | ^ Object ^ Initial / queued state ^ Successful state ^ Failure state ^ | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | |||
| - | ===== Support-Relevant Failure Points ===== | ||
| - | |||
| - | * Customer has unpaid/ | ||
| - | * Customer has no verified payment details / is not subscribed — throws at API level if '' | ||
| - | * Customer is at guest limit — checked at both API and domain level; throws '' | ||
| - | * Plan is inactive or not listable — caught by '' | ||
| - | * No host/ | ||
| - | * HostCommand is blocked by another active command — '' | ||
| - | * Payment cannot be processed — '' | ||
| - | * HostDaemon cannot create disk, install OS, start guest, or reach guest by ping — any of these throws and triggers '' | ||
| - | * HostDaemon/ | ||
| - | |||
| - | ===== Source Files ===== | ||
| - | |||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | |||
| - | ===== Remaining Questions ===== | ||
| - | |||
| - | * Which customer-visible status label maps to internal '' | ||
| - | * Which operational job performs automatic cleanup/ | ||
| - | * Which logs/ | ||
| - | |||
| - | ===== Related Wiki Pages ===== | ||
| - | |||
| - | * [[compute-host-stack|Compute Host Stack]] | ||
| - | * [[compute-repo-structure|vps/ | ||
| - | * [[infrastructure-services|Infrastructure Services]] | ||
| - | * [[wiki: | ||
syntheses/vps-create-flow.1784680199.txt.gz · Last modified: by bkirk
