Add label support to baremetal power commands
The power commands support interacting with hosts by providing the host document name as an argument. This change adds support for filtering hosts using a labels flag (-l or --labels). This change also adds a name flag to support filtering host documents by name and removes the argument requirement. Change-Id: I54d487a35fb36f26fe8e9931f57bbda25375e714 Signed-off-by: Drew Walters <andrew.walters@att.com>
This commit is contained in:
parent
7ddb858135
commit
ddb43694b9
@ -21,6 +21,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
flagLabel = "labels"
|
||||||
|
flagLabelShort = "l"
|
||||||
|
flagLabelDescription = "Label(s) to filter desired baremetal host documents"
|
||||||
|
|
||||||
|
flagName = "name"
|
||||||
|
flagNameShort = "n"
|
||||||
|
flagNameDescription = "Name to filter desired baremetal host document"
|
||||||
|
|
||||||
flagPhase = "phase"
|
flagPhase = "phase"
|
||||||
flagPhaseDescription = "airshipctl phase that contains the desired baremetal host document(s)"
|
flagPhaseDescription = "airshipctl phase that contains the desired baremetal host document(s)"
|
||||||
)
|
)
|
||||||
|
@ -26,13 +26,16 @@ import (
|
|||||||
|
|
||||||
// NewPowerOffCommand provides a command to shutdown a remote host.
|
// NewPowerOffCommand provides a command to shutdown a remote host.
|
||||||
func NewPowerOffCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
func NewPowerOffCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||||
|
var labels string
|
||||||
|
var name string
|
||||||
var phase string
|
var phase string
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "poweroff BAREMETAL_HOST_DOC_NAME",
|
Use: "poweroff",
|
||||||
Short: "Shutdown a baremetal host",
|
Short: "Shutdown a baremetal host",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.NoArgs,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
m, err := remote.NewManager(rootSettings, phase, remote.ByName(args[0]))
|
m, err := remote.NewManager(rootSettings, phase, remote.ByLabel(labels), remote.ByName(name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -50,6 +53,8 @@ func NewPowerOffCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Com
|
|||||||
}
|
}
|
||||||
|
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
|
flags.StringVarP(&labels, flagLabel, flagLabelShort, "", flagLabelDescription)
|
||||||
|
flags.StringVarP(&name, flagName, flagNameShort, "", flagNameDescription)
|
||||||
flags.StringVar(&phase, flagPhase, config.BootstrapPhase, flagPhaseDescription)
|
flags.StringVar(&phase, flagPhase, config.BootstrapPhase, flagPhaseDescription)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
@ -26,13 +26,16 @@ import (
|
|||||||
|
|
||||||
// NewPowerOnCommand provides a command with the capability to power on baremetal hosts.
|
// NewPowerOnCommand provides a command with the capability to power on baremetal hosts.
|
||||||
func NewPowerOnCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
func NewPowerOnCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||||
|
var labels string
|
||||||
|
var name string
|
||||||
var phase string
|
var phase string
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "poweron BAREMETAL_HOST_DOC_NAME",
|
Use: "poweron",
|
||||||
Short: "Power on a host",
|
Short: "Power on a host",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.NoArgs,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
m, err := remote.NewManager(rootSettings, phase, remote.ByName(args[0]))
|
m, err := remote.NewManager(rootSettings, phase, remote.ByLabel(labels), remote.ByName(name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -42,7 +45,7 @@ func NewPowerOnCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Comm
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(cmd.OutOrStdout(), "Powered on remote host %s\n", args[0])
|
fmt.Fprintf(cmd.OutOrStdout(), "Powered on remote host %s\n", host.HostName)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -50,6 +53,8 @@ func NewPowerOnCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Comm
|
|||||||
}
|
}
|
||||||
|
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
|
flags.StringVarP(&labels, flagLabel, flagLabelShort, "", flagLabelDescription)
|
||||||
|
flags.StringVarP(&name, flagName, flagNameShort, "", flagNameDescription)
|
||||||
flags.StringVar(&phase, flagPhase, config.BootstrapPhase, flagPhaseDescription)
|
flags.StringVar(&phase, flagPhase, config.BootstrapPhase, flagPhaseDescription)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
@ -26,13 +26,16 @@ import (
|
|||||||
|
|
||||||
// NewPowerStatusCommand provides a command to retrieve the power status of a baremetal host.
|
// NewPowerStatusCommand provides a command to retrieve the power status of a baremetal host.
|
||||||
func NewPowerStatusCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
func NewPowerStatusCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||||
|
var labels string
|
||||||
|
var name string
|
||||||
var phase string
|
var phase string
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "powerstatus BAREMETAL_HOST_DOC_NAME",
|
Use: "powerstatus",
|
||||||
Short: "Retrieve the power status of a baremetal host",
|
Short: "Retrieve the power status of a baremetal host",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.NoArgs,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
m, err := remote.NewManager(rootSettings, phase, remote.ByName(args[0]))
|
m, err := remote.NewManager(rootSettings, phase, remote.ByLabel(labels), remote.ByName(name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -52,6 +55,8 @@ func NewPowerStatusCommand(rootSettings *environment.AirshipCTLSettings) *cobra.
|
|||||||
}
|
}
|
||||||
|
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
|
flags.StringVarP(&labels, flagLabel, flagLabelShort, "", flagLabelDescription)
|
||||||
|
flags.StringVarP(&name, flagName, flagNameShort, "", flagNameDescription)
|
||||||
flags.StringVar(&phase, flagPhase, config.BootstrapPhase, flagPhaseDescription)
|
flags.StringVar(&phase, flagPhase, config.BootstrapPhase, flagPhaseDescription)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
@ -26,13 +26,16 @@ import (
|
|||||||
|
|
||||||
// NewRebootCommand provides a command with the capability to reboot baremetal hosts.
|
// NewRebootCommand provides a command with the capability to reboot baremetal hosts.
|
||||||
func NewRebootCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
func NewRebootCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||||
|
var labels string
|
||||||
|
var name string
|
||||||
var phase string
|
var phase string
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "reboot BAREMETAL_HOST_DOC_NAME",
|
Use: "reboot",
|
||||||
Short: "Reboot a host",
|
Short: "Reboot a host",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.NoArgs,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
m, err := remote.NewManager(rootSettings, phase, remote.ByName(args[0]))
|
m, err := remote.NewManager(rootSettings, phase, remote.ByLabel(labels), remote.ByName(name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -50,6 +53,8 @@ func NewRebootCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Comma
|
|||||||
}
|
}
|
||||||
|
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
|
flags.StringVarP(&labels, flagLabel, flagLabelShort, "", flagLabelDescription)
|
||||||
|
flags.StringVarP(&name, flagName, flagNameShort, "", flagNameDescription)
|
||||||
flags.StringVar(&phase, flagPhase, config.BootstrapPhase, flagPhaseDescription)
|
flags.StringVar(&phase, flagPhase, config.BootstrapPhase, flagPhaseDescription)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
Shutdown a baremetal host
|
Shutdown a baremetal host
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
poweroff BAREMETAL_HOST_DOC_NAME [flags]
|
poweroff [flags]
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
-h, --help help for poweroff
|
-h, --help help for poweroff
|
||||||
|
-l, --labels string Label(s) to filter desired baremetal host documents
|
||||||
|
-n, --name string Name to filter desired baremetal host document
|
||||||
--phase string airshipctl phase that contains the desired baremetal host document(s) (default "bootstrap")
|
--phase string airshipctl phase that contains the desired baremetal host document(s) (default "bootstrap")
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
Power on a host
|
Power on a host
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
poweron BAREMETAL_HOST_DOC_NAME [flags]
|
poweron [flags]
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
-h, --help help for poweron
|
-h, --help help for poweron
|
||||||
|
-l, --labels string Label(s) to filter desired baremetal host documents
|
||||||
|
-n, --name string Name to filter desired baremetal host document
|
||||||
--phase string airshipctl phase that contains the desired baremetal host document(s) (default "bootstrap")
|
--phase string airshipctl phase that contains the desired baremetal host document(s) (default "bootstrap")
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
Retrieve the power status of a baremetal host
|
Retrieve the power status of a baremetal host
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
powerstatus BAREMETAL_HOST_DOC_NAME [flags]
|
powerstatus [flags]
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
-h, --help help for powerstatus
|
-h, --help help for powerstatus
|
||||||
|
-l, --labels string Label(s) to filter desired baremetal host documents
|
||||||
|
-n, --name string Name to filter desired baremetal host document
|
||||||
--phase string airshipctl phase that contains the desired baremetal host document(s) (default "bootstrap")
|
--phase string airshipctl phase that contains the desired baremetal host document(s) (default "bootstrap")
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
Reboot a host
|
Reboot a host
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
reboot BAREMETAL_HOST_DOC_NAME [flags]
|
reboot [flags]
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
-h, --help help for reboot
|
-h, --help help for reboot
|
||||||
|
-l, --labels string Label(s) to filter desired baremetal host documents
|
||||||
|
-n, --name string Name to filter desired baremetal host document
|
||||||
--phase string airshipctl phase that contains the desired baremetal host document(s) (default "bootstrap")
|
--phase string airshipctl phase that contains the desired baremetal host document(s) (default "bootstrap")
|
||||||
|
Loading…
Reference in New Issue
Block a user