mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 11:37:01 -07:00
refactor: improve Redfish service connection handling and update status retrieval
This commit is contained in:
parent
51c01df73a
commit
03bf2250a4
1 changed files with 16 additions and 13 deletions
|
|
@ -2,10 +2,8 @@ package magellan
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/OpenCHAMI/magellan/pkg/client"
|
|
||||||
"github.com/stmcginnis/gofish"
|
"github.com/stmcginnis/gofish"
|
||||||
"github.com/stmcginnis/gofish/redfish"
|
"github.com/stmcginnis/gofish/redfish"
|
||||||
)
|
)
|
||||||
|
|
@ -37,7 +35,7 @@ func UpdateFirmwareRemote(q *UpdateParams) error {
|
||||||
return fmt.Errorf("failed to parse URI: %w", err)
|
return fmt.Errorf("failed to parse URI: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect to the Redfish service using gofish (using insecure connection for this example)
|
// Connect to the Redfish service using gofish (using insecure connection for this)
|
||||||
client, err := gofish.Connect(gofish.ClientConfig{Endpoint: uri.String(), Username: q.Username, Password: q.Password, Insecure: true})
|
client, err := gofish.Connect(gofish.ClientConfig{Endpoint: uri.String(), Username: q.Username, Password: q.Password, Insecure: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to connect to Redfish service: %w", err)
|
return fmt.Errorf("failed to connect to Redfish service: %w", err)
|
||||||
|
|
@ -71,18 +69,23 @@ func GetUpdateStatus(q *UpdateParams) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to parse URI: %w", err)
|
return fmt.Errorf("failed to parse URI: %w", err)
|
||||||
}
|
}
|
||||||
uri.User = url.UserPassword(q.Username, q.Password)
|
|
||||||
updateUrl := fmt.Sprintf("%s/redfish/v1/UpdateService", uri.String())
|
// Connect to the Redfish service using gofish (using insecure connection for this)
|
||||||
res, body, err := client.MakeRequest(nil, updateUrl, "GET", nil, nil)
|
client, err := gofish.Connect(gofish.ClientConfig{Endpoint: uri.String(), Username: q.Username, Password: q.Password, Insecure: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("something went wrong: %v", err)
|
return fmt.Errorf("failed to connect to Redfish service: %w", err)
|
||||||
} else if res == nil {
|
|
||||||
return fmt.Errorf("no response returned (url: %s)", updateUrl)
|
|
||||||
} else if res.StatusCode != http.StatusOK {
|
|
||||||
return fmt.Errorf("returned status code %d", res.StatusCode)
|
|
||||||
}
|
}
|
||||||
if len(body) > 0 {
|
defer client.Logout()
|
||||||
fmt.Printf("%v\n", string(body))
|
|
||||||
|
// Retrieve the UpdateService from the Redfish client
|
||||||
|
updateService, err := client.Service.UpdateService()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to get update service: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the update status
|
||||||
|
status := updateService.Status
|
||||||
|
fmt.Printf("Update Status: %v\n", status)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue