Merge "Add baremetal host poweron command"
This commit is contained in:
commit
90265072d1
@ -38,6 +38,9 @@ func NewBaremetalCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Co
|
||||
powerOffCmd := NewPowerOffCommand(rootSettings)
|
||||
cmd.AddCommand(powerOffCmd)
|
||||
|
||||
powerOnCmd := NewPowerOnCommand(rootSettings)
|
||||
cmd.AddCommand(powerOnCmd)
|
||||
|
||||
powerStatusCmd := NewPowerStatusCommand(rootSettings)
|
||||
cmd.AddCommand(powerStatusCmd)
|
||||
|
||||
|
@ -38,6 +38,11 @@ func TestBaremetal(t *testing.T) {
|
||||
CmdLine: "-h",
|
||||
Cmd: baremetal.NewPowerOffCommand(nil),
|
||||
},
|
||||
{
|
||||
Name: "baremetal-poweron-with-help",
|
||||
CmdLine: "-h",
|
||||
Cmd: baremetal.NewPowerOnCommand(nil),
|
||||
},
|
||||
{
|
||||
Name: "baremetal-powerstatus-with-help",
|
||||
CmdLine: "-h",
|
||||
|
56
cmd/baremetal/poweron.go
Normal file
56
cmd/baremetal/poweron.go
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package baremetal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"opendev.org/airship/airshipctl/pkg/config"
|
||||
"opendev.org/airship/airshipctl/pkg/environment"
|
||||
"opendev.org/airship/airshipctl/pkg/remote"
|
||||
)
|
||||
|
||||
// NewPowerOnCommand provides a command with the capability to power on baremetal hosts.
|
||||
func NewPowerOnCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
var phase string
|
||||
cmd := &cobra.Command{
|
||||
Use: "poweron BAREMETAL_HOST_DOC_NAME",
|
||||
Short: "Power on a host",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
m, err := remote.NewManager(rootSettings, phase, remote.ByName(args[0]))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, host := range m.Hosts {
|
||||
if err := host.SystemPowerOn(host.Context); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(cmd.OutOrStdout(), "Powered on remote host %s\n", args[0])
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
flags := cmd.Flags()
|
||||
flags.StringVar(&phase, flagPhase, config.BootstrapPhase, flagPhaseDescription)
|
||||
|
||||
return cmd
|
||||
}
|
8
cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-poweron-with-help.golden
vendored
Normal file
8
cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-poweron-with-help.golden
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
Power on a host
|
||||
|
||||
Usage:
|
||||
poweron BAREMETAL_HOST_DOC_NAME [flags]
|
||||
|
||||
Flags:
|
||||
-h, --help help for poweron
|
||||
--phase string airshipctl phase that contains the desired baremetal host document(s) (default "bootstrap")
|
@ -7,6 +7,7 @@ Available Commands:
|
||||
help Help about any command
|
||||
isogen Generate baremetal host ISO image
|
||||
poweroff Shutdown a baremetal host
|
||||
poweron Power on a host
|
||||
powerstatus Retrieve the power status of a baremetal host
|
||||
reboot Reboot a host
|
||||
remotedirect Bootstrap the ephemeral host
|
||||
|
@ -28,8 +28,8 @@ import (
|
||||
// functions within client are used by power management commands and remote direct functionality.
|
||||
type Client interface {
|
||||
RebootSystem(context.Context) error
|
||||
|
||||
SystemPowerOff(context.Context) error
|
||||
SystemPowerOn(context.Context) error
|
||||
|
||||
// TODO(drewwalters96): Should this be a string forever? We may want to define our own custom type, as the
|
||||
// string format will be client dependent when we add new clients.
|
||||
|
@ -200,6 +200,16 @@ func (c *Client) SystemPowerOff(ctx context.Context) error {
|
||||
return ScreenRedfishError(httpResp, err)
|
||||
}
|
||||
|
||||
// SystemPowerOn powers on a host.
|
||||
func (c *Client) SystemPowerOn(ctx context.Context) error {
|
||||
resetReq := redfishClient.ResetRequestBody{}
|
||||
resetReq.ResetType = redfishClient.RESETTYPE_ON
|
||||
|
||||
_, httpResp, err := c.RedfishAPI.ResetSystem(ctx, c.nodeID, resetReq)
|
||||
|
||||
return ScreenRedfishError(httpResp, err)
|
||||
}
|
||||
|
||||
// SystemPowerStatus retrieves the power status of a host as a human-readable string.
|
||||
func (c *Client) SystemPowerStatus(ctx context.Context) (string, error) {
|
||||
computerSystem, httpResp, err := c.RedfishAPI.GetSystem(ctx, c.nodeID)
|
||||
|
@ -92,6 +92,19 @@ func (m *MockClient) SystemPowerOff(ctx context.Context) error {
|
||||
return args.Error(0)
|
||||
}
|
||||
|
||||
// SystemPowerOn provides a stubbed method that can be mocked to test functions that use the
|
||||
// Redfish client without making any Redfish API calls or requiring the appropriate Redfish client settings.
|
||||
//
|
||||
// Example usage:
|
||||
// client := redfishutils.NewClient()
|
||||
// client.On("SystemPowerOn").Return(<return values>)
|
||||
//
|
||||
// err := client.SystemPowerOn(<args>)
|
||||
func (m *MockClient) SystemPowerOn(ctx context.Context) error {
|
||||
args := m.Called(ctx)
|
||||
return args.Error(0)
|
||||
}
|
||||
|
||||
// SystemPowerStatus provides a stubbed method that can be mocked to test functions that use the
|
||||
// Redfish client without making any Redfish API calls or requiring the appropriate Redfish client settings.
|
||||
//
|
||||
|
Loading…
x
Reference in New Issue
Block a user