Skip to content

Commit

Permalink
Parse PowerConsumedWatts for any data type
Browse files Browse the repository at this point in the history
CASMHMS-6148
  • Loading branch information
jwlv authored Apr 23, 2024
1 parent 6105494 commit ceb7ac7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.5.0
3.6.0
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion cmd/capmcd/nodecap.go
Original file line number Diff line number Diff line change
@@ -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"),
Expand Down Expand Up @@ -30,6 +30,7 @@ import (
"fmt"
"io"
"log"
"math"
"net/http"
"path"
"strings"
Expand Down Expand Up @@ -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 [email protected].
// Looking at you Intel...
Expand Down
4 changes: 2 additions & 2 deletions internal/capmc/rfpower.go
Original file line number Diff line number Diff line change
@@ -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"),
Expand Down Expand Up @@ -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"`
Expand Down

0 comments on commit ceb7ac7

Please sign in to comment.