lablink_allocator_service.routes.provisioning¶
lablink_allocator_service.routes.provisioning
¶
Host provisioning and destruction, plus operation-job status reads.
/api/launch and /destroy do not run tofu inline — they submit a
job to OperationsWorker and return 202 (or a redirect), and the admin
dashboard polls /api/operations for progress. Both are capability-gated
on the provider (can_provision_hosts / can_destroy_hosts) rather than
on provider type.
Every handler answers twice: JSON when the caller prefers it (the CLI), a redirect back to /admin/instances otherwise (the dashboard's HTML forms).
Attributes¶
bp = Blueprint('provisioning', __name__)
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
Functions:¶
destroy()
¶
Destroy all client VMs.
Enqueues an async destroy operation: the background worker runs
tofu destroy to terminate all client EC2 instances and associated
resources, then clears all records from the vms table. This is a
destructive action. Driven by lablink client destroy, and by
lablink destroy as its first teardown step. Open session-metrics rows
are sealed (best-effort) before teardown so final sessions keep a
duration.
Request Body: None
Success Response:
- Code:
202 Acceptedwith{"job_id": 8, "status": "queued"}for JSON clients; browsers get302→/admin/instances?job=<id>.
Error Response:
- Code:
409 Conflictwhen another operation is already in progress. - Code:
405 Method Not Allowedwhen the provider cannot destroy hosts (manual).
Source code in packages/allocator/src/lablink_allocator_service/routes/provisioning.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
get_operation(operation_id)
¶
Get one operation.
Returns one operation, including its captured output and error.
This is what the CLI polls while client launch runs.
Error Response:
- Code:
404 Not Foundif the operation does not exist.
Source code in packages/allocator/src/lablink_allocator_service/routes/provisioning.py
launch()
¶
Launch new client VMs.
Takes a number of VMs to create and enqueues an async apply operation;
the background worker generates an OpenTofu variables file and runs
tofu apply to provision the new instances. Poll GET /api/operations
for progress. Rejected with 405 when the provider cannot provision
hosts (manual).
Request Body: application/x-www-form-urlencoded
num_vms(integer, required): The number of new VMs to launch.
Success Response:
- Code:
202 Acceptedwith{"job_id": 7, "status": "queued"}for JSON clients; browsers get302→/admin/instances?job=<id>.
Error Response:
- Code:
409 Conflictwhen another operation is already in progress; the body carries the in-flightjob_id. - Code:
400 Bad Requestfor a missing or non-positivenum_vms.
Source code in packages/allocator/src/lablink_allocator_service/routes/provisioning.py
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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
list_operations()
¶
List recent operations.
Returns recent operations with their op_type, status, timestamps,
and resources_completed / resources_total progress counters.
?status=in_progress returns just the currently running operation, if
any.