-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstancevolume.go
More file actions
89 lines (79 loc) · 2.93 KB
/
instancevolume.go
File metadata and controls
89 lines (79 loc) · 2.93 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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package hypeman
import (
"context"
"errors"
"fmt"
"net/http"
"slices"
"github.com/kernel/hypeman-go/internal/apijson"
"github.com/kernel/hypeman-go/internal/requestconfig"
"github.com/kernel/hypeman-go/option"
"github.com/kernel/hypeman-go/packages/param"
)
// InstanceVolumeService contains methods and other services that help with
// interacting with the hypeman 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 [NewInstanceVolumeService] method instead.
type InstanceVolumeService struct {
Options []option.RequestOption
}
// NewInstanceVolumeService 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 NewInstanceVolumeService(opts ...option.RequestOption) (r InstanceVolumeService) {
r = InstanceVolumeService{}
r.Options = opts
return
}
// Attach volume to instance
func (r *InstanceVolumeService) Attach(ctx context.Context, volumeID string, params InstanceVolumeAttachParams, opts ...option.RequestOption) (res *Instance, err error) {
opts = slices.Concat(r.Options, opts)
if params.ID == "" {
err = errors.New("missing required id parameter")
return nil, err
}
if volumeID == "" {
err = errors.New("missing required volumeId parameter")
return nil, err
}
path := fmt.Sprintf("instances/%s/volumes/%s", params.ID, volumeID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
return res, err
}
// Detach volume from instance
func (r *InstanceVolumeService) Detach(ctx context.Context, volumeID string, body InstanceVolumeDetachParams, opts ...option.RequestOption) (res *Instance, err error) {
opts = slices.Concat(r.Options, opts)
if body.ID == "" {
err = errors.New("missing required id parameter")
return nil, err
}
if volumeID == "" {
err = errors.New("missing required volumeId parameter")
return nil, err
}
path := fmt.Sprintf("instances/%s/volumes/%s", body.ID, volumeID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return res, err
}
type InstanceVolumeAttachParams struct {
ID string `path:"id" api:"required" json:"-"`
// Path where volume should be mounted
MountPath string `json:"mount_path" api:"required"`
// Mount as read-only
Readonly param.Opt[bool] `json:"readonly,omitzero"`
paramObj
}
func (r InstanceVolumeAttachParams) MarshalJSON() (data []byte, err error) {
type shadow InstanceVolumeAttachParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *InstanceVolumeAttachParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type InstanceVolumeDetachParams struct {
ID string `path:"id" api:"required" json:"-"`
paramObj
}