mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 11:37:01 -07:00
refactor: moved internal functions to pkg and updated refs
This commit is contained in:
parent
a270d68e4b
commit
1477da9693
1 changed files with 60 additions and 0 deletions
|
|
@ -1,11 +1,20 @@
|
||||||
package magellan
|
package magellan
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
<<<<<<< HEAD
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/stmcginnis/gofish"
|
"github.com/stmcginnis/gofish"
|
||||||
"github.com/stmcginnis/gofish/redfish"
|
"github.com/stmcginnis/gofish/redfish"
|
||||||
|
=======
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
|
"github.com/OpenCHAMI/magellan/pkg/client"
|
||||||
|
>>>>>>> 81116ec (refactor: moved internal functions to pkg and updated refs)
|
||||||
)
|
)
|
||||||
|
|
||||||
type UpdateParams struct {
|
type UpdateParams struct {
|
||||||
|
|
@ -14,12 +23,16 @@ type UpdateParams struct {
|
||||||
FirmwareVersion string
|
FirmwareVersion string
|
||||||
Component string
|
Component string
|
||||||
TransferProtocol string
|
TransferProtocol string
|
||||||
|
<<<<<<< HEAD
|
||||||
Insecure bool
|
Insecure bool
|
||||||
|
=======
|
||||||
|
>>>>>>> 81116ec (refactor: moved internal functions to pkg and updated refs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateFirmwareRemote() uses 'gofish' to update the firmware of a BMC node.
|
// UpdateFirmwareRemote() uses 'gofish' to update the firmware of a BMC node.
|
||||||
// The function expects the firmware URL, firmware version, and component flags to be
|
// The function expects the firmware URL, firmware version, and component flags to be
|
||||||
// set from the CLI to perform a firmware update.
|
// set from the CLI to perform a firmware update.
|
||||||
|
<<<<<<< HEAD
|
||||||
// Example:
|
// Example:
|
||||||
// ./magellan update https://192.168.23.40 --username root --password 0penBmc
|
// ./magellan update https://192.168.23.40 --username root --password 0penBmc
|
||||||
// --firmware-url http://192.168.23.19:1337/obmc-phosphor-image.static.mtd.tar
|
// --firmware-url http://192.168.23.19:1337/obmc-phosphor-image.static.mtd.tar
|
||||||
|
|
@ -29,12 +42,15 @@ type UpdateParams struct {
|
||||||
// q.URI https://192.168.23.40
|
// q.URI https://192.168.23.40
|
||||||
// q.TransferProtocol TFTP
|
// q.TransferProtocol TFTP
|
||||||
// q.FirmwarePath http://192.168.23.19:1337/obmc-phosphor-image.static.mtd.tar
|
// q.FirmwarePath http://192.168.23.19:1337/obmc-phosphor-image.static.mtd.tar
|
||||||
|
=======
|
||||||
|
>>>>>>> 81116ec (refactor: moved internal functions to pkg and updated refs)
|
||||||
func UpdateFirmwareRemote(q *UpdateParams) error {
|
func UpdateFirmwareRemote(q *UpdateParams) error {
|
||||||
// parse URI to set up full address
|
// parse URI to set up full address
|
||||||
uri, err := url.ParseRequestURI(q.URI)
|
uri, err := url.ParseRequestURI(q.URI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to parse URI: %w", err)
|
return fmt.Errorf("failed to parse URI: %w", err)
|
||||||
}
|
}
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
// Connect to the Redfish service using gofish
|
// Connect to the Redfish service using gofish
|
||||||
client, err := gofish.Connect(gofish.ClientConfig{Endpoint: uri.String(), Username: q.Username, Password: q.Password, Insecure: q.Insecure})
|
client, err := gofish.Connect(gofish.ClientConfig{Endpoint: uri.String(), Username: q.Username, Password: q.Password, Insecure: q.Insecure})
|
||||||
|
|
@ -61,6 +77,34 @@ func UpdateFirmwareRemote(q *UpdateParams) error {
|
||||||
return fmt.Errorf("firmware update failed: %w", err)
|
return fmt.Errorf("firmware update failed: %w", err)
|
||||||
}
|
}
|
||||||
fmt.Println("Firmware update initiated successfully.")
|
fmt.Println("Firmware update initiated successfully.")
|
||||||
|
=======
|
||||||
|
uri.User = url.UserPassword(q.Username, q.Password)
|
||||||
|
|
||||||
|
// set up other vars
|
||||||
|
updateUrl := fmt.Sprintf("%s/redfish/v1/UpdateService/Actions/SimpleUpdate", uri.String())
|
||||||
|
headers := map[string]string{
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"cache-control": "no-cache",
|
||||||
|
}
|
||||||
|
b := map[string]any{
|
||||||
|
"UpdateComponent": q.Component, // BMC, BIOS
|
||||||
|
"TransferProtocol": q.TransferProtocol,
|
||||||
|
"ImageURI": q.FirmwarePath,
|
||||||
|
}
|
||||||
|
data, err := json.Marshal(b)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to marshal data: %v", err)
|
||||||
|
}
|
||||||
|
res, body, err := client.MakeRequest(nil, updateUrl, "POST", data, headers)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("something went wrong: %v", err)
|
||||||
|
} else if res == nil {
|
||||||
|
return fmt.Errorf("no response returned (url: %s)", updateUrl)
|
||||||
|
}
|
||||||
|
if len(body) > 0 {
|
||||||
|
fmt.Printf("%d: %v\n", res.StatusCode, string(body))
|
||||||
|
}
|
||||||
|
>>>>>>> 81116ec (refactor: moved internal functions to pkg and updated refs)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -70,6 +114,7 @@ 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)
|
||||||
}
|
}
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
// Connect to the Redfish service using gofish
|
// Connect to the Redfish service using gofish
|
||||||
client, err := gofish.Connect(gofish.ClientConfig{Endpoint: uri.String(), Username: q.Username, Password: q.Password, Insecure: q.Insecure})
|
client, err := gofish.Connect(gofish.ClientConfig{Endpoint: uri.String(), Username: q.Username, Password: q.Password, Insecure: q.Insecure})
|
||||||
|
|
@ -88,5 +133,20 @@ func GetUpdateStatus(q *UpdateParams) error {
|
||||||
status := updateService.Status
|
status := updateService.Status
|
||||||
fmt.Printf("Update Status: %v\n", status)
|
fmt.Printf("Update Status: %v\n", status)
|
||||||
|
|
||||||
|
=======
|
||||||
|
uri.User = url.UserPassword(q.Username, q.Password)
|
||||||
|
updateUrl := fmt.Sprintf("%s/redfish/v1/UpdateService", uri.String())
|
||||||
|
res, body, err := client.MakeRequest(nil, updateUrl, "GET", nil, nil)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("something went wrong: %v", 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 {
|
||||||
|
fmt.Printf("%v\n", string(body))
|
||||||
|
}
|
||||||
|
>>>>>>> 81116ec (refactor: moved internal functions to pkg and updated refs)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue