/
main.go
193 lines (183 loc) · 4.45 KB
/
main.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package main
import (
"log"
"os"
"github.com/olekukonko/tablewriter"
nutanix "github.com/routebyintuition/ntnx-go-sdk"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v2/altsrc"
)
// NCLI is the baseline type to house SDK/connection config
type NCLI struct {
con *nutanix.Client
tr *tablewriter.Table
}
// BCLI (base CLI) is used for non-API calls but allows the table writer setup
type BCLI struct {
tr *tablewriter.Table
}
func main() {
ncli := &NCLI{}
ncli.tr = tablewriter.NewWriter(os.Stdout)
bcli := &BCLI{}
bcli.tr = tablewriter.NewWriter(os.Stdout)
flags := getFlags()
app := &cli.App{
Name: "Unikum und Wunderbar Nutanix CLI",
Usage: "uwncli [flags] [command] [subcommand]",
EnableBashCompletion: true,
Before: altsrc.InitInputSourceWithContext(flags, NewYamlSourceFromProfileFunc("profile")),
Flags: flags,
Commands: []*cli.Command{
{
Name: "configure",
Aliases: []string{"conf"},
Usage: "configure stored credentials",
Action: bcli.configureDefaultProfile,
},
{
Name: "profile",
Usage: "stored profile specific commands. use `uwncli profile help` to view options",
Subcommands: []*cli.Command{
{
Name: "list",
Usage: "list all stored profiles",
Action: bcli.listProfiles,
},
{
Name: "delete",
Usage: "uwncli delete <profile name>",
Action: bcli.deleteProfile,
},
{
Name: "create",
Usage: "create a new profile",
Action: bcli.createProfile,
},
},
},
{
Before: func(c *cli.Context) error {
var err error
ncli.con, err = setupConnection(c)
return err
},
Name: "vm",
Usage: "virtual machine specific commands. use `uwncli vm help` to view options",
Subcommands: []*cli.Command{
{
Name: "list",
Usage: "retrieve all VMs",
Action: ncli.vmList,
Category: "get",
},
{
Name: "get",
Usage: "<VM UUID>",
Action: ncli.vmGet,
Category: "get",
},
{
Name: "disklist",
Usage: "<VM UUID>",
Action: ncli.vmDiskList,
Category: "put",
},
{
Name: "update-memory",
Usage: "<VM UUID> <memory in MB integer>",
Action: ncli.vmMemoryUpdate,
Category: "put",
},
{
Name: "update-power",
Usage: "<VM UUID> <ON|OFF|POWERCYCLE|RESET|PAUSE|SUSPEND|RESUME|ACPI_SHUTDOWN|ACPI_REBOOT>",
Action: ncli.vmSetPowerState,
Category: "put",
},
},
},
{
Before: func(c *cli.Context) error {
var err error
ncli.con, err = setupConnection(c)
return err
},
Name: "image",
Usage: "image specific commands. use `uwncli image help` to view options",
Subcommands: []*cli.Command{
{
Name: "list",
Usage: "list all images",
Action: ncli.imageList,
Category: "image",
},
{
Name: "create",
Usage: "create a new image",
Action: ncli.imageCreate,
Category: "image",
},
},
},
{
Before: func(c *cli.Context) error {
var err error
ncli.con, err = setupConnection(c)
return err
},
Name: "cluster",
Usage: "cluster specific commands. use `uwncli cluster help` to view options",
Subcommands: []*cli.Command{
{
Name: "all",
Usage: "retrieve all VMs",
Category: "cluster",
},
},
},
{
Before: func(c *cli.Context) error {
var err error
ncli.con, err = setupConnection(c)
return err
},
Name: "subnet",
Usage: "subnet specific commands. use `uwncli subnet help` to view options",
Subcommands: []*cli.Command{
{
Name: "list",
Usage: "list all subnets",
Action: ncli.listSubnets,
},
},
},
{
Before: func(c *cli.Context) error {
var err error
ncli.con, err = setupConnection(c)
return err
},
Name: "karbon",
Usage: "karbon specific commands. use `uwncli karbon help` to view options",
Subcommands: []*cli.Command{
{
Name: "cluster",
Usage: "karbon cluster commands. use `uwncli karbon cluster help",
Subcommands: []*cli.Command{
{
Name: "list",
Usage: "list all karbon clusters",
Action: ncli.krbnListClusters,
},
},
},
},
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}