-
Notifications
You must be signed in to change notification settings - Fork 10
/
region.go
314 lines (295 loc) · 7.97 KB
/
region.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
package utils
import (
"fmt"
"strings"
)
func GetRegion(zone string) (region string, err error) {
err = nil
switch {
case strings.HasPrefix(zone, "us-south"):
region = "us-south"
case strings.HasPrefix(zone, "dal"):
region = "dal"
case strings.HasPrefix(zone, "sao"):
region = "sao"
case strings.HasPrefix(zone, "us-east"):
region = "us-east"
case strings.HasPrefix(zone, "eu-de-"):
region = "eu-de"
case strings.HasPrefix(zone, "lon"):
region = "lon"
case strings.HasPrefix(zone, "syd"):
region = "syd"
case strings.HasPrefix(zone, "tok"):
region = "tok"
case strings.HasPrefix(zone, "osa"):
region = "osa"
case strings.HasPrefix(zone, "mon"):
region = "mon"
case strings.HasPrefix(zone, "mad"):
region = "mad"
case strings.HasPrefix(zone, "wdc"):
region = "wdc"
case strings.HasPrefix(zone, "tor"):
region = "tor"
case strings.HasPrefix(zone, "che"):
region = "che"
default:
return "", fmt.Errorf("region not found for the zone, talk to the developer to add the support into the tool: %s", zone)
}
return
}
// Region describes respective IBM Cloud COS region, VPC region and Zones associated with a region in Power VS.
type Region struct {
Description string
VPCRegion string
COSRegion string
Zones []string
SysTypes []string
VPCZones []string
}
// Regions provides a mapping between Power VS and IBM Cloud VPC and IBM COS regions.
var Regions = map[string]Region{
"dal": {
Description: "Dallas, USA",
VPCRegion: "us-south",
COSRegion: "us-south",
Zones: []string{
"dal10",
"dal12",
},
SysTypes: []string{"s922", "e980"},
VPCZones: []string{"us-south-1", "us-south-2", "us-south-3"},
},
"eu-de": {
Description: "Frankfurt, Germany",
VPCRegion: "eu-de",
COSRegion: "eu-de",
Zones: []string{
"eu-de-1",
"eu-de-2",
},
SysTypes: []string{"s922", "e980"},
VPCZones: []string{"eu-de-1", "eu-de-2", "eu-de-3"},
},
"lon": {
Description: "London, UK.",
VPCRegion: "eu-gb",
COSRegion: "eu-gb",
Zones: []string{
"lon04",
"lon06",
},
SysTypes: []string{"s922", "e980"},
VPCZones: []string{"eu-gb-1", "eu-gb-2", "eu-gb-3"},
},
"mad": {
Description: "Madrid, Spain",
VPCRegion: "eu-es",
COSRegion: "eu-de", // @HACK - PowerVS says COS not supported in this region
Zones: []string{
"mad02",
"mad04",
},
SysTypes: []string{"s1022", "e980"},
VPCZones: []string{"eu-es-1", "eu-es-2", "eu-es-3"},
},
"mon": {
Description: "Montreal, Canada",
VPCRegion: "",
COSRegion: "ca-tor",
Zones: []string{"mon01"},
SysTypes: []string{"s922", "e980"},
VPCZones: []string{},
},
"osa": {
Description: "Osaka, Japan",
VPCRegion: "jp-osa",
COSRegion: "jp-osa",
Zones: []string{"osa21"},
SysTypes: []string{"s922", "e980"},
VPCZones: []string{"jp-osa-1", "jp-osa-2", "jp-osa-3"},
},
"sao": {
Description: "São Paulo, Brazil",
VPCRegion: "br-sao",
COSRegion: "br-sao",
Zones: []string{
"sao01",
"sao04",
},
SysTypes: []string{"s922", "e980"},
VPCZones: []string{"br-sao-1", "br-sao-2", "br-sao-3"},
},
"syd": {
Description: "Sydney, Australia",
VPCRegion: "au-syd",
COSRegion: "au-syd",
Zones: []string{
"syd04",
"syd05",
},
SysTypes: []string{"s922", "e980"},
VPCZones: []string{"au-syd-1", "au-syd-2", "au-syd-3"},
},
"tok": {
Description: "Tokyo, Japan",
VPCRegion: "jp-tok",
COSRegion: "jp-tok",
Zones: []string{"tok04"},
SysTypes: []string{"s922", "e980", "s1022"},
VPCZones: []string{"jp-tok-1", "jp-tok-2", "jp-tok-3"},
},
"tor": {
Description: "Toronto, Canada",
VPCRegion: "ca-tor",
COSRegion: "ca-tor",
Zones: []string{"tor01"},
SysTypes: []string{"s922", "e980"},
VPCZones: []string{"ca-tor-1", "ca-tor-2", "ca-tor-3"},
}, // Keeping us-east and us-south zones as individual entries to easily map the respective VPC and COS regions by matching the prefix of the zone like in GetRegion()
"us-east": {
Description: "Washington DC, USA",
VPCRegion: "us-east",
COSRegion: "us-east",
Zones: []string{"us-east"},
SysTypes: []string{"s922", "e980"},
VPCZones: []string{"us-east-1", "us-east-2", "us-east-3"},
},
"us-south": {
Description: "Dallas, USA",
VPCRegion: "us-south",
COSRegion: "us-south",
Zones: []string{
"us-south",
},
SysTypes: []string{"s922", "e980", "e880"},
VPCZones: []string{"us-south-1", "us-south-2", "us-south-3"},
},
"wdc": {
Description: "Washington DC, USA",
VPCRegion: "us-east",
COSRegion: "us-east",
Zones: []string{
"wdc06",
"wdc07",
},
SysTypes: []string{"s922", "e980"},
VPCZones: []string{"us-east-1", "us-east-2", "us-east-3"},
},
"che": {
Description: "Chennai, India",
VPCRegion: "",
COSRegion: "",
Zones: []string{
"che01",
},
SysTypes: []string{"s922", "e980"},
VPCZones: []string{},
},
}
// COSRegionForVPCRegion returns the corresponding COS region for the given VPC region
func COSRegionForVPCRegion(vpcRegion string) (string, error) {
for r := range Regions {
if vpcRegion == Regions[r].VPCRegion {
return Regions[r].COSRegion, nil
}
}
return "", fmt.Errorf("COS region corresponding to a VPC region %s not found ", vpcRegion)
}
// VPCRegionForPowerVSRegion returns the VPC region for the specified PowerVS region.
func VPCRegionForPowerVSRegion(region string) (string, error) {
if r, ok := Regions[region]; ok {
return r.VPCRegion, nil
}
return "", fmt.Errorf("VPC region corresponding to a PowerVS region %s not found ", region)
}
// COSRegionForPowerVSRegion returns the IBM COS region for the specified PowerVS region.
func COSRegionForPowerVSRegion(region string) (string, error) {
if r, ok := Regions[region]; ok {
return r.COSRegion, nil
}
return "", fmt.Errorf("COS region corresponding to a PowerVS region %s not found ", region)
}
// ValidateVPCRegion validates that given VPC region is known/tested.
func ValidateVPCRegion(region string) bool {
for r := range Regions {
if region == Regions[r].VPCRegion {
return true
}
}
return false
}
// ValidateCOSRegion validates that given COS region is known/tested.
func ValidateCOSRegion(region string) bool {
for r := range Regions {
if region == Regions[r].COSRegion {
return true
}
}
return false
}
// RegionShortNames returns the list of region names
func RegionShortNames() []string {
var keys []string
for r := range Regions {
keys = append(keys, r)
}
return keys
}
// ValidateZone validates that the given zone is known/tested.
func ValidateZone(zone string) bool {
for r := range Regions {
for z := range Regions[r].Zones {
if zone == Regions[r].Zones[z] {
return true
}
}
}
return false
}
// ZoneNames returns the list of zone names.
func ZoneNames() []string {
zones := []string{}
for r := range Regions {
for z := range Regions[r].Zones {
zones = append(zones, Regions[r].Zones[z])
}
}
return zones
}
// RegionFromZone returns the region name for a given zone name.
func RegionFromZone(zone string) string {
for r := range Regions {
for z := range Regions[r].Zones {
if zone == Regions[r].Zones[z] {
return r
}
}
}
return ""
}
// AvailableSysTypes returns the default system type for the zone.
func AvailableSysTypes(region string) ([]string, error) {
knownRegion, ok := Regions[region]
if !ok {
return nil, fmt.Errorf("unknown region name provided")
}
return knownRegion.SysTypes, nil
}
// IsGlobalRoutingRequiredForTG returns true when powervs and vpc regions are different.
func IsGlobalRoutingRequiredForTG(powerVSRegion string, vpcRegion string) bool {
if r, ok := Regions[powerVSRegion]; ok && r.VPCRegion == vpcRegion {
return false
}
return true
}
// VPCZonesForVPCRegion returns the VPC zones associated with the VPC region.
func VPCZonesForVPCRegion(region string) ([]string, error) {
for _, regionDetails := range Regions {
if regionDetails.VPCRegion == region {
return regionDetails.VPCZones, nil
}
}
return nil, fmt.Errorf("VPC zones corresponding to the VPC region %s is not found", region)
}