Merge "Move remote cmd functionality to baremetal cmd"
This commit is contained in:
commit
3d10e1cde1
|
@ -20,6 +20,11 @@ import (
|
|||
"opendev.org/airship/airshipctl/pkg/environment"
|
||||
)
|
||||
|
||||
const (
|
||||
flagPhase = "phase"
|
||||
flagPhaseDescription = "airshipctl phase that contains the desired baremetal host document(s)"
|
||||
)
|
||||
|
||||
// NewBaremetalCommand creates a new command for interacting with baremetal using airshipctl.
|
||||
func NewBaremetalCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
|
@ -30,6 +35,15 @@ func NewBaremetalCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Co
|
|||
isoGenCmd := NewISOGenCommand(rootSettings)
|
||||
cmd.AddCommand(isoGenCmd)
|
||||
|
||||
powerOffCmd := NewPowerOffCommand(rootSettings)
|
||||
cmd.AddCommand(powerOffCmd)
|
||||
|
||||
powerStatusCmd := NewPowerStatusCommand(rootSettings)
|
||||
cmd.AddCommand(powerStatusCmd)
|
||||
|
||||
rebootCmd := NewRebootCommand(rootSettings)
|
||||
cmd.AddCommand(rebootCmd)
|
||||
|
||||
remoteDirectCmd := NewRemoteDirectCommand(rootSettings)
|
||||
cmd.AddCommand(remoteDirectCmd)
|
||||
|
||||
|
|
|
@ -33,6 +33,21 @@ func TestBaremetal(t *testing.T) {
|
|||
CmdLine: "-h",
|
||||
Cmd: baremetal.NewISOGenCommand(nil),
|
||||
},
|
||||
{
|
||||
Name: "baremetal-poweroff-with-help",
|
||||
CmdLine: "-h",
|
||||
Cmd: baremetal.NewPowerOffCommand(nil),
|
||||
},
|
||||
{
|
||||
Name: "baremetal-powerstatus-with-help",
|
||||
CmdLine: "-h",
|
||||
Cmd: baremetal.NewPowerStatusCommand(nil),
|
||||
},
|
||||
{
|
||||
Name: "baremetal-reboot-with-help",
|
||||
CmdLine: "-h",
|
||||
Cmd: baremetal.NewRebootCommand(nil),
|
||||
},
|
||||
{
|
||||
Name: "baremetal-remotedirect-with-help",
|
||||
CmdLine: "-h",
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package remote
|
||||
package baremetal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -28,8 +28,8 @@ import (
|
|||
func NewPowerOffCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
var phase string
|
||||
cmd := &cobra.Command{
|
||||
Use: "poweroff SYSTEM_ID",
|
||||
Short: "Shutdown a host",
|
||||
Use: "poweroff BAREMETAL_HOST_DOC_NAME",
|
||||
Short: "Shutdown a baremetal host",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
m, err := remote.NewManager(rootSettings, phase, remote.ByName(args[0]))
|
||||
|
@ -42,7 +42,7 @@ func NewPowerOffCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Com
|
|||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(cmd.OutOrStdout(), "Remote host %s powered off\n", args[0])
|
||||
fmt.Fprintf(cmd.OutOrStdout(), "Remote host %s powered off\n", host.HostName)
|
||||
}
|
||||
|
||||
return nil
|
|
@ -12,7 +12,7 @@
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package remote
|
||||
package baremetal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -24,12 +24,12 @@ import (
|
|||
"opendev.org/airship/airshipctl/pkg/remote"
|
||||
)
|
||||
|
||||
// NewPowerStatusCommand provides a command to retrieve the power status of a remote host.
|
||||
// NewPowerStatusCommand provides a command to retrieve the power status of a baremetal host.
|
||||
func NewPowerStatusCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
var phase string
|
||||
cmd := &cobra.Command{
|
||||
Use: "powerstatus SYSTEM_ID",
|
||||
Short: "Retrieve the power status of a host",
|
||||
Use: "powerstatus BAREMETAL_HOST_DOC_NAME",
|
||||
Short: "Retrieve the power status of a baremetal host",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
m, err := remote.NewManager(rootSettings, phase, remote.ByName(args[0]))
|
||||
|
@ -43,7 +43,7 @@ func NewPowerStatusCommand(rootSettings *environment.AirshipCTLSettings) *cobra.
|
|||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(cmd.OutOrStdout(), "Remote host %s has power status: %s\n", args[0],
|
||||
fmt.Fprintf(cmd.OutOrStdout(), "Remote host %s has power status: %s\n", host.HostName,
|
||||
powerStatus)
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package remote
|
||||
package baremetal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -24,11 +24,11 @@ import (
|
|||
"opendev.org/airship/airshipctl/pkg/remote"
|
||||
)
|
||||
|
||||
// NewRebootCommand provides a command with the capability to reboot hosts.
|
||||
// NewRebootCommand provides a command with the capability to reboot baremetal hosts.
|
||||
func NewRebootCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
var phase string
|
||||
cmd := &cobra.Command{
|
||||
Use: "reboot SYSTEM_ID",
|
||||
Use: "reboot BAREMETAL_HOST_DOC_NAME",
|
||||
Short: "Reboot a host",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
@ -42,7 +42,7 @@ func NewRebootCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Comma
|
|||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(cmd.OutOrStdout(), "Rebooted remote host %s\n", args[0])
|
||||
fmt.Fprintf(cmd.OutOrStdout(), "Rebooted remote host at %s\n", host.HostName)
|
||||
}
|
||||
|
||||
return nil
|
8
cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-poweroff-with-help.golden
vendored
Normal file
8
cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-poweroff-with-help.golden
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
Shutdown a baremetal host
|
||||
|
||||
Usage:
|
||||
poweroff BAREMETAL_HOST_DOC_NAME [flags]
|
||||
|
||||
Flags:
|
||||
-h, --help help for poweroff
|
||||
--phase string airshipctl phase that contains the desired baremetal host document(s) (default "bootstrap")
|
8
cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-powerstatus-with-help.golden
vendored
Normal file
8
cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-powerstatus-with-help.golden
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
Retrieve the power status of a baremetal host
|
||||
|
||||
Usage:
|
||||
powerstatus BAREMETAL_HOST_DOC_NAME [flags]
|
||||
|
||||
Flags:
|
||||
-h, --help help for powerstatus
|
||||
--phase string airshipctl phase that contains the desired baremetal host document(s) (default "bootstrap")
|
8
cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-reboot-with-help.golden
vendored
Normal file
8
cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-reboot-with-help.golden
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
Reboot a host
|
||||
|
||||
Usage:
|
||||
reboot BAREMETAL_HOST_DOC_NAME [flags]
|
||||
|
||||
Flags:
|
||||
-h, --help help for reboot
|
||||
--phase string airshipctl phase that contains the desired baremetal host document(s) (default "bootstrap")
|
|
@ -6,6 +6,9 @@ Usage:
|
|||
Available Commands:
|
||||
help Help about any command
|
||||
isogen Generate baremetal host ISO image
|
||||
poweroff Shutdown a baremetal host
|
||||
powerstatus Retrieve the power status of a baremetal host
|
||||
reboot Reboot a host
|
||||
remotedirect Bootstrap the ephemeral host
|
||||
|
||||
Flags:
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
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 remote
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"opendev.org/airship/airshipctl/pkg/environment"
|
||||
)
|
||||
|
||||
const (
|
||||
flagPhase = "phase"
|
||||
flagPhaseDescription = "airshipctl phase that contains the desired baremetal host document(s)"
|
||||
)
|
||||
|
||||
// NewRemoteCommand creates a new command that provides functionality to control remote entities.
|
||||
func NewRemoteCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
remoteRootCmd := &cobra.Command{
|
||||
Use: "remote",
|
||||
Short: "Control remote entities, i.e. hosts.",
|
||||
}
|
||||
|
||||
powerOffCmd := NewPowerOffCommand(rootSettings)
|
||||
remoteRootCmd.AddCommand(powerOffCmd)
|
||||
|
||||
powerStatusCmd := NewPowerStatusCommand(rootSettings)
|
||||
remoteRootCmd.AddCommand(powerStatusCmd)
|
||||
|
||||
rebootCmd := NewRebootCommand(rootSettings)
|
||||
remoteRootCmd.AddCommand(rebootCmd)
|
||||
|
||||
return remoteRootCmd
|
||||
}
|
|
@ -27,7 +27,6 @@ import (
|
|||
"opendev.org/airship/airshipctl/cmd/completion"
|
||||
"opendev.org/airship/airshipctl/cmd/config"
|
||||
"opendev.org/airship/airshipctl/cmd/document"
|
||||
"opendev.org/airship/airshipctl/cmd/remote"
|
||||
"opendev.org/airship/airshipctl/cmd/secret"
|
||||
"opendev.org/airship/airshipctl/pkg/environment"
|
||||
"opendev.org/airship/airshipctl/pkg/log"
|
||||
|
@ -71,7 +70,6 @@ func AddDefaultAirshipCTLCommands(cmd *cobra.Command, settings *environment.Airs
|
|||
cmd.AddCommand(completion.NewCompletionCommand())
|
||||
cmd.AddCommand(document.NewDocumentCommand(settings))
|
||||
cmd.AddCommand(config.NewConfigCommand(settings))
|
||||
cmd.AddCommand(remote.NewRemoteCommand(settings))
|
||||
cmd.AddCommand(secret.NewSecretCommand())
|
||||
|
||||
return cmd
|
||||
|
|
|
@ -10,7 +10,6 @@ Available Commands:
|
|||
config Manage the airshipctl config file
|
||||
document Manage deployment documents
|
||||
help Help about any command
|
||||
remote Control remote entities, i.e. hosts.
|
||||
secret Manage secrets
|
||||
version Show the version number of airshipctl
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ type baremetalHost struct {
|
|||
Client
|
||||
Context context.Context
|
||||
BMCAddress string
|
||||
HostName string
|
||||
username string
|
||||
password string
|
||||
}
|
||||
|
@ -176,7 +177,7 @@ func newBaremetalHost(mgmtCfg config.ManagementConfiguration,
|
|||
return host, err
|
||||
}
|
||||
|
||||
host = baremetalHost{client, ctx, address, username, password}
|
||||
host = baremetalHost{client, ctx, address, hostDoc.GetName(), username, password}
|
||||
default:
|
||||
return host, ErrUnknownManagementType{Type: mgmtCfg.Type}
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ func TestDoRemoteDirectMissingConfigOpts(t *testing.T) {
|
|||
rMock,
|
||||
ctx,
|
||||
redfishURL,
|
||||
"doc-name",
|
||||
username,
|
||||
password,
|
||||
}
|
||||
|
@ -73,6 +74,7 @@ func TestDoRemoteDirectMissingISOURL(t *testing.T) {
|
|||
rMock,
|
||||
ctx,
|
||||
redfishURL,
|
||||
"doc-name",
|
||||
username,
|
||||
password,
|
||||
}
|
||||
|
@ -98,6 +100,7 @@ func TestDoRemoteDirectRedfish(t *testing.T) {
|
|||
rMock,
|
||||
ctx,
|
||||
redfishURL,
|
||||
"doc-name",
|
||||
username,
|
||||
password,
|
||||
}
|
||||
|
@ -127,6 +130,7 @@ func TestDoRemoteDirectRedfishVirtualMediaError(t *testing.T) {
|
|||
rMock,
|
||||
ctx,
|
||||
redfishURL,
|
||||
"doc-name",
|
||||
username,
|
||||
password,
|
||||
}
|
||||
|
@ -158,6 +162,7 @@ func TestDoRemoteDirectRedfishBootSourceError(t *testing.T) {
|
|||
rMock,
|
||||
ctx,
|
||||
redfishURL,
|
||||
"doc-name",
|
||||
username,
|
||||
password,
|
||||
}
|
||||
|
@ -190,6 +195,7 @@ func TestDoRemoteDirectRedfishRebootError(t *testing.T) {
|
|||
rMock,
|
||||
ctx,
|
||||
redfishURL,
|
||||
"doc-name",
|
||||
username,
|
||||
password,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue