Skip to content

Commit f1c0924

Browse files
committed
add admin endpoint to node client
1 parent cf3a138 commit f1c0924

2 files changed

Lines changed: 66 additions & 7 deletions

File tree

client/node.go

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,23 +259,82 @@ func (n *NodeClient) NetworkListInterfaces(ctx context.Context) (result map[stri
259259
return
260260
}
261261

262-
// AdminRebootNode return all physical devices on a node
262+
// AdminRebootNode stops all the running services and reboots the node
263263
func (n *NodeClient) AdminRebootNode(ctx context.Context) error {
264264
const cmd = "zos.admin.reboot"
265265

266266
return n.bus.Call(ctx, n.nodeTwin, cmd, nil, nil)
267267
}
268268

269-
// AdminRestartService return all physical devices on a node
269+
// AdminRestartService restarts a zinit service
270270
func (n *NodeClient) AdminRestartService(ctx context.Context, service string) error {
271271
const cmd = "zos.admin.restart"
272272

273273
return n.bus.Call(ctx, n.nodeTwin, cmd, service, nil)
274274
}
275275

276+
// AdminRestartAll restarts all zinit services
277+
func (n *NodeClient) AdminRestartAll(ctx context.Context) error {
278+
const cmd = "zos.admin.restart_all"
279+
280+
return n.bus.Call(ctx, n.nodeTwin, cmd, nil, nil)
281+
}
282+
283+
// AdminShowLogs returns a l lines of zinit logs
284+
func (n *NodeClient) AdminShowLogs(ctx context.Context, l int) (logs []byte, err error) {
285+
const cmd = "zos.admin.show_logs"
286+
287+
err = n.bus.Call(ctx, n.nodeTwin, cmd, l, &logs)
288+
return
289+
}
290+
291+
// AdminShowResolve return the content of /etc/resolv.conf
292+
func (n *NodeClient) AdminShowResolve(ctx context.Context) (res []byte, err error) {
293+
const cmd = "zos.admin.show_resolve"
294+
295+
err = n.bus.Call(ctx, n.nodeTwin, cmd, nil, &res)
296+
return
297+
}
298+
299+
// AdminShowOpenConnections return information about all open connections in the node
300+
func (n *NodeClient) AdminShowOpenConnections(ctx context.Context) (res []byte, err error) {
301+
const cmd = "zos.admin.show_open_connections"
302+
303+
err = n.bus.Call(ctx, n.nodeTwin, cmd, nil, &res)
304+
return
305+
}
306+
307+
// AdminStopWorkload stops a workload
308+
func (n *NodeClient) AdminStopWorkload(ctx context.Context, twinID uint32, wlID uint64) error {
309+
const cmd = "zos.admin.stop_workload"
310+
args := struct {
311+
TwinID uint32 `json:"twin_id"`
312+
WorkloadID uint64 `json:"workload_id"`
313+
}{
314+
TwinID: twinID,
315+
WorkloadID: wlID,
316+
}
317+
318+
return n.bus.Call(ctx, n.nodeTwin, cmd, args, nil)
319+
}
320+
321+
// AdminResumeWorkload stops a workload
322+
func (n *NodeClient) AdminResumeWorkload(ctx context.Context, twinID uint32, wlID uint64) error {
323+
const cmd = "zos.admin.resume_workload"
324+
args := struct {
325+
TwinID uint32 `json:"twin_id"`
326+
WorkloadID uint64 `json:"workload_id"`
327+
}{
328+
TwinID: twinID,
329+
WorkloadID: wlID,
330+
}
331+
332+
return n.bus.Call(ctx, n.nodeTwin, cmd, args, nil)
333+
}
334+
276335
// NetworkListAllInterfaces return all physical devices on a node
277336
func (n *NodeClient) NetworkListAllInterfaces(ctx context.Context) (result map[string]Interface, err error) {
278-
const cmd = "zos.network.admin.interfaces"
337+
const cmd = "zos.admin.interfaces"
279338

280339
err = n.bus.Call(ctx, n.nodeTwin, cmd, nil, &result)
281340

@@ -285,14 +344,14 @@ func (n *NodeClient) NetworkListAllInterfaces(ctx context.Context) (result map[s
285344
// NetworkSetPublicExitDevice select which physical interface to use as an exit device
286345
// setting `iface` to `zos` will then make node run in a single nic setup.
287346
func (n *NodeClient) NetworkSetPublicExitDevice(ctx context.Context, iface string) error {
288-
const cmd = "zos.network.admin.set_public_nic"
347+
const cmd = "zos.admin.set_public_nic"
289348

290349
return n.bus.Call(ctx, n.nodeTwin, cmd, iface, nil)
291350
}
292351

293352
// NetworkGetPublicExitDevice gets the current dual nic setup of the node.
294353
func (n *NodeClient) NetworkGetPublicExitDevice(ctx context.Context) (exit ExitDevice, err error) {
295-
const cmd = "zos.network.admin.get_public_nic"
354+
const cmd = "zos.admin.get_public_nic"
296355

297356
err = n.bus.Call(ctx, n.nodeTwin, cmd, nil, &exit)
298357
return

pkg/zos_api/routes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ func (g *ZosAPI) SetupRoutes(router *peer.Router) {
4949
admin.WithHandler("restart", g.adminRestartServiceHandler)
5050
admin.WithHandler("restart_all", g.adminRestartAllHandler)
5151

52-
admin.WithHandler("logs", g.adminShowLogsHandler)
52+
admin.WithHandler("show_logs", g.adminShowLogsHandler)
5353
admin.WithHandler("show_resolve", g.adminShowResolveHandler)
54-
admin.WithHandler("get_open_connections", g.adminShowOpenConnectionsHandler)
54+
admin.WithHandler("show_open_connections", g.adminShowOpenConnectionsHandler)
5555

5656
admin.WithHandler("stop_workload", g.adminStopWorkloadHandler)
5757
admin.WithHandler("resume_workload", g.adminResumeWorkloadHandler)

0 commit comments

Comments
 (0)