Skip to content

Commit

Permalink
add support for power switch annotations
Browse files Browse the repository at this point in the history
the GetPowerInfo function returns a string
map with the available annotations:

power.hhfab.githedgehog.com/psu1: http://PDUIP/outlet/1
power.hhfab.githedgehog.com/psu2: http://PDUIP/outlet/2
  • Loading branch information
pau-hedgehog committed Dec 11, 2024
1 parent 4d940e7 commit 8f44b51
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkg/hhfctl/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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://"
Expand Down Expand Up @@ -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
}

0 comments on commit 8f44b51

Please sign in to comment.