mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 11:37:01 -07:00
feat: add --insecure flag to allow insecure connections for firmware updates
This commit is contained in:
parent
03bf2250a4
commit
b31ed136f6
2 changed files with 27 additions and 21 deletions
|
|
@ -17,18 +17,19 @@ var (
|
||||||
component string
|
component string
|
||||||
transferProtocol string
|
transferProtocol string
|
||||||
showStatus bool
|
showStatus bool
|
||||||
|
Insecure 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 hosts...",
|
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\n" +
|
Long: "Perform an firmware update using Redfish by providing a remote firmware URL and component.\n\n" +
|
||||||
"Examples:\n" +
|
"Examples:\n" +
|
||||||
" magellan update 172.16.0.108:443 --username bmc_username --password bmc_password --firmware-url http://172.16.0.200:8005/firmware/bios/image.RBU --component BIOS\n" +
|
" magellan update 172.16.0.108:443 --insecure --username bmc_username --password bmc_password --firmware-url http://172.16.0.200:8005/firmware/bios/image.RBU --component BIOS\n" +
|
||||||
" magellan update 172.16.0.108:443 --status --username bmc_username --password bmc_password",
|
" magellan update 172.16.0.108:443 --insecure --status --username bmc_username --password bmc_password",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
// check that we have at least one host
|
// check that we have at least one host
|
||||||
if len(args) <= 0 {
|
if len(args) <= 0 {
|
||||||
|
|
@ -44,6 +45,7 @@ var UpdateCmd = &cobra.Command{
|
||||||
FirmwareVersion: firmwareVersion,
|
FirmwareVersion: firmwareVersion,
|
||||||
Component: component,
|
Component: component,
|
||||||
TransferProtocol: transferProtocol,
|
TransferProtocol: transferProtocol,
|
||||||
|
Insecure: Insecure,
|
||||||
CollectParams: magellan.CollectParams{
|
CollectParams: magellan.CollectParams{
|
||||||
URI: arg,
|
URI: arg,
|
||||||
Username: username,
|
Username: username,
|
||||||
|
|
@ -63,6 +65,7 @@ var UpdateCmd = &cobra.Command{
|
||||||
FirmwareVersion: firmwareVersion,
|
FirmwareVersion: firmwareVersion,
|
||||||
Component: component,
|
Component: component,
|
||||||
TransferProtocol: strings.ToUpper(transferProtocol),
|
TransferProtocol: strings.ToUpper(transferProtocol),
|
||||||
|
Insecure: Insecure,
|
||||||
CollectParams: magellan.CollectParams{
|
CollectParams: magellan.CollectParams{
|
||||||
URI: host,
|
URI: host,
|
||||||
Username: username,
|
Username: username,
|
||||||
|
|
@ -78,21 +81,23 @@ var UpdateCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
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, "scheme", "https", "Set the transfer protocol")
|
updateCmd.Flags().StringVar(&transferProtocol, "scheme", "https", "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 (BMC|BIOS)")
|
updateCmd.Flags().StringVar(&component, "component", "", "Set the component to upgrade (BMC|BIOS)")
|
||||||
UpdateCmd.Flags().BoolVar(&showStatus, "status", false, "Get the status of the update")
|
updateCmd.Flags().BoolVar(&showStatus, "status", false, "Get the status of the update")
|
||||||
|
updateCmd.Flags().BoolVar(&Insecure, "insecure", false, "Allow insecure connections to the server")
|
||||||
|
|
||||||
checkBindFlagError(viper.BindPFlag("update.username", UpdateCmd.Flags().Lookup("username")))
|
checkBindFlagError(viper.BindPFlag("update.username", updateCmd.Flags().Lookup("username")))
|
||||||
checkBindFlagError(viper.BindPFlag("update.password", UpdateCmd.Flags().Lookup("password")))
|
checkBindFlagError(viper.BindPFlag("update.password", updateCmd.Flags().Lookup("password")))
|
||||||
checkBindFlagError(viper.BindPFlag("update.scheme", UpdateCmd.Flags().Lookup("scheme")))
|
checkBindFlagError(viper.BindPFlag("update.scheme", updateCmd.Flags().Lookup("scheme")))
|
||||||
checkBindFlagError(viper.BindPFlag("update.firmware-url", UpdateCmd.Flags().Lookup("firmware-url")))
|
checkBindFlagError(viper.BindPFlag("update.firmware-url", updateCmd.Flags().Lookup("firmware-url")))
|
||||||
checkBindFlagError(viper.BindPFlag("update.firmware-version", UpdateCmd.Flags().Lookup("firmware-version")))
|
checkBindFlagError(viper.BindPFlag("update.firmware-version", updateCmd.Flags().Lookup("firmware-version")))
|
||||||
checkBindFlagError(viper.BindPFlag("update.component", UpdateCmd.Flags().Lookup("component")))
|
checkBindFlagError(viper.BindPFlag("update.component", updateCmd.Flags().Lookup("component")))
|
||||||
checkBindFlagError(viper.BindPFlag("update.status", UpdateCmd.Flags().Lookup("status")))
|
checkBindFlagError(viper.BindPFlag("update.status", updateCmd.Flags().Lookup("status")))
|
||||||
|
checkBindFlagError(viper.BindPFlag("update.insecure", updateCmd.Flags().Lookup("insecure")))
|
||||||
|
|
||||||
rootCmd.AddCommand(UpdateCmd)
|
rootCmd.AddCommand(UpdateCmd)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ type UpdateParams struct {
|
||||||
FirmwareVersion string
|
FirmwareVersion string
|
||||||
Component string
|
Component string
|
||||||
TransferProtocol string
|
TransferProtocol string
|
||||||
|
Insecure bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateFirmwareRemote() uses 'gofish' to update the firmware of a BMC node.
|
// UpdateFirmwareRemote() uses 'gofish' to update the firmware of a BMC node.
|
||||||
|
|
@ -35,8 +36,8 @@ 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)
|
// Connect to the Redfish service using gofish
|
||||||
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: q.Insecure})
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
@ -70,8 +71,8 @@ func GetUpdateStatus(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)
|
// Connect to the Redfish service using gofish
|
||||||
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: q.Insecure})
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue