Skip to content

Commit

Permalink
Add load-balancer nodes flags and display (#474)
Browse files Browse the repository at this point in the history
* Add loadbalancer nodes flags and display

* Add shorthand flag for lb nodes
  • Loading branch information
optik-aper authored Sep 19, 2024
1 parent 1105943 commit 8b30bd0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
29 changes: 29 additions & 0 deletions cmd/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,19 @@ func NewCmdLoadBalancer(base *cli.Base) *cobra.Command { //nolint:funlen,gocyclo
return fmt.Errorf("error parsing flag 'instances' for load balancer create : %v", errIn)
}

nodes, errNo := cmd.Flags().GetInt("nodes")
if errNo != nil {
return fmt.Errorf("error parsing flag 'nodes' for load balancer create : %v", errNo)
}

o.CreateReq = &govultr.LoadBalancerReq{
Region: region,
Label: label,
VPC: &vpc,
ProxyProtocol: &proxyProtocol,
SSLRedirect: &sslRedirect,
BalancingAlgorithm: algorithm,
Nodes: nodes,
Instances: instances,
HealthCheck: &govultr.HealthCheck{
Port: port,
Expand Down Expand Up @@ -403,6 +409,13 @@ When not provided, load balancer defaults to public network.`,
"(optional) an array of instances IDs that you want attached to the load balancer.",
)

create.Flags().IntP(
"nodes",
"n",
1,
"(optional) The number of nodes to add to the load balancer (1-99), must be an odd number",
)

// Update
update := &cobra.Command{
Use: "update <Load Balancer ID>",
Expand Down Expand Up @@ -512,6 +525,11 @@ When not provided, load balancer defaults to public network.`,
return fmt.Errorf("error parsing flag 'instances' for load balancer update : %v", errIn)
}

nodes, errNo := cmd.Flags().GetInt("nodes")
if errNo != nil {
return fmt.Errorf("error parsing flag 'nodes' for load balancer update : %v", errNo)
}

o.UpdateReq = &govultr.LoadBalancerReq{}

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

if cmd.Flags().Changed("nodes") {
o.UpdateReq.Nodes = nodes
}

if err := o.update(); err != nil {
return fmt.Errorf("error updating load balancer : %v", err)
}
Expand Down Expand Up @@ -686,6 +708,13 @@ When not provided, load balancer defaults to public network.`,
"(optional) an array of instances IDs that you want attached to the load balancer.",
)

update.Flags().IntP(
"nodes",
"n",
1,
"(optional) The number of nodes to add to the load balancer (1-99), must be an odd number",
)

// Delete
del := &cobra.Command{
Use: "delete <Load Balancer ID>",
Expand Down
6 changes: 5 additions & 1 deletion cmd/loadbalancer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func (l *LBsPrinter) Data() [][]string {
[]string{"IPV4", l.LBs[i].IPV4},
[]string{"IPV6", l.LBs[i].IPV6},
[]string{"HAS SSL", strconv.FormatBool(*l.LBs[i].SSLInfo)},
[]string{"NODES", strconv.Itoa(l.LBs[i].Nodes)},
[]string{"INSTANCES", printer.ArrayOfStringsToString(l.LBs[i].Instances)},

[]string{" "},
Expand Down Expand Up @@ -167,6 +168,7 @@ func (l *LBPrinter) Data() [][]string {
[]string{"IPV4", l.LB.IPV4},
[]string{"IPV6", l.LB.IPV6},
[]string{"HAS SSL", strconv.FormatBool(*l.LB.SSLInfo)},
[]string{"NODES", strconv.Itoa(l.LB.Nodes)},
[]string{"INSTANCES", printer.ArrayOfStringsToString(l.LB.Instances)},

[]string{" "},
Expand Down Expand Up @@ -279,13 +281,14 @@ func (l *LBsSummaryPrinter) Columns() [][]string {
"INSTANCE#",
"FORWARD#",
"FIREWALL#",
"NODES#",
}}
}

// Data ...
func (l *LBsSummaryPrinter) Data() [][]string {
if len(l.LBs) == 0 {
return [][]string{0: {"---", "---", "---", "---", "---", "---", "---"}}
return [][]string{0: {"---", "---", "---", "---", "---", "---", "---", "---"}}
}

var data [][]string
Expand All @@ -303,6 +306,7 @@ func (l *LBsSummaryPrinter) Data() [][]string {
strconv.Itoa(instanceCount),
strconv.Itoa(forwardRuleCount),
strconv.Itoa(firewallRuleCount),
strconv.Itoa(l.LBs[i].Nodes),
})
}

Expand Down

0 comments on commit 8b30bd0

Please sign in to comment.