-
Notifications
You must be signed in to change notification settings - Fork 7
Adding Support for JAWS PDU devices #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mbuchmann-hpe
wants to merge
4
commits into
OpenCHAMI:main
Choose a base branch
from
mbuchmann-hpe:JAWSSupport_RB
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
854560e
r Adding Support for JAWS PDU devices
mbuchmann-hpe 21eda97
Added updated payload for jaws, dockerfiles
mbuchmann-hpe 7eabbc6
Added error message from review
mbuchmann-hpe 79a8fc7
Removed GODEBUG from Dockerfile and replaced with CipherSuites TLS Co…
mbuchmann-hpe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,204 @@ | ||
| // MIT License | ||
| // | ||
| // (C) Copyright [2025] 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"), | ||
| // to deal in the Software without restriction, including without limitation | ||
| // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
| // and/or sell copies of the Software, and to permit persons to whom the | ||
| // Software is furnished to do so, subject to the following conditions: | ||
| // | ||
| // The above copyright notice and this permission notice shall be included | ||
| // in all copies or substantial portions of the Software. | ||
| // | ||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
| // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
| // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
| // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
| // OTHER DEALINGS IN THE SOFTWARE. | ||
|
|
||
| package domain | ||
|
|
||
| import ( | ||
| "context" | ||
| "crypto/tls" | ||
| "encoding/json" | ||
| "io" | ||
| "net/http" | ||
| "net/url" | ||
| "strconv" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/hashicorp/go-retryablehttp" | ||
| "github.com/sirupsen/logrus" | ||
|
|
||
| "github.com/OpenCHAMI/power-control/v2/internal/logger" | ||
| pcsmodel "github.com/OpenCHAMI/power-control/v2/internal/model" | ||
| ) | ||
|
|
||
| type JawsEndpointStatus struct { | ||
| Id string `json:"id"` | ||
| Name string `json:"name"` | ||
| Active_power int `json:"active_power"` | ||
| Active_power_status string `json:"active_power_status"` | ||
| Apparent_power int `json:"apparent_power"` | ||
| Branch_id string `json:"branch_id"` | ||
| Control_state string `json:"control_state"` | ||
| Current float32 `json:"current"` | ||
| Current_capacity int `json:"current_capacity"` | ||
| Current_status string `json:"current_status"` | ||
| Current_utilized float32 `json:"current_utilized"` | ||
| Energy int `json:"energy"` | ||
| Ocp_id string `json:"ocp_id"` | ||
| Phase_id string `json:"phase_id"` | ||
| Power_capacity int `json:"power_capacity"` | ||
| Power_factor_status string `json:"power_factor_status"` | ||
| Socket_adapter string `json:"socket_adapter"` | ||
| Socket_type string `json:"socket_type"` | ||
| State string `json:"state"` | ||
| Status string `json:"status"` | ||
| Voltage float32 `json:"voltage"` | ||
| } | ||
|
|
||
| func jawsSuites() []uint16 { | ||
| suites := []uint16{tls.TLS_RSA_WITH_AES_128_GCM_SHA256, tls.TLS_RSA_WITH_AES_256_GCM_SHA384, tls.TLS_RSA_WITH_AES_128_CBC_SHA, tls.TLS_RSA_WITH_AES_256_CBC_SHA} | ||
| for _, c := range tls.CipherSuites() { | ||
| suites = append(suites, c.ID) | ||
| } | ||
| return suites | ||
| } | ||
|
|
||
| // Load JAWS outlets and store | ||
| func JawsLoad(xname string, FQDN string, authUser string, authPass string) { | ||
|
|
||
| tlsConfig := &tls.Config{ | ||
| InsecureSkipVerify: true, | ||
| CipherSuites: jawsSuites(), | ||
| } | ||
|
|
||
| timeout := 20 | ||
| transport := &http.Transport{ | ||
| // TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, | ||
| TLSClientConfig: tlsConfig, | ||
| } | ||
| client := retryablehttp.NewClient() | ||
| client.HTTPClient.Transport = transport | ||
|
|
||
| var req *retryablehttp.Request | ||
|
|
||
| // jaws/monitor/outlets | ||
| jurl, _ := url.Parse("https://" + FQDN + "/jaws/monitor/outlets") | ||
| req, err := retryablehttp.NewRequest("GET", jurl.String(), nil) | ||
| if err != nil { | ||
| logger.Log.Error(err) | ||
| return | ||
| } | ||
|
|
||
| reqContext, reqCtxCancel := context.WithTimeout(context.Background(), time.Second*time.Duration(timeout)) | ||
| req = req.WithContext(reqContext) | ||
|
|
||
| req.Header.Add("Content-Type", "application/json") | ||
| req.Header.Add("cache-control", "no-cache") | ||
|
|
||
| if !(authUser == "" && authPass == "") { | ||
| req.SetBasicAuth(authUser, authPass) | ||
| } | ||
|
|
||
| resp, err := client.Do(req) | ||
| defer drainAndCloseBodyWithCtxCancel(resp, reqCtxCancel) | ||
| if err != nil { | ||
| logger.Log.Error(err) | ||
| return | ||
| } | ||
|
|
||
| body, err := io.ReadAll(resp.Body) | ||
| var eps []JawsEndpointStatus | ||
| if err != nil { | ||
| logger.Log.Error(err) | ||
| return | ||
| } | ||
| err = json.Unmarshal(body, &eps) | ||
| if err != nil { | ||
| logger.Log.Error(err) | ||
| return | ||
| } | ||
|
|
||
| // Store power state for each outlet | ||
| for _, jep2 := range eps { | ||
| epxname := jaws2xname(xname, jep2.Id) | ||
|
|
||
| powerState := pcsmodel.PowerStateFilter_Undefined | ||
| if strings.EqualFold(jep2.State, "on") { | ||
| powerState = pcsmodel.PowerStateFilter_On | ||
| } else if strings.EqualFold(jep2.State, "off") { | ||
| powerState = pcsmodel.PowerStateFilter_Off | ||
| } | ||
|
|
||
| updateHWState(epxname, powerState, pcsmodel.ManagementStateFilter_available, "") | ||
| } | ||
| return | ||
| } | ||
|
|
||
| // Convert JAWS outlet name to an xname | ||
| // example: x3000m0p0v17 | ||
| func jaws2xname(xname string, id string) string { | ||
| nxname := xname | ||
| nxname = nxname + "p" + strconv.Itoa(int(id[0])-int('A')) | ||
| nxname = nxname + "v" + id[2:] | ||
| return nxname | ||
| } | ||
|
|
||
| // JAWS loop to monitor PDUs | ||
| func JawsMonitor(looptime int) { | ||
| logger.Log.Info("In JAWS Monitor") | ||
| if looptime == 0 { | ||
| looptime = 20 | ||
| } | ||
| // Loop forever | ||
| for { | ||
| xnameList := []string{} | ||
| // Find PDUs | ||
| compMap, err := (*hsmHandle).FillHSMData([]string{"all"}) | ||
| if err != nil { | ||
| logger.Log.Error("JAWS FillHMSDATA ERROR: ", err) | ||
| } else { | ||
| for _, xname := range compMap { | ||
| if xname.BaseData.Type == "CabinetPDUController" { | ||
| if xname.PowerStatusURI == "/jaws" { | ||
| xnameList = append(xnameList, xname.BaseData.ID) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| for _, xname := range xnameList { | ||
| logger.Log.Info("JAWS Load: " + xname) | ||
| var user, pw string | ||
| if GLOB.VaultEnabled { | ||
| user, pw, err = (*GLOB.CS).GetControllerCredentials(xname) | ||
| if err != nil { | ||
| logger.Log.WithFields(logrus.Fields{"ERROR": err}).Error("Unable to get credentials for " + xname) | ||
| } | ||
| } | ||
| JawsLoad(xname, xname, user, pw) | ||
| } | ||
| // Wait for a bit | ||
| time.Sleep(time.Duration(looptime) * time.Second) | ||
| } | ||
| } | ||
|
|
||
| func drainAndCloseBodyWithCtxCancel(resp *http.Response, ctxCancel context.CancelFunc) { | ||
| // Must always drain and close response bodies | ||
| if resp != nil && resp.Body != nil { | ||
| _, _ = io.Copy(io.Discard, resp.Body) // ok even if already drained | ||
| resp.Body.Close() | ||
| } | ||
| // Call context cancel function, if supplied. This must be done after | ||
| // draining and closing the response body | ||
| if ctxCancel != nil { | ||
| ctxCancel() | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.