/
destroy.go
50 lines (40 loc) · 1.08 KB
/
destroy.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
package cmd
import (
log "github.com/Sirupsen/logrus"
"github.com/axsh/openvdc/cmd/openvdc/internal/util"
"github.com/axsh/openvdc/api"
"github.com/spf13/cobra"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
func init() {
destroyCmd.Flags().Bool("force", false, "Force destroy instance, ignoring states")
}
var destroyCmd = &cobra.Command{
Use: "destroy [Instance ID] [flags]",
Short: "Destroy an instance",
Long: "Destroy an already existing instance.",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
log.Fatal("Please provide an instance ID")
}
instanceID := args[0]
force, err := cmd.Flags().GetBool("force")
if err != nil {
log.WithError(err).Fatal("Failed getting flag")
}
req := &api.DestroyRequest{
InstanceId: instanceID,
Force: force,
}
return util.RemoteCall(func(conn *grpc.ClientConn) error {
c := api.NewInstanceClient(conn)
_, err := c.Destroy(context.Background(), req)
if err != nil {
log.WithError(err).Fatal("Disconnected abnormally")
return err
}
return err
})
},
}