forked from cloudspannerecosystem/wrench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
instance.go
75 lines (59 loc) · 1.32 KB
/
instance.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package cmd
import (
"context"
"github.com/spf13/cobra"
)
var node int32
var instanceCmd = &cobra.Command{
Use: "instance",
}
var instanceCreateCmd = &cobra.Command{
Use: "create",
Short: "Create a instance",
RunE: instanceCreate,
}
func instanceCreate(c *cobra.Command, _ []string) error {
ctx, cancel := context.WithTimeout(c.Context(), timeout)
defer cancel()
client, err := newSpannerAdminClient(ctx, c)
if err != nil {
return err
}
defer client.Close()
err = client.CreateInstance(ctx, node)
if err != nil {
return &Error{
err: err,
cmd: c,
}
}
return nil
}
var instanceDeleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete a instance",
Long: "Delete a instance. This command will delete databases immediately and irrevocably disappear",
RunE: instanceDelete,
}
func instanceDelete(c *cobra.Command, _ []string) error {
ctx, cancel := context.WithTimeout(c.Context(), timeout)
defer cancel()
client, err := newSpannerAdminClient(ctx, c)
if err != nil {
return err
}
defer client.Close()
err = client.DeleteInstance(ctx, instance)
if err != nil {
return &Error{
err: err,
cmd: c,
}
}
return nil
}
func init() {
instanceCreateCmd.Flags().Int32Var(&node, flagNode, 1, "TODO: ")
instanceCmd.AddCommand(instanceCreateCmd)
instanceCmd.AddCommand(instanceDeleteCmd)
}