Skip to content

Commit f850732

Browse files
feat: Volumes
1 parent b942d3c commit f850732

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 18
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fhypeman-edab7ce8bc63b4aa65874ad88beb74d854e1fb377578029358b83ba73882f368.yml
3-
openapi_spec_hash: af92664caaf3a52526962d2d99d2091a
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fhypeman-4f49f45b02b41543e2bc99d17dfe49ef8768e843f5bf6082f4d6771b0e0ad5ca.yml
3+
openapi_spec_hash: af94bed7bec48ed50d0dbb7dddb844e0
44
config_hash: 2ce06f034ee83acd32ef586f484fc4f0

api.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ Methods:
2323

2424
# Instances
2525

26+
Params Types:
27+
28+
- <a href="https://pkg.go.dev/github.com/onkernel/hypeman-go">hypeman</a>.<a href="https://pkg.go.dev/github.com/onkernel/hypeman-go#VolumeAttachmentParam">VolumeAttachmentParam</a>
29+
2630
Response Types:
2731

2832
- <a href="https://pkg.go.dev/github.com/onkernel/hypeman-go">hypeman</a>.<a href="https://pkg.go.dev/github.com/onkernel/hypeman-go#Instance">Instance</a>
33+
- <a href="https://pkg.go.dev/github.com/onkernel/hypeman-go">hypeman</a>.<a href="https://pkg.go.dev/github.com/onkernel/hypeman-go#VolumeAttachment">VolumeAttachment</a>
2934

3035
Methods:
3136

instance.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package hypeman
44

55
import (
66
"context"
7+
"encoding/json"
78
"errors"
89
"fmt"
910
"net/http"
@@ -163,6 +164,8 @@ type Instance struct {
163164
StoppedAt time.Time `json:"stopped_at,nullable" format:"date-time"`
164165
// Number of virtual CPUs
165166
Vcpus int64 `json:"vcpus"`
167+
// Volumes attached to the instance
168+
Volumes []VolumeAttachment `json:"volumes"`
166169
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
167170
JSON struct {
168171
ID respjson.Field
@@ -179,6 +182,7 @@ type Instance struct {
179182
StartedAt respjson.Field
180183
StoppedAt respjson.Field
181184
Vcpus respjson.Field
185+
Volumes respjson.Field
182186
ExtraFields map[string]respjson.Field
183187
raw string
184188
} `json:"-"`
@@ -236,6 +240,57 @@ func (r *InstanceNetwork) UnmarshalJSON(data []byte) error {
236240
return apijson.UnmarshalRoot(data, r)
237241
}
238242

243+
type VolumeAttachment struct {
244+
// Path where volume is mounted in the guest
245+
MountPath string `json:"mount_path,required"`
246+
// Volume identifier
247+
VolumeID string `json:"volume_id,required"`
248+
// Whether volume is mounted read-only
249+
Readonly bool `json:"readonly"`
250+
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
251+
JSON struct {
252+
MountPath respjson.Field
253+
VolumeID respjson.Field
254+
Readonly respjson.Field
255+
ExtraFields map[string]respjson.Field
256+
raw string
257+
} `json:"-"`
258+
}
259+
260+
// Returns the unmodified JSON received from the API
261+
func (r VolumeAttachment) RawJSON() string { return r.JSON.raw }
262+
func (r *VolumeAttachment) UnmarshalJSON(data []byte) error {
263+
return apijson.UnmarshalRoot(data, r)
264+
}
265+
266+
// ToParam converts this VolumeAttachment to a VolumeAttachmentParam.
267+
//
268+
// Warning: the fields of the param type will not be present. ToParam should only
269+
// be used at the last possible moment before sending a request. Test for this with
270+
// VolumeAttachmentParam.Overrides()
271+
func (r VolumeAttachment) ToParam() VolumeAttachmentParam {
272+
return param.Override[VolumeAttachmentParam](json.RawMessage(r.RawJSON()))
273+
}
274+
275+
// The properties MountPath, VolumeID are required.
276+
type VolumeAttachmentParam struct {
277+
// Path where volume is mounted in the guest
278+
MountPath string `json:"mount_path,required"`
279+
// Volume identifier
280+
VolumeID string `json:"volume_id,required"`
281+
// Whether volume is mounted read-only
282+
Readonly param.Opt[bool] `json:"readonly,omitzero"`
283+
paramObj
284+
}
285+
286+
func (r VolumeAttachmentParam) MarshalJSON() (data []byte, err error) {
287+
type shadow VolumeAttachmentParam
288+
return param.MarshalObject(r, (*shadow)(&r))
289+
}
290+
func (r *VolumeAttachmentParam) UnmarshalJSON(data []byte) error {
291+
return apijson.UnmarshalRoot(data, r)
292+
}
293+
239294
type InstanceNewParams struct {
240295
// OCI image reference
241296
Image string `json:"image,required"`
@@ -254,6 +309,8 @@ type InstanceNewParams struct {
254309
Env map[string]string `json:"env,omitzero"`
255310
// Network configuration for the instance
256311
Network InstanceNewParamsNetwork `json:"network,omitzero"`
312+
// Volumes to attach to the instance at creation time
313+
Volumes []VolumeAttachmentParam `json:"volumes,omitzero"`
257314
paramObj
258315
}
259316

instance_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ func TestInstanceNewWithOptionalParams(t *testing.T) {
4040
OverlaySize: hypeman.String("20GB"),
4141
Size: hypeman.String("2GB"),
4242
Vcpus: hypeman.Int(2),
43+
Volumes: []hypeman.VolumeAttachmentParam{{
44+
MountPath: "/mnt/data",
45+
VolumeID: "vol-abc123",
46+
Readonly: hypeman.Bool(true),
47+
}},
4348
})
4449
if err != nil {
4550
var apierr *hypeman.Error

0 commit comments

Comments
 (0)