blob: e835a7e88ff95162a100c71343b8f3467f4bed78 [file] [log] [blame]
Tim Windelschmidt6d33a432025-02-04 14:34:25 +01001// Copyright The Monogon Project Authors.
2// SPDX-License-Identifier: Apache-2.0
3
Tim Windelschmidt886c3862023-05-23 16:47:41 +02004package main
5
6import (
7 "context"
Tim Windelschmidtb765f242024-05-08 01:40:02 +02008 "os"
9 "os/signal"
Tim Windelschmidt886c3862023-05-23 16:47:41 +020010
11 "github.com/spf13/cobra"
12 "k8s.io/klog/v2"
13
Tim Windelschmidtb6308cd2023-10-10 21:19:03 +020014 "source.monogon.dev/cloud/equinix/wrapngo"
Tim Windelschmidt886c3862023-05-23 16:47:41 +020015)
16
17var moveCmd = &cobra.Command{
18 Use: "move [source] [target]",
19 Short: "Move all reserved hardware from one to another project",
20 Args: cobra.ExactArgs(2),
21 Run: doMove,
22}
23
24func init() {
25 rootCmd.AddCommand(moveCmd)
26}
27
28func doMove(cmd *cobra.Command, args []string) {
Tim Windelschmidtb765f242024-05-08 01:40:02 +020029 ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt)
Tim Windelschmidt886c3862023-05-23 16:47:41 +020030 api := wrapngo.New(&c)
31
32 klog.Infof("Listing reservations for %q", args[0])
33 reservations, err := api.ListReservations(ctx, args[0])
34 if err != nil {
35 klog.Exitf("failed listing reservations: %v", err)
36 }
37
38 klog.Infof("Got %d reservations. Moving machines", len(reservations))
39 for _, r := range reservations {
40 _, err := api.MoveReservation(ctx, r.ID, args[1])
41 if err != nil {
42 klog.Errorf("failed moving reservation: %v", err)
43 continue
44 }
45 klog.Infof("Moved Device %s", r.ID)
46 }
47}