c/s/e/cli: add equinix api cli tooling

This is a fairly simple and hacked together cli but it does its job for basic maintenance tasks

Change-Id: I043c12b930546f9405b9f8190326724122f1c0aa
Reviewed-on: https://review.monogon.dev/c/monogon/+/1704
Tested-by: Jenkins CI
Reviewed-by: Serge Bazanski <serge@monogon.tech>
diff --git a/cloud/shepherd/equinix/cli/cmd_delete.go b/cloud/shepherd/equinix/cli/cmd_delete.go
new file mode 100644
index 0000000..e3c51a5
--- /dev/null
+++ b/cloud/shepherd/equinix/cli/cmd_delete.go
@@ -0,0 +1,51 @@
+package main
+
+import (
+	"context"
+	"time"
+
+	"github.com/spf13/cobra"
+	"k8s.io/klog/v2"
+
+	"source.monogon.dev/cloud/shepherd/equinix/wrapngo"
+	clicontext "source.monogon.dev/metropolis/cli/pkg/context"
+)
+
+var deleteCmd = &cobra.Command{
+	Use:   "delete [target]",
+	Short: "Delete all devices from one project",
+	Args:  cobra.ExactArgs(1),
+	Run:   doDelete,
+}
+
+func init() {
+	rootCmd.AddCommand(deleteCmd)
+}
+
+func doDelete(cmd *cobra.Command, args []string) {
+	ctx := clicontext.WithInterrupt(context.Background())
+	api := wrapngo.New(&c)
+
+	klog.Infof("Listing devices for %q", args[0])
+
+	devices, err := api.ListDevices(ctx, args[0])
+	if err != nil {
+		klog.Exitf("failed listing devices: %v", err)
+	}
+
+	if len(devices) == 0 {
+		klog.Infof("No devices found in %s", args[0])
+		return
+	}
+
+	klog.Infof("Deleting %d Devices in %s. THIS WILL DELETE SERVERS! You have five seconds to cancel!", len(devices), args[0])
+	time.Sleep(5 * time.Second)
+
+	for _, d := range devices {
+		klog.Infof("deleting %s (%s)...", d.ID, d.Hostname)
+		if err := api.DeleteDevice(ctx, d.ID); err != nil {
+			klog.Infof("failed deleting device %s (%s): %v", d.ID, d.Hostname, err)
+			continue
+		}
+	}
+}