mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 11:37:01 -07:00
Changed how arguments are passed to update command
This commit is contained in:
parent
bc01412b08
commit
51e24e2edd
1 changed files with 35 additions and 33 deletions
|
|
@ -1,6 +1,9 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
magellan "github.com/OpenCHAMI/magellan/internal"
|
magellan "github.com/OpenCHAMI/magellan/internal"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
@ -14,76 +17,75 @@ var (
|
||||||
firmwareVersion string
|
firmwareVersion string
|
||||||
component string
|
component string
|
||||||
transferProtocol string
|
transferProtocol string
|
||||||
status bool
|
showStatus bool
|
||||||
)
|
)
|
||||||
|
|
||||||
// The `update` command provides an interface to easily update firmware
|
// The `update` command provides an interface to easily update firmware
|
||||||
// using Redfish. It also provides a simple way to check the status of
|
// using Redfish. It also provides a simple way to check the status of
|
||||||
// an update in-progress.
|
// an update in-progress.
|
||||||
var updateCmd = &cobra.Command{
|
var updateCmd = &cobra.Command{
|
||||||
Use: "update",
|
Use: "update hosts...",
|
||||||
Short: "Update BMC node firmware",
|
Short: "Update BMC node firmware",
|
||||||
Long: "Perform an firmware update using Redfish by providing a remote firmware URL and component.\n" +
|
Long: "Perform an firmware update using Redfish by providing a remote firmware URL and component.\n" +
|
||||||
"Examples:\n" +
|
"Examples:\n" +
|
||||||
" magellan update --bmc.host 172.16.0.108 --bmc.port 443 --username bmc_username --password bmc_password --firmware-url http://172.16.0.200:8005/firmware/bios/image.RBU --component BIOS\n" +
|
" magellan update --bmc.host 172.16.0.108 --bmc.port 443 --username bmc_username --password bmc_password --firmware-url http://172.16.0.200:8005/firmware/bios/image.RBU --component BIOS\n" +
|
||||||
" magellan update --status --bmc.host 172.16.0.108 --bmc.port 443 --username bmc_username --password bmc_password",
|
" magellan update --status --bmc.host 172.16.0.108 --bmc.port 443 --username bmc_username --password bmc_password",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
// check if required params are set
|
// check that we have at least one host
|
||||||
if host == "" || username == "" || password == "" {
|
if len(args) <= 0 {
|
||||||
log.Error().Msg("requires host, user, and pass to be set")
|
log.Error().Msg("update requires at least one host")
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get status if flag is set and exit
|
// get status if flag is set and exit
|
||||||
if status {
|
for _, arg := range args {
|
||||||
err := magellan.GetUpdateStatus(&magellan.UpdateParams{
|
if showStatus {
|
||||||
|
err := magellan.GetUpdateStatus(&magellan.UpdateParams{
|
||||||
|
FirmwarePath: firmwareUrl,
|
||||||
|
FirmwareVersion: firmwareVersion,
|
||||||
|
Component: component,
|
||||||
|
TransferProtocol: transferProtocol,
|
||||||
|
CollectParams: magellan.CollectParams{
|
||||||
|
URI: arg,
|
||||||
|
Username: username,
|
||||||
|
Password: password,
|
||||||
|
Timeout: timeout,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msgf("failed to get update status")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// initiate a remote update
|
||||||
|
err := magellan.UpdateFirmwareRemote(&magellan.UpdateParams{
|
||||||
FirmwarePath: firmwareUrl,
|
FirmwarePath: firmwareUrl,
|
||||||
FirmwareVersion: firmwareVersion,
|
FirmwareVersion: firmwareVersion,
|
||||||
Component: component,
|
Component: component,
|
||||||
TransferProtocol: transferProtocol,
|
TransferProtocol: strings.ToUpper(transferProtocol),
|
||||||
CollectParams: magellan.CollectParams{
|
CollectParams: magellan.CollectParams{
|
||||||
Host: host,
|
URI: host,
|
||||||
Username: username,
|
Username: username,
|
||||||
Password: password,
|
Password: password,
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
Port: port,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msgf("failed to get update status")
|
log.Error().Err(err).Msgf("failed to update firmware")
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// initiate a remote update
|
|
||||||
err := magellan.UpdateFirmwareRemote(&magellan.UpdateParams{
|
|
||||||
FirmwarePath: firmwareUrl,
|
|
||||||
FirmwareVersion: firmwareVersion,
|
|
||||||
Component: component,
|
|
||||||
TransferProtocol: transferProtocol,
|
|
||||||
CollectParams: magellan.CollectParams{
|
|
||||||
Host: host,
|
|
||||||
Username: username,
|
|
||||||
Password: password,
|
|
||||||
Timeout: timeout,
|
|
||||||
Port: port,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Error().Err(err).Msgf("failed to update firmware")
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
updateCmd.Flags().StringVar(&host, "bmc.host", "", "set the BMC host")
|
|
||||||
updateCmd.Flags().IntVar(&port, "bmc.port", 443, "set the BMC port")
|
|
||||||
updateCmd.Flags().StringVar(&username, "username", "", "set the BMC user")
|
updateCmd.Flags().StringVar(&username, "username", "", "set the BMC user")
|
||||||
updateCmd.Flags().StringVar(&password, "password", "", "set the BMC password")
|
updateCmd.Flags().StringVar(&password, "password", "", "set the BMC password")
|
||||||
updateCmd.Flags().StringVar(&transferProtocol, "transfer-protocol", "HTTP", "set the transfer protocol")
|
updateCmd.Flags().StringVar(&transferProtocol, "transfer-protocol", "HTTP", "set the transfer protocol")
|
||||||
updateCmd.Flags().StringVar(&firmwareUrl, "firmware.url", "", "set the path to the firmware")
|
updateCmd.Flags().StringVar(&firmwareUrl, "firmware.url", "", "set the path to the firmware")
|
||||||
updateCmd.Flags().StringVar(&firmwareVersion, "firmware.version", "", "set the version of firmware to be installed")
|
updateCmd.Flags().StringVar(&firmwareVersion, "firmware.version", "", "set the version of firmware to be installed")
|
||||||
updateCmd.Flags().StringVar(&component, "component", "", "set the component to upgrade")
|
updateCmd.Flags().StringVar(&component, "component", "", "set the component to upgrade")
|
||||||
updateCmd.Flags().BoolVar(&status, "status", false, "get the status of the update")
|
updateCmd.Flags().BoolVar(&showStatus, "status", false, "get the status of the update")
|
||||||
|
|
||||||
viper.BindPFlag("update.bmc.host", updateCmd.Flags().Lookup("bmc.host"))
|
viper.BindPFlag("update.bmc.host", updateCmd.Flags().Lookup("bmc.host"))
|
||||||
viper.BindPFlag("update.bmc.port", updateCmd.Flags().Lookup("bmc.port"))
|
viper.BindPFlag("update.bmc.port", updateCmd.Flags().Lookup("bmc.port"))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue