forked from aliyun/terraform-provider-alicloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension_slb.go
122 lines (94 loc) · 2.31 KB
/
extension_slb.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
package alicloud
import (
"fmt"
"strings"
)
type SchedulerType string
const (
WRRScheduler = SchedulerType("wrr")
WLCScheduler = SchedulerType("wlc")
)
type FlagType string
const (
OnFlag = FlagType("on")
OffFlag = FlagType("off")
)
type AclType string
const (
AclTypeBlack = AclType("black")
AclTypeWhite = AclType("white")
)
type IPVersion string
const (
IPVersion4 = IPVersion("ipv4")
IPVersion6 = IPVersion("ipv6")
)
type StickySessionType string
const (
InsertStickySessionType = StickySessionType("insert")
ServerStickySessionType = StickySessionType("server")
)
const BackendServerPort = -520
type HealthCheckHttpCodeType string
const (
HTTP_2XX = HealthCheckHttpCodeType("http_2xx")
HTTP_3XX = HealthCheckHttpCodeType("http_3xx")
HTTP_4XX = HealthCheckHttpCodeType("http_4xx")
HTTP_5XX = HealthCheckHttpCodeType("http_5xx")
)
type HealthCheckType string
const (
TCPHealthCheckType = HealthCheckType("tcp")
HTTPHealthCheckType = HealthCheckType("http")
)
type LoadBalancerSpecType string
const (
S1Small = "slb.s1.small"
S2Small = "slb.s2.small"
S2Medium = "slb.s2.medium"
S3Small = "slb.s3.small"
S3Medium = "slb.s3.medium"
S3Large = "slb.s3.large"
)
type ListenerErr struct {
ErrType string
Err error
}
func (e *ListenerErr) Error() string {
return e.ErrType + " " + e.Err.Error()
}
func expandBackendServersToString(list []interface{}, weight int) string {
if len(list) < 1 {
return ""
}
var items []string
for _, id := range list {
items = append(items, fmt.Sprintf("{'ServerId':'%s','Weight':'%d'}", id, weight))
}
return fmt.Sprintf("[%s]", strings.Join(items, COMMA_SEPARATED))
}
func expandBackendServersWithPortToString(items []interface{}) string {
if len(items) < 1 {
return ""
}
var servers []string
for _, server := range items {
s := server.(map[string]interface{})
var server_ids []interface{}
var port, weight int
if v, ok := s["server_ids"]; ok {
server_ids = v.([]interface{})
}
if v, ok := s["port"]; ok {
port = v.(int)
}
if v, ok := s["weight"]; ok {
weight = v.(int)
}
for _, id := range server_ids {
str := fmt.Sprintf("{'ServerId':'%s','Port':'%d','Weight':'%d'}", strings.Trim(id.(string), " "), port, weight)
servers = append(servers, str)
}
}
return fmt.Sprintf("[%s]", strings.Join(servers, COMMA_SEPARATED))
}