-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmain.go
563 lines (482 loc) · 26.6 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
package main
import (
_ "github.com/subutai-io/agent/a"
"os"
"github.com/subutai-io/agent/agent"
"github.com/subutai-io/agent/cli"
"github.com/subutai-io/agent/config"
"github.com/subutai-io/agent/log"
prxy "github.com/subutai-io/agent/lib/proxy"
"gopkg.in/alecthomas/kingpin.v2"
"fmt"
"github.com/subutai-io/agent/lib/net"
"github.com/subutai-io/agent/agent/vars"
"text/tabwriter"
"strings"
"github.com/subutai-io/agent/lib/container"
)
var version = "unknown"
var (
app = kingpin.New("subutai", "Subutai Agent")
debugFlag = app.Flag("debug", "Set log level to DEBUG").Short('d').Bool()
//daemon command
daemonCmd = app.Command("daemon", "Run subutai agent daemon")
//subutai list command
/*
subutai list templates
subutai list containers
subutai list all
subutai list info
subutai list containers -n foo
subutai list all -p
*/
listCmd = app.Command("list", "List containers/templates").Alias("ls")
listContainers = listCmd.Command("containers", "List containers").Alias("c")
listTemplates = listCmd.Command("templates", "List templates").Alias("t")
listAll = listCmd.Command("all", "List all").Alias("a")
listContainersDetails = listCmd.Command("info", "List containers info").Alias("i")
listName = listCmd.Flag("name", "container/template name").Short('n').String()
listParents = listCmd.Flag("parents", "list parents").Short('p').Bool()
existsCmd = app.Command("exists", "Check if container/template exists, exit code 0 - exists, 1 - not found")
existsCmdName = existsCmd.Arg("name", "name of container/template").Required().String()
//attach command
/*
subutai attach foo
subutai attach foo "ping localhost"
*/
attachCmd = app.Command("attach", "Attach to Subutai container")
attachName = attachCmd.Arg("name", "running container name").Required().String()
attachCommand = attachCmd.Arg("command", "ad-hoc command to execute").String()
//clone command
/*
subutai clone master foo [-e {env-id} -n {net-settings} -s {secret}]
*/
cloneCmd = app.Command("clone", "Create Subutai container")
cloneTemplate = cloneCmd.Arg("template", "source template").Required().String()
cloneContainer = cloneCmd.Arg("container", "container name").Required().String()
cloneEnvId = cloneCmd.Flag("environment", "id of container environment").Short('e').String()
cloneNetwork = cloneCmd.Flag("network", "container network settings in form 'ip/mask vlan'").Short('n').String()
cloneSecret = cloneCmd.Flag("secret", "console secret").Short('s').String()
restoreCmd = app.Command("restore", "Restore container")
restoreContainer = restoreCmd.Arg("container", "container name").Required().String()
restoreEnvId = restoreCmd.Flag("environment", "id of container environment").Short('e').String()
restoreNetwork = restoreCmd.Flag("network", "container network settings in form 'ip/mask vlan'").Short('n').String()
restoreSecret = restoreCmd.Flag("secret", "console secret").Short('s').String()
//cleanup command
/*
subutai cleanup 123
*/
cleanupCmd = app.Command("cleanup", "Cleanup environment")
cleanupVlan = cleanupCmd.Arg("vlan", "environment vlan").Required().String()
//prune templates command
/*
subutai prune
*/
pruneCmd = app.Command("prune", "Prune templates with no child containers")
//destroy command
/*
subutai destroy foo
*/
destroyCmd = app.Command("destroy", "Destroy Subutai container/template").Alias("rm").Alias("del")
destroyName = destroyCmd.Arg("name", "container/template name").Required().Strings()
//export command
/*
subutai export foo -t {token} [-n {template-name} -s tiny -r 1.0.0 --local]
*/
exportCmd = app.Command("export", "Export container as a template")
exportContainer = exportCmd.Arg("container", "source container").Required().String()
exportToken = exportCmd.Flag("token", "CDN token").Required().Short('t').String()
exportName = exportCmd.Flag("name", "template name").Short('n').String()
exportSize = exportCmd.Flag("size", "template preferred size").Short('s').String()
exportLocal = exportCmd.Flag("local", "export template to local cache").Short('l').Bool()
exportVersion = exportCmd.Flag("ver", "template version").Short('r').String()
//import command
/*
subutai import debian-stretch
#special case for management container:
subutai import management -s {secret}
*/
importCmd = app.Command("import", "Import Subutai template")
importName = importCmd.Arg("template", "template name/path to template archive").Required().String()
importSecret = importCmd.Flag("secret", "console secret").Short('s').String()
//info command
infoCmd = app.Command("info", "System information")
/*
#RH id
subutai info id
#container id
subutai info id foo
*/
infoIdCmd = infoCmd.Command("id", "host/container id")
infoIdContainer = infoIdCmd.Arg("container", "container name").String()
//subutai info system
infoSystemCmd = infoCmd.Command("system", "host info").Alias("sys")
//subutai info os
infoOsCmd = infoCmd.Command("os", "host os")
//subutai info ip
infoIpCmd = infoCmd.Command("ipaddr", "host ip address").Alias("ip")
//subutai info ports
infoPortsCmd = infoCmd.Command("ports", "host used ports").Alias("p")
//subutai info du foo
infoDUCmd = infoCmd.Command("du", "container disk usage")
infoDUContainer = infoDUCmd.Arg("container", "container name").Required().String()
//subutai info qu foo
infoQuotaCmd = infoCmd.Command("qu", "container quota usage")
infoQuotaContainer = infoQuotaCmd.Arg("container", "container name").Required().String()
//hostname command
//TODO add hostname read commands e.g. subutai hostname rh, subutai hostname con foo [no-console-change]
/*
subutai hostname rh new-rh-hostname
subutai hostname container foo new-container-hostname
*/
hostnameCmd = app.Command("hostname", "Set host/container hostname")
hostnameRh = hostnameCmd.Command("rh", "Set RH hostname")
hostnameRhNewHostname = hostnameRh.Arg("hostname", "new hostname").Required().String()
hostnameContainer = hostnameCmd.Command("con", "Set container hostname").Alias("container")
hostnameContainerName = hostnameContainer.Arg("container", "container name").Required().String()
hostnameContainerNewHostname = hostnameContainer.Arg("hostname", "new hostname").Required().String()
//map command
//e.g. subutai map list, subutai map add .., subutai map del ..
/*
subutai map add ...
*/
mapCmd = app.Command("map", "Map ports")
mapAddCmd = mapCmd.Command("add", "Add port mapping")
mapAddProtocol = mapAddCmd.Flag("protocol", "protocol [http,https,tcp,udp]").Short('p').Required().String()
mapAddExternalPort = mapAddCmd.Flag("external port", "external port in range [80,443,1000-65535]").Short('e').Required().Int()
mapAddInternalServer = mapAddCmd.Flag("internal server", "ip:port").Short('i').Required().String()
mapAddDomain = mapAddCmd.Flag("domain", "domain name").Short('n').String()
mapAddCertificate = mapAddCmd.Flag("certificate", "path to joint x509 cert and private key pem file; if not specified, LE certificates will be obtained").Short('c').String()
mapAddBalancing = mapAddCmd.Flag("balancing", "load balancing policy [rr(round_robin),sticky(ip_hash),lcon(least_conn)]").Short('b').String()
mapAddSslBackend = mapAddCmd.Flag("sslbackend", "use ssl backend in https upstream").Short('s').Bool()
mapAddRedirect = mapAddCmd.Flag("redirect", "redirect port 80 to external port").Short('r').Bool()
mapAddHttp2 = mapAddCmd.Flag("http2", "use http2 protocol").Bool()
/*
subutai map rm tcp ...
*/
mapRemoveCmd = mapCmd.Command("rm", "Remove port mapping").Alias("del")
mapRemoveProtocol = mapRemoveCmd.Flag("protocol", "protocol [http,https,tcp,udp]").Short('p').Required().String()
mapRemoveExternalPort = mapRemoveCmd.Flag("external port", "external port in range [80,443,1000-65535]").Short('e').Required().Int()
mapRemoveInternalServer = mapRemoveCmd.Flag("internal server", "ip:port").Short('i').String()
mapRemoveDomain = mapRemoveCmd.Flag("domain", "domain name").Short('n').String()
/*
subutai map list
subutai map list tcp
*/
mapList = mapCmd.Command("list", "List mapped ports").Alias("ls")
mapListProtocol = mapList.Flag("protocol", "http, https, tcp or udp").Short('p').String()
//metrics command
//subutai metrics -s "2018-08-17 02:26:11" -e "2018-08-17 03:26:11"
metricsCmd = app.Command("metrics", "Print host/container metrics")
metricsHost = metricsCmd.Arg("name", "host/container name").Required().String()
metricsStart = metricsCmd.Flag("start", "metrics start time 'yyyy-mm-dd hh:mi:ss'").Short('s').Required().String()
metricsEnd = metricsCmd.Flag("end", "metrics end time 'yyyy-mm-dd hh:mi:ss'").Short('e').Required().String()
//prxy command
prxyCmd = app.Command("proxy", "Subutai proxy")
prxyCreateCmd = prxyCmd.Command("create", "Create proxy")
prxyCreateDomain = prxyCreateCmd.Flag("domain", "proxy domain").Short('n').String()
prxyCreateProtocol = prxyCreateCmd.Flag("protocol", "protocol [http,https,tcp,udp]").Short('p').Required().String()
prxyCreatePort = prxyCreateCmd.Flag("port", "external port in range [80,443,1000-65535]").Short('e').Required().Int()
prxyCreateTag = prxyCreateCmd.Flag("tag", "unique tag for proxy").Short('t').Required().String()
prxyCreateLoadBalancing = prxyCreateCmd.Flag("balancing", "load balancing policy [rr(round_robin),sticky(ip_hash),lcon(least_conn)]").Short('b').String()
prxyCreateCertificate = prxyCreateCmd.Flag("certificate", "path to joint x509 cert and private key pem file; if not specified, LE certificates will be obtained").Short('c').String()
prxyCreateRedirect = prxyCreateCmd.Flag("redirect", "redirect port 80 to external port").Short('r').Bool()
prxyCreateSslBackend = prxyCreateCmd.Flag("sslbackend", "use ssl backend in https upstream").Short('s').Bool()
prxyCreateHttp2 = prxyCreateCmd.Flag("http2", "use http2 protocol").Bool()
prxyListCmd = prxyCmd.Command("list", "List proxies").Alias("ls")
prxyListProtocol = prxyListCmd.Flag("protocol", "filer by protocol [http,https]").Short('p').String()
prxyListTag = prxyListCmd.Flag("tag", "proxy tag").Short('t').String()
prxyRemoveCmd = prxyCmd.Command("remove", "Remove proxy").Alias("rm").Alias("del")
prxyRemoveTag = prxyRemoveCmd.Flag("tag", "proxy tag").Short('t').Required().String()
//prxy server command
prxyServerCmd = prxyCmd.Command("server", "Manage proxied servers").Alias("srv")
prxyServerAddCmd = prxyServerCmd.Command("add", "Add proxied server")
prxyServerAddTag = prxyServerAddCmd.Flag("tag", "proxy tag").Short('t').Required().String()
prxyServerAddSocket = prxyServerAddCmd.Flag("server", "ip:port").Short('s').Required().String()
prxyServerRemoveCmd = prxyServerCmd.Command("remove", "Remove proxied server").Alias("rm").Alias("del")
prxyServerRemoveTag = prxyServerRemoveCmd.Flag("tag", "proxy tag").Short('t').Required().String()
prxyServerRemoveSocket = prxyServerRemoveCmd.Flag("server", "ip:port").Short('s').Required().String()
prxyServerListCmd = prxyServerCmd.Command("list", "List servers for proxy").Alias("ls")
prxyServerListTag = prxyServerListCmd.Flag("tag", "proxy tag").Short('t').Required().String()
//quota command
quotaCmd = app.Command("quota", "Manage container quotas")
quotaGetCmd = quotaCmd.Command("get", "Print container resource quota")
quotaSetCmd = quotaCmd.Command("set", "Set container resource quota")
//subutai quota get -c foo -r cpu
quotaGetResource = quotaGetCmd.Flag("resource", "resource type (cpu, cpuset, ram, disk, network)").
Short('r').Required().String()
quotaGetContainer = quotaGetCmd.Flag("container", "container name").Short('c').Required().String()
//subutai quota set -c foo -r cpu 123
quotaSetResource = quotaSetCmd.Flag("resource", "resource type (cpu, cpuset, ram, disk, network)").
Short('r').Required().String()
quotaSetContainer = quotaSetCmd.Flag("container", "container name").Short('c').Required().String()
quotaSetLimit = quotaSetCmd.Arg("limit", "limit (% for cpu, # for cpuset, b for network, mb for ram, gb for disk )").Required().String()
//start command
startCmd = app.Command("start", "Start Subutai container")
startCmdContainer = startCmd.Arg("name(s)", "container name(s)").Required().Strings()
//stop command
stopCmd = app.Command("stop", "Stop Subutai container")
stopCmdContainer = stopCmd.Arg("name(s)", "container name(s)").Required().Strings()
//snapshot command
snapshotCmd = app.Command("snapshot", "Manage container snapshots").Alias("snap")
snapshotCreateCmd = snapshotCmd.Command("create", "Create snapshot").Alias("add")
snapshotCreateCmdContainer = snapshotCreateCmd.Flag("container", "container name").Short('c').Required().String()
snapshotCreateCmdPartition = snapshotCreateCmd.Flag(
"partition", "container partition [rootfs|var|opt|home|config|all]").Short('p').Required().String()
snapshotCreateCmdLabel = snapshotCreateCmd.Flag("label", "snapshot label").Short('l').Required().String()
snapshotCreateCmdStop = snapshotCreateCmd.Flag("stop", "stop container when doing snapshot").Short('s').Bool()
snapshotRemoveCmd = snapshotCmd.Command("remove", "Remove snapshot").Alias("rm").Alias("del")
snapshotRemoveCmdContainer = snapshotRemoveCmd.Flag("container", "container name").Short('c').Required().String()
snapshotRemoveCmdPartition = snapshotRemoveCmd.Flag(
"partition", "container partition [rootfs|var|opt|home|config|all]").Short('p').Required().String()
snapshotRemoveCmdLabel = snapshotRemoveCmd.Flag("label", "snapshot label").Short('l').Required().String()
snapshotListCmd = snapshotCmd.Command("list", "List snapshots").Alias("ls")
snapshotListCmdContainer = snapshotListCmd.Flag("container", "container name").Short('c').String()
snapshotListCmdPartition = snapshotListCmd.Flag(
"partition", "container partition [rootfs|var|opt|home]").Short('p').String()
snapshotRollbackCmd = snapshotCmd.Command("rollback", "Rollback to snapshot").Alias("rb")
snapshotRollBackCmdContainer = snapshotRollbackCmd.Flag("container", "container name").Short('c').Required().String()
snapshotRollbackCmdPartition = snapshotRollbackCmd.Flag(
"partition", "container partition [rootfs|var|opt|home|config|all]").Short('p').Required().String()
snapshotRollbackCmdLabel = snapshotRollbackCmd.Flag("label", "snapshot label").Short('l').Required().String()
snapshotRollbackCmdStop = snapshotRollbackCmd.Flag("stop", "stop container when doing rollback").Short('s').Bool()
snapshotRollbackCmdForce = snapshotRollbackCmd.Flag("force", "force rollback which will remove more recent snapshots if any").Short('f').Bool()
snapshotSendCmd = snapshotCmd.Command("send", "Send snapshots to archive file")
snapshotSendCmdContainer = snapshotSendCmd.Flag("container", "container name").Short('c').Required().String()
snapshotSendCmdSnapshots = snapshotSendCmd.Flag("label(s)", "snapshot label(s). You can specify up to 2 labels separated by space").Short('l').Required().String()
snapshotSendCmdDestination = snapshotSendCmd.Flag("destination", "Destination directory").Default(config.Agent.CacheDir).String()
snapshotReceiveCmd = snapshotCmd.Command("receive", "Receive snapshots from a file").Alias("recv")
snapshotReceiveCmdContainer = snapshotReceiveCmd.Flag("container", "container name").Short('c').Required().String()
snapshotReceiveCmdFile = snapshotReceiveCmd.Flag("file", "path to archive file containing snapshots").Short('f').Required().String()
cdnCmd = app.Command("cdn", "Download/upload files from/to CDN")
cdnDownloadCmd = cdnCmd.Command("get", "Download file")
cdnDownloadCmdId = cdnDownloadCmd.Arg("id", "Id of file on CDN").Required().String()
cdnDowloadCmdDestDir = cdnDownloadCmd.Flag("destination", "Destination directory").Default(config.Agent.CacheDir).String()
cdnUploadCmd = cdnCmd.Command("put", "Upload file")
cdnUploadCmdFile = cdnUploadCmd.Flag("file", "path to file to upload").Short('f').Required().String()
cndUploadCmdToken = cdnUploadCmd.Flag("token", "CDN token").Short('t').Required().String()
fileCmd = app.Command("file", "Encrypt/decrypt files with password")
fileEncryptCmd = fileCmd.Command("encrypt", "Encrypt file")
fileEncryptCmdPath = fileEncryptCmd.Flag("source", "Source file to encrypt").Short('s').Required().String()
fileEncryptCmdPassword = fileEncryptCmd.Flag("password", "Password to use for encryption").Short('p').Required().String()
fileDecryptCmd = fileCmd.Command("decrypt", "Decrypt file")
fileDecryptCmdSourcePath = fileDecryptCmd.Flag("source", "Source file to decrypt").Short('s').Required().String()
fileDecryptCmdTargetPath = fileDecryptCmd.Flag("target", "Target decrypted file").Short('t').String()
fileDecryptCmdPassword = fileDecryptCmd.Flag("password", "Password to use for decryption").Short('p').Required().String()
//restart command
restartCmd = app.Command("restart", "Restart Subutai container")
restartCmdContainer = restartCmd.Arg("name(s)", "container name(s)").Required().Strings()
//update command
//subutai update rh
//subutai update management -c
updateCmd = app.Command("update", "Update peer components")
updateCmdComponent = updateCmd.Arg("component", "component to update (rh, management)").Required().String()
updateCheck = updateCmd.Flag("check", "check for updates without installation").Short('c').Bool()
//tunnel command
tunnelCmd = app.Command("tunnel", "Manage ssh tunnels")
//tunnel add ip[:port] [ttl]
tunnelAddCmd = tunnelCmd.Command("add", "Create ssh tunnel")
tunneAddSocket = tunnelAddCmd.Arg("socket", "socket in form ip[:port]").Required().String()
tunnelAddTimeout = tunnelAddCmd.Arg("ttl", "ttl of tunnel (if ttl missing, tunnel is permanent)").String()
tunnelAddHumanFriendly = tunnelAddCmd.Flag("ssh", "generate ssh connection string").Short('s').Bool()
//tunnel del ip[:port]
tunnelDelCmd = tunnelCmd.Command("del", "Delete ssh tunnel").Alias("rm")
tunnelDelSocket = tunnelDelCmd.Arg("socket", "socket in form ip[:port]").Required().String()
//tunnel list
tunnelListCmd = tunnelCmd.Command("list", "List ssh tunnels").Alias("ls")
//tunnel check
tunnelCheckCmd = tunnelCmd.Command("check", "for internal usage").Hidden()
//vxlan command
vxlanCmd = app.Command("vxlan", "Manage vxlan tunnels")
//vxlan add command
vxlanAddCmd = vxlanCmd.Command("add", "Add vxlan tunnel")
vxlanAddName = vxlanAddCmd.Arg("name", "tunnel name").Required().String()
vxlanAddRemoteIp = vxlanAddCmd.Flag("remoteip", "remote ip").Required().Short('r').String()
vxlanAddVni = vxlanAddCmd.Flag("vni", "environment vni").Required().Short('n').String()
vxlanAddVlan = vxlanAddCmd.Flag("vlan", "environment vlan").Required().Short('l').String()
//vxlan del {tunnel-name}
vxlanDelCmd = vxlanCmd.Command("del", "Delete vxlan tunnel").Alias("rm")
vxlanDelName = vxlanDelCmd.Arg("name", "tunnel name").Required().String()
//vxlan list
vxlanListCmd = vxlanCmd.Command("list", "List vxlan tunnels").Alias("ls")
//batch command
batchCmd = app.Command("batch", "Execute a batch of commands")
batchJson = batchCmd.Arg("commands", "batch of commands in JSON").Required().String()
)
func init() {
app.Version(version)
app.HelpFlag.Short('h')
app.VersionFlag.Hidden().Short('v')
vars.Version = version
}
func main() {
input := kingpin.MustParse(app.Parse(os.Args[1:]))
if *debugFlag {
log.Level(log.DebugLevel)
}
vars.IsDaemon = input == daemonCmd.FullCommand()
switch input {
case listContainers.FullCommand():
cli.LxcList(*listName, true, false, false, *listParents)
case listTemplates.FullCommand():
cli.LxcList(*listName, false, true, false, *listParents)
case listContainersDetails.FullCommand():
cli.LxcList(*listName, false, false, true, *listParents)
case listAll.FullCommand():
cli.LxcList(*listName, true, true, false, *listParents)
case existsCmd.FullCommand():
if !container.LxcInstanceExists(*existsCmdName) {
os.Exit(1)
}
case daemonCmd.FullCommand():
config.InitAgentDebug()
agent.Start()
case attachCmd.FullCommand():
cli.LxcAttach(*attachName, *attachCommand)
case cloneCmd.FullCommand():
cli.LxcClone(*cloneTemplate, *cloneContainer, *cloneEnvId, *cloneNetwork, *cloneSecret)
case restoreCmd.FullCommand():
cli.RestoreContainer(*restoreContainer, *restoreEnvId, *restoreNetwork, *restoreSecret)
case cleanupCmd.FullCommand():
cli.Cleanup(*cleanupVlan)
case pruneCmd.FullCommand():
cli.Prune()
case destroyCmd.FullCommand():
cli.LxcDestroy(*destroyName...)
case exportCmd.FullCommand():
cli.LxcExport(*exportContainer, *exportName, *exportVersion, *exportSize, *exportToken, *exportLocal)
case importCmd.FullCommand():
cli.LxcImport(*importName, *importSecret)
case infoIdCmd.FullCommand():
fmt.Println(cli.GetFingerprint(*infoIdContainer))
case infoSystemCmd.FullCommand():
fmt.Println(cli.GetSystemInfo())
case infoOsCmd.FullCommand():
fmt.Println(cli.GetOsName())
case infoIpCmd.FullCommand():
fmt.Println(net.GetIp())
case infoPortsCmd.FullCommand():
for k := range cli.GetUsedPorts() {
fmt.Println(k)
}
case infoDUCmd.FullCommand():
fmt.Println(cli.GetDiskUsage(*infoDUContainer))
case infoQuotaCmd.FullCommand():
fmt.Println(cli.GetContainerQuotaUsage(*infoQuotaContainer))
case hostnameRh.FullCommand():
cli.Hostname(*hostnameRhNewHostname)
case hostnameContainer.FullCommand():
cli.LxcHostname(*hostnameContainerName, *hostnameContainerNewHostname)
case mapAddCmd.FullCommand():
cli.AddPortMapping(*mapAddProtocol, *mapAddDomain, *mapAddBalancing, *mapAddExternalPort,
*mapAddInternalServer, *mapAddCertificate, *mapAddRedirect, *mapAddSslBackend, *mapAddHttp2)
case mapRemoveCmd.FullCommand():
cli.RemovePortMapping(*mapRemoveProtocol, *mapRemoveDomain, *mapRemoveExternalPort, *mapRemoveInternalServer)
case mapList.FullCommand():
for _, v := range cli.GetPortMappings(*mapListProtocol) {
fmt.Println(v)
}
//prxy command
case prxyCreateCmd.FullCommand():
log.Check(log.ErrorLevel, "Creating proxy", prxy.CreateProxy(*prxyCreateProtocol,
*prxyCreateDomain, *prxyCreateLoadBalancing, *prxyCreateTag, *prxyCreatePort,
*prxyCreateRedirect, *prxyCreateSslBackend, *prxyCreateCertificate, *prxyCreateHttp2))
case prxyListCmd.FullCommand():
lines := []string{"Tag\tProtocol\tPort\tDomain\tBalancing\tRedirected\tSslBackend\tLE\tHttp2\tApplied"}
proxies, err := prxy.GetProxies(*prxyListProtocol)
log.Check(log.ErrorLevel, "Getting proxies", err)
for _, v := range proxies {
proxy := v.Proxy
if *prxyListTag == "" || *prxyListTag == proxy.Tag {
servers := v.Servers
lines = append(lines, fmt.Sprintf("%s\t%s\t%d\t%s\t%s\t%t\t%t\t%t\t%t\t%t",
proxy.Tag, proxy.Protocol, proxy.Port, proxy.Domain, proxy.LoadBalancing, proxy.Redirect80Port,
proxy.SslBackend, proxy.IsLE(), proxy.Http2, len(servers) > 0))
}
}
output(lines)
case prxyRemoveCmd.FullCommand():
log.Check(log.ErrorLevel, "Removing proxy", prxy.RemoveProxy(*prxyRemoveTag))
case prxyServerAddCmd.FullCommand():
log.Check(log.ErrorLevel, "Adding server",
prxy.AddProxiedServer(*prxyServerAddTag, *prxyServerAddSocket))
case prxyServerRemoveCmd.FullCommand():
log.Check(log.ErrorLevel, "Removing server",
prxy.RemoveProxiedServer(*prxyServerRemoveTag, *prxyServerRemoveSocket))
case prxyServerListCmd.FullCommand():
lines := []string{"Protocol\tPort\tDomain\tServer"}
proxies, err := prxy.GetProxies("")
log.Check(log.ErrorLevel, "Getting proxies", err)
for _, v := range proxies {
proxy := v.Proxy
if *prxyServerListTag == proxy.Tag {
for _, server := range v.Servers {
lines = append(lines, fmt.Sprintf("%s\t%d\t%s\t%s", proxy.Protocol, proxy.Port, proxy.Domain, server.Socket))
}
}
}
output(lines)
case snapshotCreateCmd.FullCommand():
cli.CreateSnapshot(*snapshotCreateCmdContainer, *snapshotCreateCmdPartition, *snapshotCreateCmdLabel, *snapshotCreateCmdStop)
case snapshotRemoveCmd.FullCommand():
cli.RemoveSnapshot(*snapshotRemoveCmdContainer, *snapshotRemoveCmdPartition, *snapshotRemoveCmdLabel)
case snapshotListCmd.FullCommand():
fmt.Println(cli.ListSnapshots(*snapshotListCmdContainer, *snapshotListCmdPartition))
case snapshotRollbackCmd.FullCommand():
cli.RollbackToSnapshot(*snapshotRollBackCmdContainer, *snapshotRollbackCmdPartition, *snapshotRollbackCmdLabel, *snapshotRollbackCmdForce, *snapshotRollbackCmdStop)
case snapshotSendCmd.FullCommand():
cli.SendContainerSnapshots(*snapshotSendCmdContainer, *snapshotSendCmdDestination, strings.Split(*snapshotSendCmdSnapshots, ",")...)
case snapshotReceiveCmd.FullCommand():
cli.ReceiveContainerSnapshots(*snapshotReceiveCmdContainer, *snapshotReceiveCmdFile)
case cdnDownloadCmd.FullCommand():
cli.DownloadRawFile(*cdnDownloadCmdId, *cdnDowloadCmdDestDir)
case cdnUploadCmd.FullCommand():
cli.UploadRawFile(*cdnUploadCmdFile, *cndUploadCmdToken)
case fileEncryptCmd.FullCommand():
cli.EncryptFile(*fileEncryptCmdPath, *fileEncryptCmdPassword)
case fileDecryptCmd.FullCommand():
cli.DecryptFile(*fileDecryptCmdSourcePath, *fileDecryptCmdTargetPath, *fileDecryptCmdPassword)
case metricsCmd.FullCommand():
fmt.Println(cli.GetHostMetrics(*metricsHost, *metricsStart, *metricsEnd))
case quotaGetCmd.FullCommand():
cli.LxcQuota(*quotaGetContainer, *quotaGetResource, "", "")
case quotaSetCmd.FullCommand():
cli.LxcQuota(*quotaSetContainer, *quotaSetResource, *quotaSetLimit, "")
case startCmd.FullCommand():
cli.LxcStart(*startCmdContainer...)
case stopCmd.FullCommand():
cli.LxcStop(*stopCmdContainer...)
case restartCmd.FullCommand():
cli.LxcRestart(*restartCmdContainer...)
case updateCmd.FullCommand():
cli.Update(*updateCmdComponent, *updateCheck)
case tunnelAddCmd.FullCommand():
cli.AddSshTunnel(*tunneAddSocket, *tunnelAddTimeout, *tunnelAddHumanFriendly)
case tunnelDelCmd.FullCommand():
cli.DelSshTunnel(*tunnelDelSocket)
case tunnelCheckCmd.FullCommand():
cli.CheckSshTunnels()
case tunnelListCmd.FullCommand():
for _, tunnel := range cli.GetSshTunnels() {
fmt.Printf("%s\t%s\t%d\n",
tunnel.RemoteSocket, tunnel.LocalSocket, tunnel.Ttl)
}
case vxlanAddCmd.FullCommand():
cli.AddVxlanTunnel(*vxlanAddName, *vxlanAddRemoteIp, *vxlanAddVlan, *vxlanAddVni)
case vxlanDelCmd.FullCommand():
cli.DelVxlanTunnel(*vxlanDelName)
case vxlanListCmd.FullCommand():
for _, tun := range cli.GetVxlanTunnels() {
fmt.Println(tun.Name, tun.RemoteIp, tun.Vlan, tun.Vni)
}
case batchCmd.FullCommand():
cli.Batch(*batchJson)
}
}
func output(lines []string) {
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.TabIndent)
for _, line := range lines {
fmt.Fprintln(w, line)
}
w.Flush()
}