-
Notifications
You must be signed in to change notification settings - Fork 235
/
vm.go
51 lines (38 loc) · 1.3 KB
/
vm.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 cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/cmdctx"
"github.com/superfly/flyctl/docstrings"
"github.com/superfly/flyctl/internal/client"
)
func newVMCommand(client *client.Client) *Command {
vmCmd := BuildCommandKS(nil, nil, docstrings.Get("vm"), client)
vmRestartCmd := BuildCommandKS(vmCmd, runVMRestart, docstrings.Get("vm.restart"), client, requireSession, requireAppName)
vmRestartCmd.Args = cobra.ExactArgs(1)
vmStopCmd := BuildCommandKS(vmCmd, runVMStop, docstrings.Get("vm.stop"), client, requireSession, requireAppName)
vmStopCmd.Args = cobra.ExactArgs(1)
vmStatusCmd := BuildCommandKS(vmCmd, runAllocStatus, docstrings.Get("vm.status"), client, requireSession, requireAppName)
vmStatusCmd.Args = cobra.ExactArgs(1)
return vmCmd
}
func runVMRestart(cmdctx *cmdctx.CmdContext) error {
appName := cmdctx.AppName
allocID := cmdctx.Args[0]
err := cmdctx.Client.API().RestartAllocation(appName, allocID)
if err != nil {
return err
}
fmt.Printf("VM %s is being restarted\n", allocID)
return nil
}
func runVMStop(cmdctx *cmdctx.CmdContext) error {
appName := cmdctx.AppName
allocID := cmdctx.Args[0]
err := cmdctx.Client.API().StopAllocation(appName, allocID)
if err != nil {
return err
}
fmt.Printf("VM %s is being stopped\n", allocID)
return nil
}