diff --git a/cmd/baremetal/baremetal.go b/cmd/baremetal/baremetal.go index 4d88ec4ad..a6f2117fc 100644 --- a/cmd/baremetal/baremetal.go +++ b/cmd/baremetal/baremetal.go @@ -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) diff --git a/cmd/baremetal/baremetal_test.go b/cmd/baremetal/baremetal_test.go index 9753172d0..6b03dd1da 100644 --- a/cmd/baremetal/baremetal_test.go +++ b/cmd/baremetal/baremetal_test.go @@ -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", diff --git a/cmd/remote/remote_power_off.go b/cmd/baremetal/poweroff.go similarity index 92% rename from cmd/remote/remote_power_off.go rename to cmd/baremetal/poweroff.go index c11dd3650..48643d362 100644 --- a/cmd/remote/remote_power_off.go +++ b/cmd/baremetal/poweroff.go @@ -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 diff --git a/cmd/remote/remote_power_status.go b/cmd/baremetal/powerstatus.go similarity index 89% rename from cmd/remote/remote_power_status.go rename to cmd/baremetal/powerstatus.go index f6ec2c754..d6e9dc52d 100644 --- a/cmd/remote/remote_power_status.go +++ b/cmd/baremetal/powerstatus.go @@ -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) } diff --git a/cmd/remote/remote_reboot.go b/cmd/baremetal/reboot.go similarity index 89% rename from cmd/remote/remote_reboot.go rename to cmd/baremetal/reboot.go index d2cd0506a..a271099bd 100644 --- a/cmd/remote/remote_reboot.go +++ b/cmd/baremetal/reboot.go @@ -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 diff --git a/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-poweroff-with-help.golden b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-poweroff-with-help.golden new file mode 100644 index 000000000..ebb3c13ef --- /dev/null +++ b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-poweroff-with-help.golden @@ -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") diff --git a/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-powerstatus-with-help.golden b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-powerstatus-with-help.golden new file mode 100644 index 000000000..149b13476 --- /dev/null +++ b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-powerstatus-with-help.golden @@ -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") diff --git a/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-reboot-with-help.golden b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-reboot-with-help.golden new file mode 100644 index 000000000..bd7c5c678 --- /dev/null +++ b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-reboot-with-help.golden @@ -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") diff --git a/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-with-help.golden b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-with-help.golden index 5d05060d9..7d2281fd2 100644 --- a/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-with-help.golden +++ b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-with-help.golden @@ -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: diff --git a/cmd/remote/remote.go b/cmd/remote/remote.go deleted file mode 100644 index 396378d42..000000000 --- a/cmd/remote/remote.go +++ /dev/null @@ -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 -} diff --git a/cmd/root.go b/cmd/root.go index 7beb31cdc..5c4912470 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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 diff --git a/cmd/testdata/TestRootGoldenOutput/rootCmd-with-default-subcommands.golden b/cmd/testdata/TestRootGoldenOutput/rootCmd-with-default-subcommands.golden index 366db5b2a..bf4ce9d0c 100644 --- a/cmd/testdata/TestRootGoldenOutput/rootCmd-with-default-subcommands.golden +++ b/cmd/testdata/TestRootGoldenOutput/rootCmd-with-default-subcommands.golden @@ -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 diff --git a/pkg/remote/management.go b/pkg/remote/management.go index 358f2b3c2..766ed54dc 100644 --- a/pkg/remote/management.go +++ b/pkg/remote/management.go @@ -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} } diff --git a/pkg/remote/remote_direct_test.go b/pkg/remote/remote_direct_test.go index 1320b6335..914686ba5 100644 --- a/pkg/remote/remote_direct_test.go +++ b/pkg/remote/remote_direct_test.go @@ -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, }