instance_pause: Add buttons to start/stop instance
This commit is contained in:
parent
092304f891
commit
1f7d92bea8
4 changed files with 67 additions and 0 deletions
47
cmd/instance_pause.go
Normal file
47
cmd/instance_pause.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/cli"
|
||||
)
|
||||
|
||||
// InstancePause is the 'instance_pause' command
|
||||
var InstancePause wisski_distillery.Command = instancepause{}
|
||||
|
||||
type instancepause struct {
|
||||
Stop bool `short:"d" long:"stop" description:"stop instance"`
|
||||
Start bool `short:"u" long:"start" description:"start (or restart) instance"`
|
||||
Positionals struct {
|
||||
Slug string `positional-arg-name:"slug" required:"1-1" description:"name of instance to purge"`
|
||||
} `positional-args:"true"`
|
||||
}
|
||||
|
||||
func (instancepause) Description() wisski_distillery.Description {
|
||||
return wisski_distillery.Description{
|
||||
Requirements: cli.Requirements{
|
||||
NeedsDistillery: true,
|
||||
},
|
||||
Command: "instance_pause",
|
||||
Description: "stops or starts a single instance",
|
||||
}
|
||||
}
|
||||
|
||||
func (i instancepause) AfterParse() error {
|
||||
if i.Stop == i.Start {
|
||||
return errStopStartExcluded
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i instancepause) Run(context wisski_distillery.Context) error {
|
||||
instance, err := context.Environment.Instances().WissKI(context.Context, i.Positionals.Slug)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if i.Stop {
|
||||
return instance.Barrel().Stack().Down(context.Context, context.Stdout)
|
||||
} else {
|
||||
return instance.Barrel().Stack().Up(context.Context, context.Stdout)
|
||||
}
|
||||
}
|
||||
|
|
@ -39,6 +39,7 @@ func init() {
|
|||
wdcli.Register(cmd.Ls)
|
||||
wdcli.Register(cmd.Info)
|
||||
wdcli.Register(cmd.InstanceLock)
|
||||
wdcli.Register(cmd.InstancePause)
|
||||
|
||||
// instance tasks
|
||||
wdcli.Register(cmd.Shell)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue