-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.http
More file actions
427 lines (334 loc) · 9.37 KB
/
Copy pathapi.http
File metadata and controls
427 lines (334 loc) · 9.37 KB
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
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
191
192
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
### LXD Management API — request collection
### Works in VS Code "REST Client" extension and JetBrains HTTP Client.
###
### Usage:
### 1. Run the API (make up) and seed an admin (SEED_ADMIN_* in .env).
### 2. Send the "Login" request; copy the access_token into @token below.
### 3. Send any other request.
###
### Variables ----------------------------------------------------------------
@host = http://localhost:8000
@token = PASTE_ACCESS_TOKEN_HERE
@auth = Authorization: Bearer {{token}}
@json = Content-Type: application/json
### -------------------------------------------------------------------------
### Health & system
### -------------------------------------------------------------------------
### Unversioned liveness (no auth)
GET {{host}}/health
### Deep health (checks LXD connectivity) — no auth
GET {{host}}/api/v1/system/health
### LXD server info (version, auth, addresses)
GET {{host}}/api/v1/system/info
{{auth}}
### Host resources (CPU, memory, storage, network)
GET {{host}}/api/v1/system/resources
{{auth}}
### Pool-specific resource usage
GET {{host}}/api/v1/system/storage-pools/default/resources
{{auth}}
### -------------------------------------------------------------------------
### Auth
### -------------------------------------------------------------------------
### Register a new user (admin only)
# @name register
POST {{host}}/api/v1/auth/register
{{auth}}
{{json}}
{
"username": "operator1",
"password": "operator-pass-123",
"role": "operator"
}
### Login -> access + refresh tokens
# @name login
POST {{host}}/api/v1/auth/login
{{json}}
{
"username": "admin",
"password": "changeme123"
}
### Refresh the access token
POST {{host}}/api/v1/auth/refresh
{{json}}
{
"refresh_token": "PASTE_REFRESH_TOKEN_HERE"
}
### Current user
GET {{host}}/api/v1/auth/me
{{auth}}
### List users (admin only)
GET {{host}}/api/v1/auth/users
{{auth}}
### -------------------------------------------------------------------------
### Instances
### -------------------------------------------------------------------------
### List instances (full objects, paginated, optional project/type/filter)
GET {{host}}/api/v1/instances?limit=20&offset=0&project=default
{{auth}}
### List only virtual machines
GET {{host}}/api/v1/instances?instance-type=virtual-machine
{{auth}}
### OData filter: running instances only
GET {{host}}/api/v1/instances?filter=status%20eq%20Running
{{auth}}
### Create an instance (async -> returns operation ref)
# @name createInstance
POST {{host}}/api/v1/instances
{{auth}}
{{json}}
{
"name": "web1",
"instance_type": "container",
"source": {
"type": "image",
"alias": "ubuntu/22.04"
},
"config": {
"limits.cpu": "2",
"limits.memory": "2GiB"
}
}
### Get an instance
GET {{host}}/api/v1/instances/web1
{{auth}}
### Update (full replace, async)
PUT {{host}}/api/v1/instances/web1
{{auth}}
{{json}}
{
"config": {"limits.cpu": "4"},
"description": "web server"
}
### Patch (partial update, async)
PATCH {{host}}/api/v1/instances/web1
{{auth}}
{{json}}
{
"description": "patched description"
}
### Delete (async)
DELETE {{host}}/api/v1/instances/web1
{{auth}}
### Instance state (CPU/mem/net/IPs)
GET {{host}}/api/v1/instances/web1/state
{{auth}}
### Start instance (async; ?wait=true blocks until started)
PUT {{host}}/api/v1/instances/web1/state
{{auth}}
{{json}}
{
"action": "start",
"timeout": 60
}
### Stop instance
PUT {{host}}/api/v1/instances/web1/state
{{auth}}
{{json}}
{"action": "stop", "force": false}
### Restart
PUT {{host}}/api/v1/instances/web1/state
{{auth}}
{{json}}
{"action": "restart"}
### Freeze / unfreeze
PUT {{host}}/api/v1/instances/web1/state
{{auth}}
{{json}}
{"action": "freeze"}
### Exec (non-interactive) — triggers an operation
POST {{host}}/api/v1/instances/web1/exec
{{auth}}
{{json}}
{
"command": ["/bin/ls", "-la", "/"],
"interactive": false
}
### Interactive exec over WebSocket (use a WS client, not REST client):
# ws://localhost:8000/api/v1/instances/web1/exec/ws?token={{token}}&command=/bin/bash
### Console over WebSocket:
# ws://localhost:8000/api/v1/instances/web1/console/ws?token={{token}}
### List log files
GET {{host}}/api/v1/instances/web1/logs
{{auth}}
### Stream a log file
GET {{host}}/api/v1/instances/web1/logs/lxc.log
{{auth}}
### -------------------------------------------------------------------------
### Snapshots
### -------------------------------------------------------------------------
### List snapshots
GET {{host}}/api/v1/instances/web1/snapshots
{{auth}}
### Create a snapshot (async)
POST {{host}}/api/v1/instances/web1/snapshots
{{auth}}
{{json}}
{
"name": "snap-001",
"stateful": false
}
### Restore from a snapshot (async)
POST {{host}}/api/v1/instances/web1/snapshots/snap-001/restore
{{auth}}
### Delete a snapshot (async)
DELETE {{host}}/api/v1/instances/web1/snapshots/snap-001
{{auth}}
### -------------------------------------------------------------------------
### Backups
### -------------------------------------------------------------------------
### List backups
GET {{host}}/api/v1/instances/web1/backups
{{auth}}
### Create a backup (async; build the tarball in the background)
POST {{host}}/api/v1/instances/web1/backups
{{auth}}
{{json}}
{
"name": "bk-001",
"instance_only": false,
"optimized_storage": true,
"compression_algorithm": "gzip"
}
### Download the backup tarball
GET {{host}}/api/v1/instances/web1/backups/bk-001/export
{{auth}}
### Delete a backup (async)
DELETE {{host}}/api/v1/instances/web1/backups/bk-001
{{auth}}
### -------------------------------------------------------------------------
### Storage
### -------------------------------------------------------------------------
### List storage pools
GET {{host}}/api/v1/storage/pools
{{auth}}
### Create a storage pool (async)
POST {{host}}/api/v1/storage/pools
{{auth}}
{{json}}
{
"name": "fast",
"driver": "zfs",
"config": {"size": "50GB"}
}
### Get / update / patch / delete a pool
GET {{host}}/api/v1/storage/pools/fast
{{auth}}
PATCH {{host}}/api/v1/storage/pools/fast
{{auth}}
{{json}}
{"config": {"zfs.pool_name": "fast"}}
DELETE {{host}}/api/v1/storage/pools/fast
{{auth}}
### List volumes in a pool
GET {{host}}/api/v1/storage/pools/default/volumes
{{auth}}
### Create a custom volume (async)
POST {{host}}/api/v1/storage/pools/default/volumes
{{auth}}
{{json}}
{
"name": "shared",
"type": "custom",
"content_type": "filesystem",
"config": {"size": "5GB"}
}
### Resize a custom volume (patch config.size)
PATCH {{host}}/api/v1/storage/pools/default/volumes/custom/shared
{{auth}}
{{json}}
{"config": {"size": "10GB"}}
### Attach a custom volume to an instance (async)
POST {{host}}/api/v1/storage/pools/default/volumes/custom/shared/attach?instance=web1
{{auth}}
### Detach (async)
POST {{host}}/api/v1/storage/pools/default/volumes/custom/shared/detach?instance=web1
{{auth}}
### -------------------------------------------------------------------------
### Networks
### -------------------------------------------------------------------------
### List networks
GET {{host}}/api/v1/networks
{{auth}}
### Create a managed network (async)
POST {{host}}/api/v1/networks
{{auth}}
{{json}}
{
"name": "lxdbr1",
"type": "bridge",
"config": {
"ipv4.address": "10.100.0.1/24",
"ipv4.nat": "true"
}
}
### Network state (leases / counters)
GET {{host}}/api/v1/networks/lxdbr0/state
{{auth}}
### Attach a NIC to an instance (async)
POST {{host}}/api/v1/networks/lxdbr0/attach?instance=web1&device_name=eth1&nic_name=eth1
{{auth}}
### Detach (async)
POST {{host}}/api/v1/networks/lxdbr0/detach?instance=web1&device_name=eth1
{{auth}}
### -------------------------------------------------------------------------
### Projects
### -------------------------------------------------------------------------
### List projects
GET {{host}}/api/v1/projects
{{auth}}
### Create a project (async)
POST {{host}}/api/v1/projects
{{auth}}
{{json}}
{
"name": "staging",
"config": {"features.images": "true"}
}
### Scoped request: list instances in the staging project
GET {{host}}/api/v1/instances?project=staging
{{auth}}
### -------------------------------------------------------------------------
### Images
### -------------------------------------------------------------------------
### List local images
GET {{host}}/api/v1/images
{{auth}}
### Copy/import an image from a remote server (async -> operation ref)
POST {{host}}/api/v1/images
{{auth}}
{{json}}
{
"source": {
"type": "image",
"alias": "ubuntu/22.04",
"server": "https://images.linuxcontainers.org",
"protocol": "simplestreams"
},
"auto_update": true
}
### Create an alias for an image
POST {{host}}/api/v1/images/aliases
{{auth}}
{{json}}
{
"name": "ubuntu-2204",
"target": "PASTE_FINGERPRINT_HERE"
}
### -------------------------------------------------------------------------
### Operations (async ops)
### -------------------------------------------------------------------------
### List running operations
GET {{host}}/api/v1/operations
{{auth}}
### Get an operation's status
GET {{host}}/api/v1/operations/OPERATION_ID_HERE
{{auth}}
### Long-poll wait for completion (?timeout in seconds; 0 = unbounded)
GET {{host}}/api/v1/operations/OPERATION_ID_HERE/wait?timeout=30
{{auth}}
### Cancel an operation (operator+)
DELETE {{host}}/api/v1/operations/OPERATION_ID_HERE
{{auth}}
### Subscribe to live operation events over WebSocket:
# ws://localhost:8000/api/v1/operations/ws?token={{token}}