@@ -4,6 +4,7 @@ package hypeman
44
55import (
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+
239294type 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
0 commit comments