This repository was archived by the owner on Apr 21, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathvm.go
More file actions
676 lines (576 loc) · 22.7 KB
/
Copy pathvm.go
File metadata and controls
676 lines (576 loc) · 22.7 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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package vers
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"slices"
"time"
"github.com/hdresearch/vers-sdk-go/internal/apijson"
"github.com/hdresearch/vers-sdk-go/internal/apiquery"
"github.com/hdresearch/vers-sdk-go/internal/param"
"github.com/hdresearch/vers-sdk-go/internal/requestconfig"
"github.com/hdresearch/vers-sdk-go/option"
)
// VmService contains methods and other services that help with interacting with
// the vers API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewVmService] method instead.
type VmService struct {
Options []option.RequestOption
}
// NewVmService generates a new service that applies the given options to each
// request. These options are applied after the parent client's options (if there
// is one), and before any request-specific options.
func NewVmService(opts ...option.RequestOption) (r *VmService) {
r = &VmService{}
r.Options = opts
return
}
func (r *VmService) List(ctx context.Context, opts ...option.RequestOption) (res *[]Vm, err error) {
opts = slices.Concat(r.Options, opts)
path := "api/v1/vms"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
func (r *VmService) Delete(ctx context.Context, vmID string, body VmDeleteParams, opts ...option.RequestOption) (res *VmDeleteResponse, err error) {
opts = slices.Concat(r.Options, opts)
if vmID == "" {
err = errors.New("missing required vm_id parameter")
return nil, err
}
path := fmt.Sprintf("api/v1/vm/%s", vmID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, body, &res, opts...)
return res, err
}
func (r *VmService) Branch(ctx context.Context, vmOrCommitID string, body VmBranchParams, opts ...option.RequestOption) (res *NewVmsResponse, err error) {
opts = slices.Concat(r.Options, opts)
if vmOrCommitID == "" {
err = errors.New("missing required vm_or_commit_id parameter")
return nil, err
}
path := fmt.Sprintf("api/v1/vm/%s/branch", vmOrCommitID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
func (r *VmService) BranchByCommit(ctx context.Context, commitID string, body VmBranchByCommitParams, opts ...option.RequestOption) (res *NewVmsResponse, err error) {
opts = slices.Concat(r.Options, opts)
if commitID == "" {
err = errors.New("missing required commit_id parameter")
return nil, err
}
path := fmt.Sprintf("api/v1/vm/branch/by_commit/%s", commitID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
func (r *VmService) BranchByTag(ctx context.Context, tagName string, body VmBranchByTagParams, opts ...option.RequestOption) (res *NewVmsResponse, err error) {
opts = slices.Concat(r.Options, opts)
if tagName == "" {
err = errors.New("missing required tag_name parameter")
return nil, err
}
path := fmt.Sprintf("api/v1/vm/branch/by_tag/%s", tagName)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
func (r *VmService) BranchByVm(ctx context.Context, vmID string, body VmBranchByVmParams, opts ...option.RequestOption) (res *NewVmsResponse, err error) {
opts = slices.Concat(r.Options, opts)
if vmID == "" {
err = errors.New("missing required vm_id parameter")
return nil, err
}
path := fmt.Sprintf("api/v1/vm/branch/by_vm/%s", vmID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
func (r *VmService) Commit(ctx context.Context, vmID string, body VmCommitParams, opts ...option.RequestOption) (res *VmCommitResponse, err error) {
opts = slices.Concat(r.Options, opts)
if vmID == "" {
err = errors.New("missing required vm_id parameter")
return nil, err
}
path := fmt.Sprintf("api/v1/vm/%s/commit", vmID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
func (r *VmService) NewRoot(ctx context.Context, params VmNewRootParams, opts ...option.RequestOption) (res *NewVmResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "api/v1/vm/new_root"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
return res, err
}
func (r *VmService) GetMetadata(ctx context.Context, vmID string, opts ...option.RequestOption) (res *VmMetadataResponse, err error) {
opts = slices.Concat(r.Options, opts)
if vmID == "" {
err = errors.New("missing required vm_id parameter")
return nil, err
}
path := fmt.Sprintf("api/v1/vm/%s/metadata", vmID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
func (r *VmService) GetSSHKey(ctx context.Context, vmID string, opts ...option.RequestOption) (res *VmSSHKeyResponse, err error) {
opts = slices.Concat(r.Options, opts)
if vmID == "" {
err = errors.New("missing required vm_id parameter")
return nil, err
}
path := fmt.Sprintf("api/v1/vm/%s/ssh_key", vmID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
func (r *VmService) ResizeDisk(ctx context.Context, vmID string, params VmResizeDiskParams, opts ...option.RequestOption) (err error) {
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithHeader("Accept", "*/*")}, opts...)
if vmID == "" {
err = errors.New("missing required vm_id parameter")
return err
}
path := fmt.Sprintf("api/v1/vm/%s/disk", vmID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, params, nil, opts...)
return err
}
func (r *VmService) RestoreFromCommit(ctx context.Context, body VmRestoreFromCommitParams, opts ...option.RequestOption) (res *NewVmResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "api/v1/vm/from_commit"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
func (r *VmService) Status(ctx context.Context, vmID string, opts ...option.RequestOption) (res *Vm, err error) {
opts = slices.Concat(r.Options, opts)
if vmID == "" {
err = errors.New("missing required vm_id parameter")
return nil, err
}
path := fmt.Sprintf("api/v1/vm/%s/status", vmID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
func (r *VmService) UpdateState(ctx context.Context, vmID string, params VmUpdateStateParams, opts ...option.RequestOption) (err error) {
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithHeader("Accept", "*/*")}, opts...)
if vmID == "" {
err = errors.New("missing required vm_id parameter")
return err
}
path := fmt.Sprintf("api/v1/vm/%s/state", vmID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, params, nil, opts...)
return err
}
type NewRootRequestParam struct {
// Struct representing configuration options common to all VMs
VmConfig param.Field[NewRootRequestVmConfigParam] `json:"vm_config" api:"required"`
}
func (r NewRootRequestParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Struct representing configuration options common to all VMs
type NewRootRequestVmConfigParam struct {
// The disk size, in MiB.
FsSizeMib param.Field[int64] `json:"fs_size_mib"`
// The filesystem base image name. Currently, must be 'default'
ImageName param.Field[string] `json:"image_name"`
// The kernel name. Currently, must be 'default.bin'
KernelName param.Field[string] `json:"kernel_name"`
// The RAM size, in MiB.
MemSizeMib param.Field[int64] `json:"mem_size_mib"`
// How many vCPUs to allocate to this VM (and its children)
VcpuCount param.Field[int64] `json:"vcpu_count"`
}
func (r NewRootRequestVmConfigParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Response body for new VM requests (new_root, from_commit, branch)
type NewVmResponse struct {
VmID string `json:"vm_id" api:"required"`
JSON newVmResponseJSON `json:"-"`
}
// newVmResponseJSON contains the JSON metadata for the struct [NewVmResponse]
type newVmResponseJSON struct {
VmID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *NewVmResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r newVmResponseJSON) RawJSON() string {
return r.raw
}
type NewVmsResponse struct {
Vms []NewVmResponse `json:"vms" api:"required"`
JSON newVmsResponseJSON `json:"-"`
}
// newVmsResponseJSON contains the JSON metadata for the struct [NewVmsResponse]
type newVmsResponseJSON struct {
Vms apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *NewVmsResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r newVmsResponseJSON) RawJSON() string {
return r.raw
}
type Vm struct {
CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
OwnerID string `json:"owner_id" api:"required" format:"uuid"`
// The state of a VM
State VmState `json:"state" api:"required"`
VmID string `json:"vm_id" api:"required" format:"uuid"`
JSON vmJSON `json:"-"`
}
// vmJSON contains the JSON metadata for the struct [Vm]
type vmJSON struct {
CreatedAt apijson.Field
OwnerID apijson.Field
State apijson.Field
VmID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Vm) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r vmJSON) RawJSON() string {
return r.raw
}
// The state of a VM
type VmState string
const (
VmStateBooting VmState = "booting"
VmStateRunning VmState = "running"
VmStatePaused VmState = "paused"
VmStateSleeping VmState = "sleeping"
VmStateDead VmState = "dead"
)
func (r VmState) IsKnown() bool {
switch r {
case VmStateBooting, VmStateRunning, VmStatePaused, VmStateSleeping, VmStateDead:
return true
}
return false
}
// The response body for POST /api/vm/{vm_id}/commit
type VmCommitResponse struct {
// The UUID of the newly-created commit
CommitID string `json:"commit_id" api:"required" format:"uuid"`
JSON vmCommitResponseJSON `json:"-"`
}
// vmCommitResponseJSON contains the JSON metadata for the struct
// [VmCommitResponse]
type vmCommitResponseJSON struct {
CommitID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *VmCommitResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r vmCommitResponseJSON) RawJSON() string {
return r.raw
}
// Response body for DELETE /api/vm/{vm_id}
type VmDeleteResponse struct {
VmID string `json:"vm_id" api:"required"`
JSON vmDeleteResponseJSON `json:"-"`
}
// vmDeleteResponseJSON contains the JSON metadata for the struct
// [VmDeleteResponse]
type vmDeleteResponseJSON struct {
VmID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *VmDeleteResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r vmDeleteResponseJSON) RawJSON() string {
return r.raw
}
// Request body for POST /api/v1/vm/from_commit
type VmFromCommitRequestParam struct {
// The commit ID to restore from
CommitID param.Field[string] `json:"commit_id" format:"uuid"`
// A repository reference in "repo_name:tag_name" format
Ref param.Field[string] `json:"ref"`
// The tag name to restore from (legacy org-scoped tag)
TagName param.Field[string] `json:"tag_name"`
}
func (r VmFromCommitRequestParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r VmFromCommitRequestParam) implementsVmFromCommitRequestUnionParam() {}
// Request body for POST /api/v1/vm/from_commit
//
// Satisfied by [VmFromCommitRequestCommitIDParam],
// [VmFromCommitRequestTagNameParam], [VmFromCommitRequestRefParam],
// [VmFromCommitRequestParam].
type VmFromCommitRequestUnionParam interface {
implementsVmFromCommitRequestUnionParam()
}
// The commit ID to restore from
type VmFromCommitRequestCommitIDParam struct {
// The commit ID to restore from
CommitID param.Field[string] `json:"commit_id" api:"required" format:"uuid"`
}
func (r VmFromCommitRequestCommitIDParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r VmFromCommitRequestCommitIDParam) implementsVmFromCommitRequestUnionParam() {}
// The tag name to restore from (legacy org-scoped tag)
type VmFromCommitRequestTagNameParam struct {
// The tag name to restore from (legacy org-scoped tag)
TagName param.Field[string] `json:"tag_name" api:"required"`
}
func (r VmFromCommitRequestTagNameParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r VmFromCommitRequestTagNameParam) implementsVmFromCommitRequestUnionParam() {}
// A repository reference in "repo_name:tag_name" format
type VmFromCommitRequestRefParam struct {
// A repository reference in "repo_name:tag_name" format
Ref param.Field[string] `json:"ref" api:"required"`
}
func (r VmFromCommitRequestRefParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r VmFromCommitRequestRefParam) implementsVmFromCommitRequestUnionParam() {}
// Response for GET /api/v1/vm/{vm_id}/metadata
type VmMetadataResponse struct {
CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
IP string `json:"ip" api:"required"`
OwnerID string `json:"owner_id" api:"required" format:"uuid"`
// The state of a VM
State VmMetadataResponseState `json:"state" api:"required"`
VmID string `json:"vm_id" api:"required" format:"uuid"`
DeletedAt time.Time `json:"deleted_at" api:"nullable" format:"date-time"`
GrandparentVmID string `json:"grandparent_vm_id" api:"nullable" format:"uuid"`
ParentCommitID string `json:"parent_commit_id" api:"nullable" format:"uuid"`
JSON vmMetadataResponseJSON `json:"-"`
}
// vmMetadataResponseJSON contains the JSON metadata for the struct
// [VmMetadataResponse]
type vmMetadataResponseJSON struct {
CreatedAt apijson.Field
IP apijson.Field
OwnerID apijson.Field
State apijson.Field
VmID apijson.Field
DeletedAt apijson.Field
GrandparentVmID apijson.Field
ParentCommitID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *VmMetadataResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r vmMetadataResponseJSON) RawJSON() string {
return r.raw
}
// The state of a VM
type VmMetadataResponseState string
const (
VmMetadataResponseStateBooting VmMetadataResponseState = "booting"
VmMetadataResponseStateRunning VmMetadataResponseState = "running"
VmMetadataResponseStatePaused VmMetadataResponseState = "paused"
VmMetadataResponseStateSleeping VmMetadataResponseState = "sleeping"
VmMetadataResponseStateDead VmMetadataResponseState = "dead"
)
func (r VmMetadataResponseState) IsKnown() bool {
switch r {
case VmMetadataResponseStateBooting, VmMetadataResponseStateRunning, VmMetadataResponseStatePaused, VmMetadataResponseStateSleeping, VmMetadataResponseStateDead:
return true
}
return false
}
// Request body for PATCH /api/vm/{vm_id}/disk
type VmResizeDiskRequestParam struct {
// The new disk size in MiB. Must be strictly greater than the current size.
FsSizeMib param.Field[int64] `json:"fs_size_mib" api:"required"`
}
func (r VmResizeDiskRequestParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Response body for GET /api/vm/{vm_id}/ssh_key
type VmSSHKeyResponse struct {
// The SSH port that will be DNAT'd to the VM's netns (and, in turn, to its TAP
// device)
SSHPort int64 `json:"ssh_port" api:"required"`
// Private SSH key in stringified OpenSSH format
SSHPrivateKey string `json:"ssh_private_key" api:"required"`
JSON vmSSHKeyResponseJSON `json:"-"`
}
// vmSSHKeyResponseJSON contains the JSON metadata for the struct
// [VmSSHKeyResponse]
type vmSSHKeyResponseJSON struct {
SSHPort apijson.Field
SSHPrivateKey apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *VmSSHKeyResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r vmSSHKeyResponseJSON) RawJSON() string {
return r.raw
}
// Request body for PATCH /api/vm/{vm_id}/state
type VmUpdateStateRequestParam struct {
// The requested state for the VM
State param.Field[VmUpdateStateRequestState] `json:"state" api:"required"`
}
func (r VmUpdateStateRequestParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// The requested state for the VM
type VmUpdateStateRequestState string
const (
VmUpdateStateRequestStatePaused VmUpdateStateRequestState = "Paused"
VmUpdateStateRequestStateRunning VmUpdateStateRequestState = "Running"
)
func (r VmUpdateStateRequestState) IsKnown() bool {
switch r {
case VmUpdateStateRequestStatePaused, VmUpdateStateRequestStateRunning:
return true
}
return false
}
type VmDeleteParams struct {
// If true, return an error immediately if the VM is still booting. Default: false
SkipWaitBoot param.Field[bool] `query:"skip_wait_boot"`
}
// URLQuery serializes [VmDeleteParams]'s query parameters as `url.Values`.
func (r VmDeleteParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type VmBranchParams struct {
// Number of VMs to branch (optional; default 1)
Count param.Field[int64] `query:"count"`
// If true, keep VM paused after commit. Only applicable when branching a VM ID.
KeepPaused param.Field[bool] `query:"keep_paused"`
// If true, immediately return an error if VM is booting instead of waiting. Only
// applicable when branching a VM ID.
SkipWaitBoot param.Field[bool] `query:"skip_wait_boot"`
}
// URLQuery serializes [VmBranchParams]'s query parameters as `url.Values`.
func (r VmBranchParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type VmBranchByCommitParams struct {
// Number of VMs to branch (optional; default 1)
Count param.Field[int64] `query:"count"`
}
// URLQuery serializes [VmBranchByCommitParams]'s query parameters as `url.Values`.
func (r VmBranchByCommitParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type VmBranchByTagParams struct {
// Number of VMs to branch (optional; default 1)
Count param.Field[int64] `query:"count"`
}
// URLQuery serializes [VmBranchByTagParams]'s query parameters as `url.Values`.
func (r VmBranchByTagParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type VmBranchByVmParams struct {
// Number of VMs to branch (optional; default 1)
Count param.Field[int64] `query:"count"`
// If true, keep VM paused after commit
KeepPaused param.Field[bool] `query:"keep_paused"`
// If true, immediately return an error if VM is booting instead of waiting
SkipWaitBoot param.Field[bool] `query:"skip_wait_boot"`
}
// URLQuery serializes [VmBranchByVmParams]'s query parameters as `url.Values`.
func (r VmBranchByVmParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type VmCommitParams struct {
// If true, keep VM paused after commit
KeepPaused param.Field[bool] `query:"keep_paused"`
// If true, return an error immediately if the VM is still booting. Default: false
SkipWaitBoot param.Field[bool] `query:"skip_wait_boot"`
}
// URLQuery serializes [VmCommitParams]'s query parameters as `url.Values`.
func (r VmCommitParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type VmNewRootParams struct {
NewRootRequest NewRootRequestParam `json:"new_root_request" api:"required"`
// If true, wait for the newly-created VM to finish booting before returning.
// Default: false.
WaitBoot param.Field[bool] `query:"wait_boot"`
}
func (r VmNewRootParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r.NewRootRequest)
}
// URLQuery serializes [VmNewRootParams]'s query parameters as `url.Values`.
func (r VmNewRootParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type VmResizeDiskParams struct {
// Request body for PATCH /api/vm/{vm_id}/disk
VmResizeDiskRequest VmResizeDiskRequestParam `json:"vm_resize_disk_request" api:"required"`
// If true, return an error immediately if the VM is still booting. Default: false
SkipWaitBoot param.Field[bool] `query:"skip_wait_boot"`
}
func (r VmResizeDiskParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r.VmResizeDiskRequest)
}
// URLQuery serializes [VmResizeDiskParams]'s query parameters as `url.Values`.
func (r VmResizeDiskParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type VmRestoreFromCommitParams struct {
// Request body for POST /api/v1/vm/from_commit
VmFromCommitRequest VmFromCommitRequestUnionParam `json:"vm_from_commit_request" api:"required"`
}
func (r VmRestoreFromCommitParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r.VmFromCommitRequest)
}
type VmUpdateStateParams struct {
// Request body for PATCH /api/vm/{vm_id}/state
VmUpdateStateRequest VmUpdateStateRequestParam `json:"vm_update_state_request" api:"required"`
// If true, error immediately if the VM is not finished booting. Defaults to false
SkipWaitBoot param.Field[bool] `query:"skip_wait_boot"`
}
func (r VmUpdateStateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r.VmUpdateStateRequest)
}
// URLQuery serializes [VmUpdateStateParams]'s query parameters as `url.Values`.
func (r VmUpdateStateParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}