-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvm.go
More file actions
181 lines (160 loc) · 6.69 KB
/
vm.go
File metadata and controls
181 lines (160 loc) · 6.69 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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package sfcnodes
import (
"context"
"net/http"
"net/url"
"slices"
"github.com/sfcompute/nodes-go/internal/apijson"
"github.com/sfcompute/nodes-go/internal/apiquery"
"github.com/sfcompute/nodes-go/internal/requestconfig"
"github.com/sfcompute/nodes-go/option"
"github.com/sfcompute/nodes-go/packages/param"
"github.com/sfcompute/nodes-go/packages/respjson"
)
// VMService contains methods and other services that help with interacting with
// the sfc-nodes 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
Script VMScriptService
Images VMImageService
}
// 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
r.Script = NewVMScriptService(opts...)
r.Images = NewVMImageService(opts...)
return
}
func (r *VMService) Logs(ctx context.Context, query VMLogsParams, opts ...option.RequestOption) (res *VMLogsResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "v0/vms/logs2"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return
}
func (r *VMService) SSH(ctx context.Context, query VMSSHParams, opts ...option.RequestOption) (res *VmsshResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "v0/vms/ssh"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return
}
type VMLogsResponse struct {
Data []VMLogsResponseData `json:"data" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Data respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r VMLogsResponse) RawJSON() string { return r.JSON.raw }
func (r *VMLogsResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type VMLogsResponseData struct {
Data []int64 `json:"data" api:"required"`
InstanceID string `json:"instance_id" api:"required"`
MonotonicTimestampNanoSec int64 `json:"monotonic_timestamp_nano_sec" api:"required"`
MonotonicTimestampSec int64 `json:"monotonic_timestamp_sec" api:"required"`
// In RFC 3339 format
RealtimeTimestamp string `json:"realtime_timestamp" api:"required"`
Seqnum int64 `json:"seqnum" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Data respjson.Field
InstanceID respjson.Field
MonotonicTimestampNanoSec respjson.Field
MonotonicTimestampSec respjson.Field
RealtimeTimestamp respjson.Field
Seqnum respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r VMLogsResponseData) RawJSON() string { return r.JSON.raw }
func (r *VMLogsResponseData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type VmsshResponse struct {
SSHHostname string `json:"ssh_hostname" api:"required"`
SSHPort int64 `json:"ssh_port" api:"required"`
// Unix timestamp.
LastAttemptedKeyUpdate int64 `json:"last_attempted_key_update" api:"nullable"`
// Unix timestamp.
LastSuccessfulKeyUpdate int64 `json:"last_successful_key_update" api:"nullable"`
SSHHostKeys []VmsshResponseSSHHostKey `json:"ssh_host_keys" api:"nullable"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
SSHHostname respjson.Field
SSHPort respjson.Field
LastAttemptedKeyUpdate respjson.Field
LastSuccessfulKeyUpdate respjson.Field
SSHHostKeys respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r VmsshResponse) RawJSON() string { return r.JSON.raw }
func (r *VmsshResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type VmsshResponseSSHHostKey struct {
Base64EncodedKey string `json:"base64_encoded_key" api:"required" format:"byte"`
KeyType string `json:"key_type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Base64EncodedKey respjson.Field
KeyType respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r VmsshResponseSSHHostKey) RawJSON() string { return r.JSON.raw }
func (r *VmsshResponseSSHHostKey) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type VMLogsParams struct {
InstanceID string `query:"instance_id" api:"required" json:"-"`
// Any of "seqnum_asc", "seqnum_desc".
OrderBy VMLogsParamsOrderBy `query:"order_by,omitzero" api:"required" json:"-"`
BeforeRealtimeTimestamp param.Opt[string] `query:"before_realtime_timestamp,omitzero" json:"-"`
BeforeSeqnum param.Opt[int64] `query:"before_seqnum,omitzero" json:"-"`
Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
SinceRealtimeTimestamp param.Opt[string] `query:"since_realtime_timestamp,omitzero" json:"-"`
SinceSeqnum param.Opt[int64] `query:"since_seqnum,omitzero" json:"-"`
paramObj
}
// URLQuery serializes [VMLogsParams]'s query parameters as `url.Values`.
func (r VMLogsParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type VMLogsParamsOrderBy string
const (
VMLogsParamsOrderBySeqnumAsc VMLogsParamsOrderBy = "seqnum_asc"
VMLogsParamsOrderBySeqnumDesc VMLogsParamsOrderBy = "seqnum_desc"
)
type VMSSHParams struct {
VMID string `query:"vm_id" api:"required" json:"-"`
paramObj
}
// URLQuery serializes [VMSSHParams]'s query parameters as `url.Values`.
func (r VMSSHParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}