github.com/openshift/installer@v1.4.17/pkg/types/powervs/powervs_regions.go (about)

     1  package powervs
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"k8s.io/apimachinery/pkg/util/sets"
     7  )
     8  
     9  // Since there is no API to query these, we have to hard-code them here.
    10  
    11  // Region describes resources associated with a region in Power VS.
    12  // We're using a few items from the IBM Cloud VPC offering. The region names
    13  // for VPC are different so another function of this is to correlate those.
    14  type Region struct {
    15  	Description string
    16  	VPCRegion   string
    17  	COSRegion   string
    18  	Zones       []string
    19  	SysTypes    []string
    20  	VPCZones    []string
    21  }
    22  
    23  // Regions holds the regions for IBM Power VS, and descriptions used during the survey.
    24  var Regions = map[string]Region{
    25  	"dal": {
    26  		Description: "Dallas, USA",
    27  		VPCRegion:   "us-south",
    28  		COSRegion:   "us-south",
    29  		Zones:       []string{"dal10", "dal12"},
    30  		SysTypes:    []string{"s922", "e980"},
    31  		VPCZones:    []string{"us-south-1", "us-south-2", "us-south-3"},
    32  	},
    33  	"eu-de": {
    34  		Description: "Frankfurt, Germany",
    35  		VPCRegion:   "eu-de",
    36  		COSRegion:   "eu-de",
    37  		Zones:       []string{"eu-de-1", "eu-de-2"},
    38  		SysTypes:    []string{"s922", "e980"},
    39  		VPCZones:    []string{"eu-de-2", "eu-de-3"},
    40  	},
    41  	"lon": {
    42  		Description: "London, UK",
    43  		VPCRegion:   "eu-gb",
    44  		COSRegion:   "eu-gb",
    45  		Zones:       []string{"lon06"},
    46  		SysTypes:    []string{"s922", "e980"},
    47  		VPCZones:    []string{"eu-gb-1", "eu-gb-2", "eu-gb-3"},
    48  	},
    49  	"mad": {
    50  		Description: "Madrid, Spain",
    51  		VPCRegion:   "eu-es",
    52  		COSRegion:   "eu-de", // @HACK - PowerVS says COS not supported in this region
    53  		Zones:       []string{"mad02", "mad04"},
    54  		SysTypes:    []string{"s1022"},
    55  		VPCZones:    []string{"eu-es-1", "eu-es-2"},
    56  	},
    57  	"osa": {
    58  		Description: "Osaka, Japan",
    59  		VPCRegion:   "jp-osa",
    60  		COSRegion:   "jp-osa",
    61  		Zones:       []string{"osa21"},
    62  		SysTypes:    []string{"s922", "e980"},
    63  		VPCZones:    []string{"jp-osa-1", "jp-osa-2", "jp-osa-3"},
    64  	},
    65  	"sao": {
    66  		Description: "São Paulo, Brazil",
    67  		VPCRegion:   "br-sao",
    68  		COSRegion:   "br-sao",
    69  		Zones:       []string{"sao01", "sao04"},
    70  		SysTypes:    []string{"s922", "e980"},
    71  		VPCZones:    []string{"br-sao-1", "br-sao-2", "br-sao-3"},
    72  	},
    73  	"syd": {
    74  		Description: "Sydney, Australia",
    75  		VPCRegion:   "au-syd",
    76  		COSRegion:   "au-syd",
    77  		Zones:       []string{"syd04"},
    78  		SysTypes:    []string{"s922", "e980"},
    79  		VPCZones:    []string{"au-syd-1", "au-syd-2", "au-syd-3"},
    80  	},
    81  	"wdc": {
    82  		Description: "Washington DC, USA",
    83  		VPCRegion:   "us-east",
    84  		COSRegion:   "us-east",
    85  		Zones:       []string{"wdc06", "wdc07"},
    86  		SysTypes:    []string{"s922", "e980"},
    87  		VPCZones:    []string{"us-east-1", "us-east-2", "us-east-3"},
    88  	},
    89  }
    90  
    91  // VPCRegionForPowerVSRegion returns the VPC region for the specified PowerVS region.
    92  func VPCRegionForPowerVSRegion(region string) (string, error) {
    93  	if r, ok := Regions[region]; ok {
    94  		return r.VPCRegion, nil
    95  	}
    96  
    97  	return "", fmt.Errorf("VPC region corresponding to a PowerVS region %s not found ", region)
    98  }
    99  
   100  // RegionShortNames returns the list of region names
   101  func RegionShortNames() []string {
   102  	keys := make([]string, len(Regions))
   103  	i := 0
   104  	for r := range Regions {
   105  		keys[i] = r
   106  		i++
   107  	}
   108  	return keys
   109  }
   110  
   111  // ValidateVPCRegion validates that given VPC region is known/tested.
   112  func ValidateVPCRegion(region string) bool {
   113  	found := false
   114  	for r := range Regions {
   115  		if region == Regions[r].VPCRegion {
   116  			found = true
   117  			break
   118  		}
   119  	}
   120  	return found
   121  }
   122  
   123  // ValidateZone validates that the given zone is known/tested.
   124  func ValidateZone(zone string) bool {
   125  	for r := range Regions {
   126  		for z := range Regions[r].Zones {
   127  			if zone == Regions[r].Zones[z] {
   128  				return true
   129  			}
   130  		}
   131  	}
   132  	return false
   133  }
   134  
   135  // ZoneNames returns the list of zone names.
   136  func ZoneNames() []string {
   137  	zones := []string{}
   138  	for r := range Regions {
   139  		for z := range Regions[r].Zones {
   140  			zones = append(zones, Regions[r].Zones[z])
   141  		}
   142  	}
   143  	return zones
   144  }
   145  
   146  // RegionFromZone returns the region name for a given zone name.
   147  func RegionFromZone(zone string) string {
   148  	for r := range Regions {
   149  		for z := range Regions[r].Zones {
   150  			if zone == Regions[r].Zones[z] {
   151  				return r
   152  			}
   153  		}
   154  	}
   155  	return ""
   156  }
   157  
   158  // AvailableSysTypes returns the default system type for the zone.
   159  func AvailableSysTypes(region string) ([]string, error) {
   160  	knownRegion, ok := Regions[region]
   161  	if !ok {
   162  		return nil, fmt.Errorf("unknown region name provided")
   163  	}
   164  	return knownRegion.SysTypes, nil
   165  }
   166  
   167  // AllKnownSysTypes returns aggregated known system types from all regions.
   168  func AllKnownSysTypes() sets.Set[string] {
   169  	sysTypes := sets.New[string]()
   170  	for _, region := range Regions {
   171  		sysTypes.Insert(region.SysTypes...)
   172  	}
   173  	return sysTypes
   174  }
   175  
   176  // AvailableVPCZones returns the known VPC zones for a specified region.
   177  func AvailableVPCZones(region string) ([]string, error) {
   178  	knownRegion, ok := Regions[region]
   179  	if !ok {
   180  		return nil, fmt.Errorf("unknown region name provided")
   181  	}
   182  	return knownRegion.VPCZones, nil
   183  }
   184  
   185  // COSRegionForVPCRegion returns the corresponding COS region for the given VPC region.
   186  func COSRegionForVPCRegion(vpcRegion string) (string, error) {
   187  	for r := range Regions {
   188  		if vpcRegion == Regions[r].VPCRegion {
   189  			return Regions[r].COSRegion, nil
   190  		}
   191  	}
   192  
   193  	return "", fmt.Errorf("COS region corresponding to a VPC region %s not found ", vpcRegion)
   194  }
   195  
   196  // COSRegionForPowerVSRegion returns the IBM COS region for the specified PowerVS region.
   197  func COSRegionForPowerVSRegion(region string) (string, error) {
   198  	if r, ok := Regions[region]; ok {
   199  		return r.COSRegion, nil
   200  	}
   201  
   202  	return "", fmt.Errorf("COS region corresponding to a PowerVS region %s not found ", region)
   203  }
   204  
   205  // ValidateCOSRegion validates that given COS region is known/tested.
   206  func ValidateCOSRegion(region string) bool {
   207  	for r := range Regions {
   208  		if region == Regions[r].COSRegion {
   209  			return true
   210  		}
   211  	}
   212  	return false
   213  }