From da2b12a11a8b68e194cc9fd43816579262584c04 Mon Sep 17 00:00:00 2001 From: Reed O'Brien Date: Thu, 9 Feb 2017 13:21:26 -0800 Subject: [PATCH] Add a method to filter unsupported instance types Refs: https://bugs.launchpad.net/juju/+bug/1663047 --- .../internal/ec2instancetypes/generated.go | 145 +----------------- .../ec2instancetypes/process_cost_data.go | 29 +++- 2 files changed, 25 insertions(+), 149 deletions(-) diff --git a/provider/ec2/internal/ec2instancetypes/generated.go b/provider/ec2/internal/ec2instancetypes/generated.go index b9c7fbf3a4f..87ead9bc34f 100644 --- a/provider/ec2/internal/ec2instancetypes/generated.go +++ b/provider/ec2/internal/ec2instancetypes/generated.go @@ -1,4 +1,4 @@ -// Copyright 2016 Canonical Ltd. +// Copyright 2017 Canonical Ltd. // Licensed under the AGPLv3, see LICENCE file for details. package ec2instancetypes @@ -795,19 +795,6 @@ var allInstanceTypes = map[string][]instances.InstanceType{ "ap-northeast-2": { - // SKU: 3MBNRY22Y6A2W6WY - // Instance family: General purpose - // Storage: 1 x 4 SSD - { - Name: "m3.medium", - Arches: amd64, - CpuCores: 1, - CpuPower: instances.CpuPower(350), - Mem: 3840, - VirtType: &hvm, - Cost: 91, - }, - // SKU: 3UWMR4BVSMJ3PTQ5 // Instance family: Storage optimized // Storage: 1 x 800 SSD @@ -821,19 +808,6 @@ var allInstanceTypes = map[string][]instances.InstanceType{ Cost: 1000, }, - // SKU: 45D7HY2M47KUYJXR - // Instance family: Compute optimized - // Storage: 2 x 320 SSD - { - Name: "c3.8xlarge", - Arches: amd64, - CpuCores: 32, - CpuPower: instances.CpuPower(12543), - Mem: 61440, - VirtType: &hvm, - Cost: 1839, - }, - // SKU: 5CB9VHZSJWQTZN3W // Instance family: Compute optimized // Storage: EBS only @@ -873,19 +847,6 @@ var allInstanceTypes = map[string][]instances.InstanceType{ Cost: 19341, }, - // SKU: 6K25ZNG5NAXQC5AB - // Instance family: GPU instance - // Storage: 1 x 60 SSD - { - Name: "g2.2xlarge", - Arches: amd64, - CpuCores: 8, - CpuPower: instances.CpuPower(2911), - Mem: 15360, - VirtType: &hvm, - Cost: 898, - }, - // SKU: 6NSPY3BTJRX47KWG // Instance family: General purpose // Storage: EBS only @@ -925,32 +886,6 @@ var allInstanceTypes = map[string][]instances.InstanceType{ Cost: 200, }, - // SKU: 7GTTQXNXREPMU7WY - // Instance family: General purpose - // Storage: 2 x 40 SSD - { - Name: "m3.xlarge", - Arches: amd64, - CpuCores: 4, - CpuPower: instances.CpuPower(1400), - Mem: 15360, - VirtType: &hvm, - Cost: 366, - }, - - // SKU: 7MQ7AMJWV8BPWH88 - // Instance family: Compute optimized - // Storage: 2 x 160 SSD - { - Name: "c3.4xlarge", - Arches: amd64, - CpuCores: 16, - CpuPower: instances.CpuPower(6271), - Mem: 30720, - VirtType: &hvm, - Cost: 919, - }, - // SKU: 7VFMGFAWZ9QPBHST // Instance family: General purpose // Storage: EBS only @@ -977,19 +912,6 @@ var allInstanceTypes = map[string][]instances.InstanceType{ Cost: 844, }, - // SKU: 98ZFCFAZXXRGF7CG - // Instance family: GPU instance - // Storage: 2 x 120 SSD - { - Name: "g2.8xlarge", - Arches: amd64, - CpuCores: 32, - CpuPower: instances.CpuPower(11647), - Mem: 61440, - VirtType: &hvm, - Cost: 3592, - }, - // SKU: 9DY7H84NVAJTABAD // Instance family: General purpose // Storage: EBS only @@ -1068,32 +990,6 @@ var allInstanceTypes = map[string][]instances.InstanceType{ Cost: 128, }, - // SKU: CFXCUT5A22XNZ43Y - // Instance family: Compute optimized - // Storage: 2 x 16 SSD - { - Name: "c3.large", - Arches: both, - CpuCores: 2, - CpuPower: instances.CpuPower(783), - Mem: 3840, - VirtType: &hvm, - Cost: 115, - }, - - // SKU: DTEVN35HD43BM5ST - // Instance family: General purpose - // Storage: 2 x 80 SSD - { - Name: "m3.2xlarge", - Arches: amd64, - CpuCores: 8, - CpuPower: instances.CpuPower(2800), - Mem: 30720, - VirtType: &hvm, - Cost: 732, - }, - // SKU: EGXGRBT8ERK49SBP // Instance family: General purpose // Storage: EBS only @@ -1159,19 +1055,6 @@ var allInstanceTypes = map[string][]instances.InstanceType{ Cost: 1688, }, - // SKU: K79C7JVTDAKRA842 - // Instance family: General purpose - // Storage: 1 x 32 SSD - { - Name: "m3.large", - Arches: amd64, - CpuCores: 2, - CpuPower: instances.CpuPower(700), - Mem: 7680, - VirtType: &hvm, - Cost: 183, - }, - // SKU: KF2B96YA25ZRC292 // Instance family: Memory optimized // Storage: 1 x 1,920 @@ -1289,32 +1172,6 @@ var allInstanceTypes = map[string][]instances.InstanceType{ Cost: 32, }, - // SKU: R7GFV82WRF8QTZYP - // Instance family: Compute optimized - // Storage: 2 x 40 SSD - { - Name: "c3.xlarge", - Arches: amd64, - CpuCores: 4, - CpuPower: instances.CpuPower(1567), - Mem: 7680, - VirtType: &hvm, - Cost: 230, - }, - - // SKU: RM2KHQ9S45BW6B7M - // Instance family: Compute optimized - // Storage: 2 x 80 SSD - { - Name: "c3.2xlarge", - Arches: amd64, - CpuCores: 8, - CpuPower: instances.CpuPower(3135), - Mem: 15360, - VirtType: &hvm, - Cost: 460, - }, - // SKU: WFBUYA3WPRPDVNEH // Instance family: Storage optimized // Storage: 12 x 2000 HDD diff --git a/provider/ec2/internal/ec2instancetypes/process_cost_data.go b/provider/ec2/internal/ec2instancetypes/process_cost_data.go index 953b5bba595..713535dfe9b 100644 --- a/provider/ec2/internal/ec2instancetypes/process_cost_data.go +++ b/provider/ec2/internal/ec2instancetypes/process_cost_data.go @@ -73,7 +73,7 @@ func Main() (int, error) { defer fout.Close() } - tmpl, err := template.New("instanceTypes").Parse(` + tmpl := template.Must(template.New("instanceTypes").Parse(` // Copyright {{.Year}} Canonical Ltd. // Licensed under the AGPLv3, see LICENCE file for details. @@ -117,10 +117,7 @@ var allInstanceTypes = map[string][]instances.InstanceType{ {{end}}{{end}} }, {{end}} -}`) - if err != nil { - panic(err) - } +}`)) fmt.Fprintln(os.Stderr, "Processing", infilename) instanceTypes, meta, err := process(fin) @@ -247,6 +244,10 @@ func process(in io.Reader) (map[string][]instanceType, metadata, error) { if !ok { return nil, metadata{}, errors.Errorf("unknown location %q", productInfo.Location) } + if !supported(region, instanceType.Name) { + continue + } + regionInstanceTypes := instanceTypes[region] regionInstanceTypes = append(regionInstanceTypes, instanceType) instanceTypes[region] = regionInstanceTypes @@ -254,6 +255,24 @@ func process(in io.Reader) (map[string][]instanceType, metadata, error) { return instanceTypes, meta, nil } +// It appears that instances sometimes show up in the offer list which aren't +// available in actual regions. e.g. m3.medium is in the offer list for +// ap-northeast-2, but attempting to launch one returns an unsupported error. +// See: https://bugs.launchpad.net/juju/+bug/1663047 +func supported(region, instanceType string) bool { + switch region { + case "ap-northeast-2": + switch instanceType[:2] { + case "c3", "g2", "m3": + return false + default: + return true + } + default: + return true + } +} + func calculateCPUPower(info productInfo) (uint64, error) { // T-class instances have burstable CPU. This is not captured // in the pricing information, so we have to hard-code it. We