Skip to content

Commit

Permalink
Add region mapping config for PowerVS cloud
Browse files Browse the repository at this point in the history
This is to keep the region mapping of PowerVS in common package
  • Loading branch information
dharaneeshvrd committed Jan 18, 2023
1 parent 24668b1 commit 979bb31
Showing 1 changed file with 107 additions and 0 deletions.
107 changes: 107 additions & 0 deletions pkg/config/cloud/powervs/powervs_regions.go
@@ -0,0 +1,107 @@
package powervs

import (
"fmt"
)

// Since there is no API to query these, we have to hard-code them here.

// Region describes resources associated with a region in Power VS.
// We're using a few items from the IBM Cloud VPC offering. The region names
// for VPC are different so another function of this is to correlate those.
type Region struct {
Description string
VPCRegion string
Zones []string
}

// Regions holds the regions for IBM Power VS, and descriptions used during the survey.
var Regions = map[string]Region{
"dal": {
Description: "Dallas, USA",
VPCRegion: "us-south",
Zones: []string{"dal12"},
},
"eu-de": {
Description: "Frankfurt, Germany",
VPCRegion: "eu-de",
Zones: []string{
"eu-de-1",
"eu-de-2",
},
},
"lon": {
Description: "London, UK.",
VPCRegion: "eu-gb",
Zones: []string{
"lon04",
"lon06",
},
},
"mon": {
Description: "Montreal, Canada",
VPCRegion: "ca-tor",
Zones: []string{"mon01"},
},
"osa": {
Description: "Osaka, Japan",
VPCRegion: "jp-osa",
Zones: []string{"osa21"},
},
"syd": {
Description: "Sydney, Australia",
VPCRegion: "au-syd",
Zones: []string{
"syd04",
"syd05",
},
},
"sao": {
Description: "São Paulo, Brazil",
VPCRegion: "br-sao",
Zones: []string{"sao01"},
},
"tor": {
Description: "Toronto, Canada",
VPCRegion: "ca-tor",
Zones: []string{"tor01"},
},
"tok": {
Description: "Tokyo, Japan",
VPCRegion: "jp-tok",
Zones: []string{"tok04"},
},
"us-east": {
Description: "Washington DC, USA",
VPCRegion: "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)
}

// RegionShortNames returns the list of region names
func RegionShortNames() []string {
keys := []string{}
for r := range Regions {
keys = append(keys, r)
}
return keys
}

// 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
}

0 comments on commit 979bb31

Please sign in to comment.