blob: 7fcd35c26c53a834faec234f980a5679c48dc3c2 [file] [log] [blame]
Tim Windelschmidt886c3862023-05-23 16:47:41 +02001package main
2
3import (
4 "context"
5
6 "github.com/spf13/cobra"
7 "k8s.io/klog/v2"
8
Tim Windelschmidtb6308cd2023-10-10 21:19:03 +02009 "source.monogon.dev/cloud/equinix/wrapngo"
Tim Windelschmidt886c3862023-05-23 16:47:41 +020010 clicontext "source.monogon.dev/metropolis/cli/pkg/context"
11)
12
13var rebootCmd = &cobra.Command{
14 Use: "reboot [project] [id]",
15 Short: "Reboots all or one specific node",
16 Args: cobra.MaximumNArgs(1),
17 Run: doReboot,
18}
19
20func init() {
21 rootCmd.AddCommand(rebootCmd)
22}
23
24func doReboot(cmd *cobra.Command, args []string) {
25 ctx := clicontext.WithInterrupt(context.Background())
26 api := wrapngo.New(&c)
27
28 klog.Infof("Requesting device list...")
29 devices, err := api.ListDevices(ctx, args[0])
30 if err != nil {
31 klog.Fatal(err)
32 }
33
34 for _, d := range devices {
35 if len(args) == 2 && args[1] != d.ID {
36 continue
37 }
38
39 err := api.RebootDevice(ctx, d.ID)
40 if err != nil {
41 klog.Error(err)
42 continue
43 }
44 klog.Infof("rebooted %s", d.ID)
45 }
46}