Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | import api from './axios' import type { Deployment, DeploymentWithRelations, DeploymentCreate, DeploymentQueryParams, DeploymentResourceListResponse, DeploymentResource, } from '@/types' // ---------------------------------------------------------------- // DEPLOYMENT API // ---------------------------------------------------------------- export const deploymentApi = { /** * Get all deployments (filtered by role) */ list: (params?: DeploymentQueryParams) => { return api.get<Deployment[]>('/deployments/', { params }) }, /** * Get deployment by ID with relations */ getById: (deploymentId: string) => { return api.get<DeploymentWithRelations>(`/deployments/${deploymentId}`) }, /** * Create deployment */ create: (data: DeploymentCreate) => { return api.post<Deployment>('/deployments/', data) }, /** * Delete a deployment. * * The backend picks the right behaviour based on status: * * ``success``/``failed``/``paused`` → returns 202 ``{task_id, status}`` and * dispatches a Destroy worker task; the SSE stream surfaces the * terraform-destroy progress and the row is auto-soft-deleted on * success. * * ``cancelled`` → 204, immediate soft-delete (no resources to * clean up). * * anything in flight → 409. * * Callers should branch on ``response.status``: 202 means "watch the * live stream, eventually we get redirected", 204 means "done". */ delete: (deploymentId: string) => { return api.delete(`/deployments/${deploymentId}`) }, /** * Pause a running deployment. * * Halts the OpenStack compute instances of the deployment without * tearing them down — volumes and networks are preserved so resume * restores the same instances byte-for-byte. * * Owner-only. Allowed only when status is ``success``. Returns 202 * with ``{task_id, status: "pausing"}``; the frontend should attach * to the SSE stream just like for delete/destroy. */ pause: (deploymentId: string) => { return api.post<{ task_id: string; status: 'pausing' }>( `/deployments/${deploymentId}/pause`, ) }, /** * Resume a paused deployment. * * Owner-only. Allowed only when status is ``paused``. Same response * shape as ``pause`` but with ``status: "resuming"``. */ resume: (deploymentId: string) => { return api.post<{ task_id: string; status: 'resuming' }>( `/deployments/${deploymentId}/resume`, ) }, /** * Re-send the per-user access mail for one team member of a * deployment. Reuses the credentials from the latest successful * DEPLOY task's terraform outputs, so this only works after a * deploy has completed. 409 if there's nothing to resend yet, * 502 if SMTP rejected the mail. */ resendAccess: (deploymentId: string, teamId: string, userId: string) => { return api.post( `/deployments/${deploymentId}/teams/${teamId}/users/${userId}/resend-access`, ) }, /** * List the deployment's infrastructure resources (Stage-1 view). * * Parses the most-recent task's cached Terraform state and (by * default) overlays a live OpenStack fetch per compute instance so * the UI sees the ECHTEN power state, fault message, IPs, etc. * * Pass ``refresh=false`` to skip the live fetch — useful during * tight polling loops (the cached state still reflects what * terraform last wrote, just not the post-apply lifecycle). * * Owner-only. 412 when the user has no OpenStack credentials, * 502 when OpenStack itself is unreachable. */ listResources: (deploymentId: string, options?: { refresh?: boolean }) => { return api.get<DeploymentResourceListResponse>( `/deployments/${deploymentId}/resources`, { params: { refresh: options?.refresh ?? true } }, ) }, /** * Stage-2 detail for a single compute instance, by Terraform state * address. The address is the same string ``terraform state list`` * prints — for the typical ``for_each = toset(teams)`` shape that * means ``openstack_compute_instance_v2.team_ide["Team-A"]``. * * Loaded lazily by the drawer in ``InfrastructureVmCard`` when the * user clicks "Details". Adds ports, security-group summaries, * volume attachments, the resolved image name, and the full * metadata map on top of the stage-1 fields. */ getResourceDetail: (deploymentId: string, address: string) => { return api.get<DeploymentResource>( `/deployments/${deploymentId}/resources/${encodeURIComponent(address)}`, ) }, /** * Replace a single compute instance via * ``terraform apply -replace=<addr> -target=<addr>``. Spawns a * dedicated ``REDEPLOY`` Celery task — the SSE stream picks it * up just like deploy/destroy/pause/resume. * * Backend enforces that the address is a known compute-instance * in the cached state; anything else is 422 (non_redeployable_ * resource_type) so the UI can surface a clear "you can only * redeploy VMs" message. Returns 202 with ``{task_id, status: * 'redeploying'}``. */ redeployResource: (deploymentId: string, address: string) => { return api.post<{ task_id: string; status: 'redeploying' }>( `/deployments/${deploymentId}/resources/${encodeURIComponent(address)}/redeploy`, ) }, } |