diff --git a/.version b/.version index 1545d96..40c341b 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -3.5.0 +3.6.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index fa859fc..4096d08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,12 @@ Fixed - for any bug fixes Security - in case of vulnerabilities --> +## [3.6.0] - 2023-04-24 + +### Added + +- Parse PowerConsumedWatts for any data type + ## [3.5.0] - 2024-03-26 ### Fixed diff --git a/cmd/capmcd/nodecap.go b/cmd/capmcd/nodecap.go index 4472c96..064f9b3 100644 --- a/cmd/capmcd/nodecap.go +++ b/cmd/capmcd/nodecap.go @@ -1,7 +1,7 @@ // // MIT License // -// (C) Copyright [2019-2022] Hewlett Packard Enterprise Development LP +// (C) Copyright [2019-2022,2024] Hewlett Packard Enterprise Development LP // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), @@ -30,6 +30,7 @@ import ( "fmt" "io" "log" + "math" "net/http" "path" "strings" @@ -340,6 +341,22 @@ func (d *CapmcD) doPowerCapGet(w http.ResponseWriter, r *http.Request) { continue } + // Convert PowerConsumedWatts to an int if not already (it's an interface{} + // type that can support ints and floats) - Needed for Foxconn Paradise, + // perhaps others in the future + for _, pwrCtl := range rfPower.PowerCtl { + if pwrCtl.PowerConsumedWatts != nil { + switch v := (*pwrCtl.PowerConsumedWatts).(type) { + case float64: // Convert to int + *pwrCtl.PowerConsumedWatts = int(math.Round(v)) + case int: // noop - no conversion needed + default: // unexpected type, set to zero + *pwrCtl.PowerConsumedWatts = int(0) + log.Printf("ERROR: unexpected type/value '%T'/'%v' detected for PowerConsumedWatts, setting to 0\n", *pwrCtl.PowerConsumedWatts, *pwrCtl.PowerConsumedWatts) + } + } + } + // This would be nice to use but not all versions // of the schema support PowerControl@odata.count. // Looking at you Intel... diff --git a/internal/capmc/rfpower.go b/internal/capmc/rfpower.go index 13a88a6..0789bb1 100644 --- a/internal/capmc/rfpower.go +++ b/internal/capmc/rfpower.go @@ -1,7 +1,7 @@ /* * MIT License * - * (C) Copyright [2019-2022] Hewlett Packard Enterprise Development LP + * (C) Copyright [2019-2022,2024] Hewlett Packard Enterprise Development LP * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -93,7 +93,7 @@ type PowerControl struct { PowerAllocatedWatts *int `json:"PowerAllocatedWatts,omitempty"` PowerAvailableWatts *int `json:"PowerAvailableWatts,omitempty"` PowerCapacityWatts *int `json:"PowerCapacityWatts,omitempty"` - PowerConsumedWatts *int `json:"PowerConsumedWatts,omitempty"` + PowerConsumedWatts *interface{} `json:"PowerConsumedWatts,omitempty"` PowerLimit *PowerLimit `json:"PowerLimit,omitempty"` PowerMetrics *PowerMetric `json:"PowerMetrics,omitempty"` PowerRequestedWatts *int `json:"PowerRequestedWatts,omitempty"`