-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmachine.connect.go
More file actions
286 lines (263 loc) · 14 KB
/
machine.connect.go
File metadata and controls
286 lines (263 loc) · 14 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
// Code generated by protoc-gen-connect-go. DO NOT EDIT.
//
// Source: metalstack/admin/v2/machine.proto
package adminv2connect
import (
connect "connectrpc.com/connect"
context "context"
errors "errors"
v2 "github.com/metal-stack/api/go/metalstack/admin/v2"
http "net/http"
strings "strings"
)
// This is a compile-time assertion to ensure that this generated file and the connect package are
// compatible. If you get a compiler error that this constant is not defined, this code was
// generated with a version of connect newer than the one compiled into your binary. You can fix the
// problem by either regenerating this code with an older version of connect or updating the connect
// version compiled into your binary.
const _ = connect.IsAtLeastVersion1_13_0
const (
// MachineServiceName is the fully-qualified name of the MachineService service.
MachineServiceName = "metalstack.admin.v2.MachineService"
)
// These constants are the fully-qualified names of the RPCs defined in this package. They're
// exposed at runtime as Spec.Procedure and as the final two segments of the HTTP route.
//
// Note that these are different from the fully-qualified method names used by
// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to
// reflection-formatted method names, remove the leading slash and convert the remaining slash to a
// period.
const (
// MachineServiceGetProcedure is the fully-qualified name of the MachineService's Get RPC.
MachineServiceGetProcedure = "/metalstack.admin.v2.MachineService/Get"
// MachineServiceListProcedure is the fully-qualified name of the MachineService's List RPC.
MachineServiceListProcedure = "/metalstack.admin.v2.MachineService/List"
// MachineServiceBMCCommandProcedure is the fully-qualified name of the MachineService's BMCCommand
// RPC.
MachineServiceBMCCommandProcedure = "/metalstack.admin.v2.MachineService/BMCCommand"
// MachineServiceGetBMCProcedure is the fully-qualified name of the MachineService's GetBMC RPC.
MachineServiceGetBMCProcedure = "/metalstack.admin.v2.MachineService/GetBMC"
// MachineServiceListBMCProcedure is the fully-qualified name of the MachineService's ListBMC RPC.
MachineServiceListBMCProcedure = "/metalstack.admin.v2.MachineService/ListBMC"
// MachineServiceConsolePasswordProcedure is the fully-qualified name of the MachineService's
// ConsolePassword RPC.
MachineServiceConsolePasswordProcedure = "/metalstack.admin.v2.MachineService/ConsolePassword"
)
// MachineServiceClient is a client for the metalstack.admin.v2.MachineService service.
type MachineServiceClient interface {
// Returns the machine with the specified UUID.
Get(context.Context, *v2.MachineServiceGetRequest) (*v2.MachineServiceGetResponse, error)
// Returns the list of all machines.
List(context.Context, *v2.MachineServiceListRequest) (*v2.MachineServiceListResponse, error)
// BMCCommand sends a command to the BMC of a machine.
BMCCommand(context.Context, *v2.MachineServiceBMCCommandRequest) (*v2.MachineServiceBMCCommandResponse, error)
// Returns the BMC details of a machine.
GetBMC(context.Context, *v2.MachineServiceGetBMCRequest) (*v2.MachineServiceGetBMCResponse, error)
// ListBMC returns the BMC details of many machines.
ListBMC(context.Context, *v2.MachineServiceListBMCRequest) (*v2.MachineServiceListBMCResponse, error)
// GetConsolePassword returns the password to access the serial console of the machine.
ConsolePassword(context.Context, *v2.MachineServiceConsolePasswordRequest) (*v2.MachineServiceConsolePasswordResponse, error)
}
// NewMachineServiceClient constructs a client for the metalstack.admin.v2.MachineService service.
// By default, it uses the Connect protocol with the binary Protobuf Codec, asks for gzipped
// responses, and sends uncompressed requests. To use the gRPC or gRPC-Web protocols, supply the
// connect.WithGRPC() or connect.WithGRPCWeb() options.
//
// The URL supplied here should be the base URL for the Connect or gRPC server (for example,
// http://api.acme.com or https://acme.com/grpc).
func NewMachineServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) MachineServiceClient {
baseURL = strings.TrimRight(baseURL, "/")
machineServiceMethods := v2.File_metalstack_admin_v2_machine_proto.Services().ByName("MachineService").Methods()
return &machineServiceClient{
get: connect.NewClient[v2.MachineServiceGetRequest, v2.MachineServiceGetResponse](
httpClient,
baseURL+MachineServiceGetProcedure,
connect.WithSchema(machineServiceMethods.ByName("Get")),
connect.WithClientOptions(opts...),
),
list: connect.NewClient[v2.MachineServiceListRequest, v2.MachineServiceListResponse](
httpClient,
baseURL+MachineServiceListProcedure,
connect.WithSchema(machineServiceMethods.ByName("List")),
connect.WithClientOptions(opts...),
),
bMCCommand: connect.NewClient[v2.MachineServiceBMCCommandRequest, v2.MachineServiceBMCCommandResponse](
httpClient,
baseURL+MachineServiceBMCCommandProcedure,
connect.WithSchema(machineServiceMethods.ByName("BMCCommand")),
connect.WithClientOptions(opts...),
),
getBMC: connect.NewClient[v2.MachineServiceGetBMCRequest, v2.MachineServiceGetBMCResponse](
httpClient,
baseURL+MachineServiceGetBMCProcedure,
connect.WithSchema(machineServiceMethods.ByName("GetBMC")),
connect.WithClientOptions(opts...),
),
listBMC: connect.NewClient[v2.MachineServiceListBMCRequest, v2.MachineServiceListBMCResponse](
httpClient,
baseURL+MachineServiceListBMCProcedure,
connect.WithSchema(machineServiceMethods.ByName("ListBMC")),
connect.WithClientOptions(opts...),
),
consolePassword: connect.NewClient[v2.MachineServiceConsolePasswordRequest, v2.MachineServiceConsolePasswordResponse](
httpClient,
baseURL+MachineServiceConsolePasswordProcedure,
connect.WithSchema(machineServiceMethods.ByName("ConsolePassword")),
connect.WithClientOptions(opts...),
),
}
}
// machineServiceClient implements MachineServiceClient.
type machineServiceClient struct {
get *connect.Client[v2.MachineServiceGetRequest, v2.MachineServiceGetResponse]
list *connect.Client[v2.MachineServiceListRequest, v2.MachineServiceListResponse]
bMCCommand *connect.Client[v2.MachineServiceBMCCommandRequest, v2.MachineServiceBMCCommandResponse]
getBMC *connect.Client[v2.MachineServiceGetBMCRequest, v2.MachineServiceGetBMCResponse]
listBMC *connect.Client[v2.MachineServiceListBMCRequest, v2.MachineServiceListBMCResponse]
consolePassword *connect.Client[v2.MachineServiceConsolePasswordRequest, v2.MachineServiceConsolePasswordResponse]
}
// Get calls metalstack.admin.v2.MachineService.Get.
func (c *machineServiceClient) Get(ctx context.Context, req *v2.MachineServiceGetRequest) (*v2.MachineServiceGetResponse, error) {
response, err := c.get.CallUnary(ctx, connect.NewRequest(req))
if response != nil {
return response.Msg, err
}
return nil, err
}
// List calls metalstack.admin.v2.MachineService.List.
func (c *machineServiceClient) List(ctx context.Context, req *v2.MachineServiceListRequest) (*v2.MachineServiceListResponse, error) {
response, err := c.list.CallUnary(ctx, connect.NewRequest(req))
if response != nil {
return response.Msg, err
}
return nil, err
}
// BMCCommand calls metalstack.admin.v2.MachineService.BMCCommand.
func (c *machineServiceClient) BMCCommand(ctx context.Context, req *v2.MachineServiceBMCCommandRequest) (*v2.MachineServiceBMCCommandResponse, error) {
response, err := c.bMCCommand.CallUnary(ctx, connect.NewRequest(req))
if response != nil {
return response.Msg, err
}
return nil, err
}
// GetBMC calls metalstack.admin.v2.MachineService.GetBMC.
func (c *machineServiceClient) GetBMC(ctx context.Context, req *v2.MachineServiceGetBMCRequest) (*v2.MachineServiceGetBMCResponse, error) {
response, err := c.getBMC.CallUnary(ctx, connect.NewRequest(req))
if response != nil {
return response.Msg, err
}
return nil, err
}
// ListBMC calls metalstack.admin.v2.MachineService.ListBMC.
func (c *machineServiceClient) ListBMC(ctx context.Context, req *v2.MachineServiceListBMCRequest) (*v2.MachineServiceListBMCResponse, error) {
response, err := c.listBMC.CallUnary(ctx, connect.NewRequest(req))
if response != nil {
return response.Msg, err
}
return nil, err
}
// ConsolePassword calls metalstack.admin.v2.MachineService.ConsolePassword.
func (c *machineServiceClient) ConsolePassword(ctx context.Context, req *v2.MachineServiceConsolePasswordRequest) (*v2.MachineServiceConsolePasswordResponse, error) {
response, err := c.consolePassword.CallUnary(ctx, connect.NewRequest(req))
if response != nil {
return response.Msg, err
}
return nil, err
}
// MachineServiceHandler is an implementation of the metalstack.admin.v2.MachineService service.
type MachineServiceHandler interface {
// Returns the machine with the specified UUID.
Get(context.Context, *v2.MachineServiceGetRequest) (*v2.MachineServiceGetResponse, error)
// Returns the list of all machines.
List(context.Context, *v2.MachineServiceListRequest) (*v2.MachineServiceListResponse, error)
// BMCCommand sends a command to the BMC of a machine.
BMCCommand(context.Context, *v2.MachineServiceBMCCommandRequest) (*v2.MachineServiceBMCCommandResponse, error)
// Returns the BMC details of a machine.
GetBMC(context.Context, *v2.MachineServiceGetBMCRequest) (*v2.MachineServiceGetBMCResponse, error)
// ListBMC returns the BMC details of many machines.
ListBMC(context.Context, *v2.MachineServiceListBMCRequest) (*v2.MachineServiceListBMCResponse, error)
// GetConsolePassword returns the password to access the serial console of the machine.
ConsolePassword(context.Context, *v2.MachineServiceConsolePasswordRequest) (*v2.MachineServiceConsolePasswordResponse, error)
}
// NewMachineServiceHandler builds an HTTP handler from the service implementation. It returns the
// path on which to mount the handler and the handler itself.
//
// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf
// and JSON codecs. They also support gzip compression.
func NewMachineServiceHandler(svc MachineServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) {
machineServiceMethods := v2.File_metalstack_admin_v2_machine_proto.Services().ByName("MachineService").Methods()
machineServiceGetHandler := connect.NewUnaryHandlerSimple(
MachineServiceGetProcedure,
svc.Get,
connect.WithSchema(machineServiceMethods.ByName("Get")),
connect.WithHandlerOptions(opts...),
)
machineServiceListHandler := connect.NewUnaryHandlerSimple(
MachineServiceListProcedure,
svc.List,
connect.WithSchema(machineServiceMethods.ByName("List")),
connect.WithHandlerOptions(opts...),
)
machineServiceBMCCommandHandler := connect.NewUnaryHandlerSimple(
MachineServiceBMCCommandProcedure,
svc.BMCCommand,
connect.WithSchema(machineServiceMethods.ByName("BMCCommand")),
connect.WithHandlerOptions(opts...),
)
machineServiceGetBMCHandler := connect.NewUnaryHandlerSimple(
MachineServiceGetBMCProcedure,
svc.GetBMC,
connect.WithSchema(machineServiceMethods.ByName("GetBMC")),
connect.WithHandlerOptions(opts...),
)
machineServiceListBMCHandler := connect.NewUnaryHandlerSimple(
MachineServiceListBMCProcedure,
svc.ListBMC,
connect.WithSchema(machineServiceMethods.ByName("ListBMC")),
connect.WithHandlerOptions(opts...),
)
machineServiceConsolePasswordHandler := connect.NewUnaryHandlerSimple(
MachineServiceConsolePasswordProcedure,
svc.ConsolePassword,
connect.WithSchema(machineServiceMethods.ByName("ConsolePassword")),
connect.WithHandlerOptions(opts...),
)
return "/metalstack.admin.v2.MachineService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case MachineServiceGetProcedure:
machineServiceGetHandler.ServeHTTP(w, r)
case MachineServiceListProcedure:
machineServiceListHandler.ServeHTTP(w, r)
case MachineServiceBMCCommandProcedure:
machineServiceBMCCommandHandler.ServeHTTP(w, r)
case MachineServiceGetBMCProcedure:
machineServiceGetBMCHandler.ServeHTTP(w, r)
case MachineServiceListBMCProcedure:
machineServiceListBMCHandler.ServeHTTP(w, r)
case MachineServiceConsolePasswordProcedure:
machineServiceConsolePasswordHandler.ServeHTTP(w, r)
default:
http.NotFound(w, r)
}
})
}
// UnimplementedMachineServiceHandler returns CodeUnimplemented from all methods.
type UnimplementedMachineServiceHandler struct{}
func (UnimplementedMachineServiceHandler) Get(context.Context, *v2.MachineServiceGetRequest) (*v2.MachineServiceGetResponse, error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.MachineService.Get is not implemented"))
}
func (UnimplementedMachineServiceHandler) List(context.Context, *v2.MachineServiceListRequest) (*v2.MachineServiceListResponse, error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.MachineService.List is not implemented"))
}
func (UnimplementedMachineServiceHandler) BMCCommand(context.Context, *v2.MachineServiceBMCCommandRequest) (*v2.MachineServiceBMCCommandResponse, error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.MachineService.BMCCommand is not implemented"))
}
func (UnimplementedMachineServiceHandler) GetBMC(context.Context, *v2.MachineServiceGetBMCRequest) (*v2.MachineServiceGetBMCResponse, error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.MachineService.GetBMC is not implemented"))
}
func (UnimplementedMachineServiceHandler) ListBMC(context.Context, *v2.MachineServiceListBMCRequest) (*v2.MachineServiceListBMCResponse, error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.MachineService.ListBMC is not implemented"))
}
func (UnimplementedMachineServiceHandler) ConsolePassword(context.Context, *v2.MachineServiceConsolePasswordRequest) (*v2.MachineServiceConsolePasswordResponse, error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.MachineService.ConsolePassword is not implemented"))
}