diff --git a/pkg/hhfctl/switch.go b/pkg/hhfctl/switch.go index d5ccfccf..9d6db5a2 100644 --- a/pkg/hhfctl/switch.go +++ b/pkg/hhfctl/switch.go @@ -32,6 +32,7 @@ import ( const ( HHFabCfgPrefix = ".hhfab.githedgehog.com" HHFabCfgSerial = "serial" + HHFabCfgPrefix + HHFabCfgPower = "power" + HHFabCfgPrefix HHFctlCfgPrefix = ".fabric.githedgehog.com" HHFctlCfgSerial = "serial" + HHFctlCfgPrefix HHFabCfgSerialSchemeSSH = "ssh://" @@ -236,3 +237,31 @@ func GetSerialInfo(sw *wiringapi.Switch) string { return "" } + +func GetPowerInfo(ctx context.Context, swName string) map[string]string { + kube, err := kubeutil.NewClient(ctx, "", wiringapi.SchemeBuilder) + if err != nil { + fmt.Println("\tError creating kube client %w", err) + + return nil + } + + sw := &wiringapi.Switch{} + if err := kube.Get(ctx, client.ObjectKey{Name: swName, Namespace: metav1.NamespaceDefault}, sw); err != nil { + fmt.Printf("\tError getting switch %s: %v\n", swName, err) + + return nil + } + + powerInfo := make(map[string]string) + if annotations := sw.GetAnnotations(); annotations != nil { + for key, value := range annotations { + if strings.HasPrefix(key, HHFabCfgPower+"/") { + psuName := strings.TrimPrefix(key, HHFabCfgPower+"/") + powerInfo[psuName] = value + } + } + } + + return powerInfo +}