github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/cmd/orbctl/reboot.go (about)

     1  package main
     2  
     3  import (
     4  	"errors"
     5  
     6  	"github.com/caos/orbos/mntr"
     7  
     8  	"github.com/caos/orbos/internal/operator/orbiter/kinds/clusters/core/infra"
     9  
    10  	"github.com/spf13/cobra"
    11  )
    12  
    13  func RebootCommand(getRv GetRootValues) *cobra.Command {
    14  	return &cobra.Command{
    15  		Use:   "reboot [<provider>.<pool>.<machine>] [<provider>.<pool>.<machine>]",
    16  		Short: "Gracefully reboot machines",
    17  		Long:  "Pass machine ids as arguments, omit arguments for selecting machines interactively",
    18  		Args:  cobra.MinimumNArgs(1),
    19  		RunE: func(cmd *cobra.Command, args []string) (err error) {
    20  
    21  			node := ""
    22  			if len(args) > 0 {
    23  				node = args[0]
    24  			}
    25  
    26  			rv := getRv("reboot", "", map[string]interface{}{"node": node})
    27  			defer rv.ErrFunc(err)
    28  
    29  			if !rv.Gitops {
    30  				return mntr.ToUserError(errors.New("reboot command is only supported with the --gitops flag and a committed orbiter.yml"))
    31  			}
    32  
    33  			return requireMachines(monitor, rv.GitClient, rv.OrbConfig, args, func(machine infra.Machine) (required bool, require func(), unrequire func()) {
    34  				return machine.RebootRequired()
    35  			})
    36  		},
    37  	}
    38  }