-
Notifications
You must be signed in to change notification settings - Fork 87
/
loadbalancer_update.go.disabled
113 lines (92 loc) · 2.74 KB
/
loadbalancer_update.go.disabled
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
package cmd
import (
"fmt"
"os"
"strconv"
"github.com/civo/civogo"
"github.com/civo/cli/config"
"github.com/civo/cli/utility"
"github.com/spf13/cobra"
)
var lbNameUpdate, lbAlgorithmUpdate string
var lbBackendsUpdate []string
var loadBalancerUpdateCmd = &cobra.Command{
Use: "update",
Aliases: []string{"change", "modify"},
Example: "civo loadbalancer update ID/NAME [flags]",
Short: "Update a load balancer",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
utility.EnsureCurrentRegion()
client, err := config.CivoAPIClient()
if regionSet != "" {
client.Region = regionSet
}
if err != nil {
utility.Error("Creating the connection to Civo's API failed with %s", err)
os.Exit(1)
}
loadBalancer, err := client.FindLoadBalancer(args[0])
if err != nil {
utility.Error("%s", err)
os.Exit(1)
}
configLoadBalancer := &civogo.LoadBalancerUpdateConfig{}
if lbNameUpdate != "" {
configLoadBalancer.Name = lbNameUpdate
}
if lbAlgorithmUpdate != "" {
configLoadBalancer.Algorithm = lbAlgorithmUpdate
}
if len(lbBackends) > 0 {
var configLoadBalancerBackend []civogo.LoadBalancerBackendConfig
for _, backend := range lbBackendsUpdate {
data := utility.GetStringMap(backend)
backend := civogo.LoadBalancerBackendConfig{
IP: data["ip"],
}
var port int
if data["source-port"] != "" {
if port, err = strconv.Atoi(data["source-port"]); err != nil {
utility.Error("%s", err)
os.Exit(1)
}
backend.SourcePort = int32(port)
}
if data["target-port"] != "" {
if port, err = strconv.Atoi(data["target-port"]); err != nil {
utility.Error("%s", err)
os.Exit(1)
}
backend.TargetPort = int32(port)
}
if data["protocol"] != "" {
backend.Protocol = data["protocol"]
}
if data["health-check-port"] != "" {
if port, err = strconv.Atoi(data["health-check-port"]); err != nil {
utility.Error("%s", err)
os.Exit(1)
}
backend.HealthCheckPort = int32(port)
}
configLoadBalancerBackend = append(configLoadBalancerBackend, backend)
}
configLoadBalancer.Backends = configLoadBalancerBackend
}
loadBalancerUpdate, err := client.UpdateLoadBalancer(loadBalancer.ID, configLoadBalancer)
if err != nil {
utility.Error("%s", err)
os.Exit(1)
}
ow := utility.NewOutputWriterWithMap(map[string]string{"id": loadBalancerUpdate.ID, "hostname": loadBalancerUpdate.Name})
switch outputFormat {
case "json":
ow.WriteSingleObjectJSON(prettySet)
case "custom":
ow.WriteCustomOutput(outputFields)
default:
fmt.Printf("Updated load balancer with name %s with ID %s\n", utility.Green(loadBalancerUpdate.Name), utility.Green(loadBalancerUpdate.ID))
}
},
}