Skip to content

Commit 8b30bd0

Browse files
authored
Add load-balancer nodes flags and display (#474)
* Add loadbalancer nodes flags and display * Add shorthand flag for lb nodes
1 parent 1105943 commit 8b30bd0

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

cmd/loadbalancer/loadbalancer.go

+29
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,19 @@ func NewCmdLoadBalancer(base *cli.Base) *cobra.Command { //nolint:funlen,gocyclo
260260
return fmt.Errorf("error parsing flag 'instances' for load balancer create : %v", errIn)
261261
}
262262

263+
nodes, errNo := cmd.Flags().GetInt("nodes")
264+
if errNo != nil {
265+
return fmt.Errorf("error parsing flag 'nodes' for load balancer create : %v", errNo)
266+
}
267+
263268
o.CreateReq = &govultr.LoadBalancerReq{
264269
Region: region,
265270
Label: label,
266271
VPC: &vpc,
267272
ProxyProtocol: &proxyProtocol,
268273
SSLRedirect: &sslRedirect,
269274
BalancingAlgorithm: algorithm,
275+
Nodes: nodes,
270276
Instances: instances,
271277
HealthCheck: &govultr.HealthCheck{
272278
Port: port,
@@ -403,6 +409,13 @@ When not provided, load balancer defaults to public network.`,
403409
"(optional) an array of instances IDs that you want attached to the load balancer.",
404410
)
405411

412+
create.Flags().IntP(
413+
"nodes",
414+
"n",
415+
1,
416+
"(optional) The number of nodes to add to the load balancer (1-99), must be an odd number",
417+
)
418+
406419
// Update
407420
update := &cobra.Command{
408421
Use: "update <Load Balancer ID>",
@@ -512,6 +525,11 @@ When not provided, load balancer defaults to public network.`,
512525
return fmt.Errorf("error parsing flag 'instances' for load balancer update : %v", errIn)
513526
}
514527

528+
nodes, errNo := cmd.Flags().GetInt("nodes")
529+
if errNo != nil {
530+
return fmt.Errorf("error parsing flag 'nodes' for load balancer update : %v", errNo)
531+
}
532+
515533
o.UpdateReq = &govultr.LoadBalancerReq{}
516534

517535
if len(rulesInForward) > 0 {
@@ -609,6 +627,10 @@ When not provided, load balancer defaults to public network.`,
609627
o.UpdateReq.Instances = instances
610628
}
611629

630+
if cmd.Flags().Changed("nodes") {
631+
o.UpdateReq.Nodes = nodes
632+
}
633+
612634
if err := o.update(); err != nil {
613635
return fmt.Errorf("error updating load balancer : %v", err)
614636
}
@@ -686,6 +708,13 @@ When not provided, load balancer defaults to public network.`,
686708
"(optional) an array of instances IDs that you want attached to the load balancer.",
687709
)
688710

711+
update.Flags().IntP(
712+
"nodes",
713+
"n",
714+
1,
715+
"(optional) The number of nodes to add to the load balancer (1-99), must be an odd number",
716+
)
717+
689718
// Delete
690719
del := &cobra.Command{
691720
Use: "delete <Load Balancer ID>",

cmd/loadbalancer/printer.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func (l *LBsPrinter) Data() [][]string {
4646
[]string{"IPV4", l.LBs[i].IPV4},
4747
[]string{"IPV6", l.LBs[i].IPV6},
4848
[]string{"HAS SSL", strconv.FormatBool(*l.LBs[i].SSLInfo)},
49+
[]string{"NODES", strconv.Itoa(l.LBs[i].Nodes)},
4950
[]string{"INSTANCES", printer.ArrayOfStringsToString(l.LBs[i].Instances)},
5051

5152
[]string{" "},
@@ -167,6 +168,7 @@ func (l *LBPrinter) Data() [][]string {
167168
[]string{"IPV4", l.LB.IPV4},
168169
[]string{"IPV6", l.LB.IPV6},
169170
[]string{"HAS SSL", strconv.FormatBool(*l.LB.SSLInfo)},
171+
[]string{"NODES", strconv.Itoa(l.LB.Nodes)},
170172
[]string{"INSTANCES", printer.ArrayOfStringsToString(l.LB.Instances)},
171173

172174
[]string{" "},
@@ -279,13 +281,14 @@ func (l *LBsSummaryPrinter) Columns() [][]string {
279281
"INSTANCE#",
280282
"FORWARD#",
281283
"FIREWALL#",
284+
"NODES#",
282285
}}
283286
}
284287

285288
// Data ...
286289
func (l *LBsSummaryPrinter) Data() [][]string {
287290
if len(l.LBs) == 0 {
288-
return [][]string{0: {"---", "---", "---", "---", "---", "---", "---"}}
291+
return [][]string{0: {"---", "---", "---", "---", "---", "---", "---", "---"}}
289292
}
290293

291294
var data [][]string
@@ -303,6 +306,7 @@ func (l *LBsSummaryPrinter) Data() [][]string {
303306
strconv.Itoa(instanceCount),
304307
strconv.Itoa(forwardRuleCount),
305308
strconv.Itoa(firewallRuleCount),
309+
strconv.Itoa(l.LBs[i].Nodes),
306310
})
307311
}
308312

0 commit comments

Comments
 (0)