-
Notifications
You must be signed in to change notification settings - Fork 240
/
restart.go
51 lines (40 loc) · 1.05 KB
/
restart.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package vm
import (
"context"
"fmt"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/client"
"github.com/superfly/flyctl/internal/appconfig"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/flag"
"github.com/superfly/flyctl/iostreams"
)
func newRestart() *cobra.Command {
const (
short = "Restart a VM"
long = "Request for a VM to be asynchronously restarted."
usage = "restart <vm-id>"
)
cmd := command.New(usage, short, long, runRestart,
command.RequireSession,
command.RequireAppName,
)
cmd.Args = cobra.ExactArgs(1)
flag.Add(cmd,
flag.App(),
flag.AppConfig(),
)
return cmd
}
func runRestart(ctx context.Context) (err error) {
var (
io = iostreams.FromContext(ctx)
appName = appconfig.NameFromContext(ctx)
client = client.FromContext(ctx).API()
)
if err := client.RestartAllocation(ctx, appName, flag.FirstArg(ctx)); err != nil {
return fmt.Errorf("failed to restart allocation: %w", err)
}
fmt.Fprintf(io.Out, "VM %s is being restarted\n", flag.FirstArg(ctx))
return
}