-
Notifications
You must be signed in to change notification settings - Fork 14
/
region.go
184 lines (173 loc) · 4.04 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
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, "tor"):
region = "tor"
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"
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
}
// 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{"dal12"},
},
"eu-de": {
Description: "Frankfurt, Germany",
VPCRegion: "eu-de",
COSRegion: "eu-de",
Zones: []string{
"eu-de-1",
"eu-de-2",
},
},
"lon": {
Description: "London, UK.",
VPCRegion: "eu-gb",
COSRegion: "eu-gb",
Zones: []string{
"lon04",
"lon06",
},
},
"mad": {
Description: "Madrid, Spain",
VPCRegion: "eu-es",
COSRegion: "eu-es",
Zones: []string{
"mad02",
"mad04",
},
},
"mon": {
Description: "Montreal, Canada",
VPCRegion: "ca-tor",
COSRegion: "ca-tor",
Zones: []string{"mon01"},
},
"osa": {
Description: "Osaka, Japan",
VPCRegion: "jp-osa",
COSRegion: "jp-osa",
Zones: []string{"osa21"},
},
"syd": {
Description: "Sydney, Australia",
VPCRegion: "au-syd",
COSRegion: "au-syd",
Zones: []string{
"syd04",
"syd05",
},
},
"sao": {
Description: "São Paulo, Brazil",
VPCRegion: "br-sao",
COSRegion: "br-sao",
Zones: []string{
"sao01",
"sao04",
},
},
"tok": {
Description: "Tokyo, Japan",
VPCRegion: "jp-tok",
COSRegion: "jp-tok",
Zones: []string{"tok04"},
},
"us-east": {
Description: "Washington DC, USA",
VPCRegion: "us-east",
COSRegion: "us-east",
Zones: []string{"us-east"},
},
"wdc": {
Description: "Washington DC, USA",
VPCRegion: "us-east",
COSRegion: "us-east",
Zones: []string{
"wdc06",
"wdc07",
},
},
}
// 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
}