Skip to content

Commit

Permalink
Add Power VS region to IBM VPC and IBM COS region mapping functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Karthik-K-N committed Mar 6, 2023
1 parent 806332d commit 9de5f67
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 0 deletions.
122 changes: 122 additions & 0 deletions region.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,125 @@ func GetRegion(zone string) (region string, err error) {
}
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",
},
},
"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"},
},
"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"},
},
}

// 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
}
40 changes: 40 additions & 0 deletions region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,43 @@ func TestGetRegion(t *testing.T) {
})
}
}

func TestVPCRegionForPowerVSRegion(t *testing.T) {
type args struct {
region string
}
tests := []struct {
name string
args args
wantRegion string
wantErr bool
}{
{
"Dallas",
args{"dal"},
"us-south",
false,
},
{
"Osaka",
args{"eu-de1"},
"eu-de",
true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
vpcRegion, err := VPCRegionForPowerVSRegion(tt.args.region)

if err != nil {
if !tt.wantErr {
t.Errorf("VPCRegionForPowerVSRegion() error = %v, wantErr %v", err, tt.wantErr)
}
return
}
if vpcRegion != tt.wantRegion {
t.Errorf("VPCRegionForPowerVSRegion() gotRegion = %v, want %v", vpcRegion, tt.wantRegion)
}
})
}
}

0 comments on commit 9de5f67

Please sign in to comment.