-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypes.go
More file actions
254 lines (221 loc) · 9.23 KB
/
types.go
File metadata and controls
254 lines (221 loc) · 9.23 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
package slicer
import (
"math"
"net"
"strings"
"time"
)
const NonRootUser = uint32(math.MaxUint32)
// SlicerNode represents a node managed by the slicer REST API.
type SlicerNode struct {
Hostname string `json:"hostname"`
HostGroup string `json:"hostgroup,omitempty"`
IP string `json:"ip"`
RamBytes int64 `json:"ram_bytes,omitempty"` // RAM size in bytes
CPUs int `json:"cpus,omitempty"`
CreatedAt time.Time `json:"created_at"`
Arch string `json:"arch,omitempty"`
Tags []string `json:"tags,omitempty"`
Status string `json:"status,omitempty"` // "Running", "Paused", or "Stopped"
Persistent bool `json:"persistent,omitempty"`
}
// SlicerCreateNodeRequest contains parameters for creating a node
type SlicerCreateNodeRequest struct {
RamBytes int64 `json:"ram_bytes,omitempty"` // RAM size in bytes (must not exceed host group limit)
CPUs int `json:"cpus,omitempty"` // Number of CPUs (must not exceed host group limit)
GPUCount int `json:"gpu_count,omitempty"`
Persistent bool `json:"persistent,omitempty"`
DiskImage string `json:"disk_image,omitempty"`
ImportUser string `json:"import_user,omitempty"`
SSHKeys []string `json:"ssh_keys,omitempty"`
Userdata string `json:"userdata,omitempty"`
IP string `json:"ip,omitempty"`
Tags []string `json:"tags,omitempty"`
Secrets []string `json:"secrets,omitempty"`
}
// SlicerCreateNodeWaitFor controls how far the server should wait before returning.
type SlicerCreateNodeWaitFor string
const (
// SlicerCreateNodeWaitAgent returns once the guest agent is reachable.
SlicerCreateNodeWaitAgent SlicerCreateNodeWaitFor = "agent"
// SlicerCreateNodeWaitUserdata returns once agent readiness and userdata completion are observed.
SlicerCreateNodeWaitUserdata SlicerCreateNodeWaitFor = "userdata"
)
// SlicerCreateNodeOptions allows typed create query params.
type SlicerCreateNodeOptions struct {
// Wait controls server-side readiness waiting (agent/userdata). Empty means no wait.
Wait SlicerCreateNodeWaitFor `json:"-"`
// Timeout is optional wait timeout when Wait is set. Parsed as Go duration.
Timeout time.Duration `json:"-"`
}
// MB converts megabytes to bytes
func MiB(mb int64) int64 {
return mb * 1024 * 1024
}
// GB converts gigabytes to bytes
func GiB(gb int64) int64 {
return gb * 1024 * 1024 * 1024
}
// SlicerCreateNodeResponse is the response from the REST API when creating a node.
type SlicerCreateNodeResponse struct {
///{"hostname":"api-1","ip":"192.168.137.2/24","created_at":"2025-11-14T13:28:34.218182826Z"}
Hostname string `json:"hostname"`
HostGroup string `json:"hostgroup,omitempty"`
IP string `json:"ip"`
CreatedAt time.Time `json:"created_at"`
Arch string `json:"arch,omitempty"`
}
func (n *SlicerCreateNodeResponse) IPAddress() net.IP {
if strings.Contains(n.IP, "/") {
ip, _, _ := net.ParseCIDR(n.IP)
return ip
}
return net.ParseIP(n.IP)
}
// SlicerHostGroup represents a host group from the /hostgroup endpoint.
type SlicerHostGroup struct {
Name string `json:"name,omitempty"`
Count int `json:"count,omitempty"`
RamBytes int64 `json:"ram_bytes,omitempty"` // RAM size in bytes
CPUs int `json:"cpus,omitempty"`
Arch string `json:"arch,omitempty"`
GPUCount int `json:"gpu_count,omitempty"`
}
// ExecWriteResult represents output from commands executing within a microVM.
type SlicerExecWriteResult struct {
Timestamp time.Time `json:"timestamp,omitempty,omitzero"`
Type string `json:"type,omitempty"`
Pid int `json:"pid,omitempty"`
Encoding string `json:"encoding,omitempty"`
Data string `json:"data,omitempty"`
StartedAt time.Time `json:"started_at,omitempty,omitzero"`
EndedAt time.Time `json:"ended_at,omitempty,omitzero"`
Signal string `json:"signal,omitempty"`
Stdout string `json:"stdout,omitempty"`
Stderr string `json:"stderr,omitempty"`
ExitCode int `json:"exit_code"`
Error string `json:"error,omitempty"`
}
type ExecResult struct {
Stdout string `json:"stdout,omitempty"`
Stderr string `json:"stderr,omitempty"`
Encoding string `json:"encoding,omitempty"`
Pid int `json:"pid,omitempty"`
StartedAt time.Time `json:"started_at,omitempty,omitzero"`
EndedAt time.Time `json:"ended_at,omitempty,omitzero"`
Signal string `json:"signal,omitempty"`
ExitCode int `json:"exit_code"`
Error string `json:"error,omitempty"`
}
// SlicerExecRequest contains parameters for invoking a command
// within a VM.
type SlicerExecRequest struct {
Command string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
Env []string `json:"env,omitempty"`
UID uint32 `json:"uid,omitempty"`
GID uint32 `json:"gid,omitempty"`
Stdin bool `json:"stdin,omitempty"`
Stdout bool `json:"stdout,omitempty"`
Stderr bool `json:"stderr,omitempty"`
Stdio string `json:"stdio,omitempty"`
Shell string `json:"shell,omitempty"`
Cwd string `json:"cwd,omitempty"`
Permissions string `json:"permissions,omitempty"`
}
// SlicerCpRequest contains parameters for copying files to/from a VM
type SlicerCpRequest struct {
VM string // VM name
Path string // Path on the VM
}
// SlicerFSInfo represents file system entry metadata returned by VM fs endpoints.
type SlicerFSInfo struct {
Name string `json:"name"`
Type string `json:"type"`
Size int64 `json:"size"`
Mtime time.Time `json:"mtime"`
Mode string `json:"mode"`
}
// SlicerFSMkdirRequest contains parameters for mkdir on a VM.
type SlicerFSMkdirRequest struct {
Path string `json:"path"`
Recursive bool `json:"recursive,omitempty"`
Mode string `json:"mode,omitempty"`
}
// SlicerNodeStat represents stats for a VM node
type SlicerNodeStat struct {
Hostname string `json:"hostname"`
IP string `json:"ip"`
CreatedAt time.Time `json:"created_at"`
Snapshot *SlicerSnapshot `json:"snapshot"`
Error string `json:"error"`
}
// SlicerSnapshot represents a snapshot of VM metrics
type SlicerSnapshot struct {
Hostname string `json:"hostname"`
Arch string `json:"arch"`
Timestamp time.Time `json:"timestamp"`
Uptime string `json:"uptime"`
TotalCPUS int `json:"totalCpus"`
TotalMemory uint64 `json:"totalMemory"`
MemoryUsed uint64 `json:"memoryUsed"`
MemoryAvailable uint64 `json:"memoryAvailable"`
MemoryUsedPercent float64 `json:"memoryUsedPercent"`
LoadAvg1 float64 `json:"loadAvg1"`
LoadAvg5 float64 `json:"loadAvg5"`
LoadAvg15 float64 `json:"loadAvg15"`
DiskReadTotal float64 `json:"diskReadTotal"`
DiskWriteTotal float64 `json:"diskWriteTotal"`
NetworkReadTotal float64 `json:"networkReadTotal"`
NetworkWriteTotal float64 `json:"networkWriteTotal"`
DiskIOInflight int64 `json:"diskIOInflight"`
OpenConnections int64 `json:"openConnections"`
OpenFiles int64 `json:"openFiles"`
Entropy int64 `json:"entropy"`
DiskSpaceTotal uint64 `json:"diskSpaceTotal"`
DiskSpaceUsed uint64 `json:"diskSpaceUsed"`
DiskSpaceFree uint64 `json:"diskSpaceFree"`
DiskSpaceUsedPercent float64 `json:"diskSpaceUsedPercent"`
}
// SlicerLogsResponse represents the response from the logs endpoint
type SlicerLogsResponse struct {
Hostname string `json:"hostname"`
Lines int `json:"lines"`
Content string `json:"content"`
}
// SlicerDeleteResponse represents the response from the delete endpoint
type SlicerDeleteResponse struct {
Message string `json:"message"`
DiskRemoved string `json:"disk_removed"`
Error string `json:"error"`
}
type SlicerAgentHealthResponse struct {
// Hostname is the hostname of the agent
Hostname string `json:"hostname,omitempty"`
// Uptime is the uptime of the agent
AgentUptime time.Duration `json:"agent_uptime,omitempty"`
// AgentVersion is the version of the agent
AgentVersion string `json:"agent_version,omitempty"`
// SystemUptime is the uptime of the system
SystemUptime time.Duration `json:"system_uptime,omitempty"`
// UserdataRan indicates whether the user data script has completed executing
UserdataRan bool `json:"userdata_ran,omitempty"`
}
// SlicerShutdownRequest contains parameters for shutting down or rebooting a VM.
// Action can be "shutdown" (default) to halt the VM or "reboot" to restart it.
type SlicerShutdownRequest struct {
// Action specifies the shutdown action: "shutdown" (halt) or "reboot" (restart).
// If empty, defaults to "shutdown".
Action string `json:"action,omitempty"`
}
// SlicerInfo represents version and server information from the /info endpoint
type SlicerInfo struct {
// Version is the version of the slicer server
Version string `json:"version,omitempty"`
// GitCommit is the git commit hash of the slicer server
GitCommit string `json:"git_commit,omitempty"`
// Platform indicates the server operating system (runtime.GOOS).
Platform string `json:"platform,omitempty"`
// Arch is the server architecture (runtime.GOARCH).
Arch string `json:"arch,omitempty"`
}