-
Notifications
You must be signed in to change notification settings - Fork 14
/
repair_queue_add.go
43 lines (36 loc) · 1.04 KB
/
repair_queue_add.go
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
package cmd
import (
"context"
"github.com/cybozu-go/cke"
"github.com/cybozu-go/well"
"github.com/spf13/cobra"
)
var repairQueueAddCmd = &cobra.Command{
Use: "add OPERATION MACHINE_TYPE ADDRESS",
Short: "append a repair request to the repair queue",
Long: `Append a repair request to the repair queue.
The repair target is a machine with an IP address ADDRESS and a machine type MACHINE_TYPE.
The machine should be processed with an operation OPERATION.`,
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
operation := args[0]
machineType := args[1]
address := args[2]
well.Go(func(ctx context.Context) error {
entry := cke.NewRepairQueueEntry(operation, machineType, address)
cluster, err := storage.GetCluster(ctx)
if err != nil {
return err
}
if _, err := entry.GetMatchingRepairOperation(cluster); err != nil {
return err
}
return storage.RegisterRepairsEntry(ctx, entry)
})
well.Stop()
return well.Wait()
},
}
func init() {
repairQueueCmd.AddCommand(repairQueueAddCmd)
}