platform/api/aws: refuse to create PV AMI in unsupported regions
CreatePVImage would previously create an AMI with no AKI ID, and
CopyImage would create an image that never exited pending state.
package aws
import (
+ "errors"
"fmt"
"net/url"
"strings"
@@ -29,6 +30,10 @@ import (
"github.com/aws/aws-sdk-go/service/iam"
)
+var (
+ NoRegionPVSupport = errors.New("Region does not support PV")
+)
+
type EC2ImageType string
const (
@@ -65,6 +70,11 @@ var akis = map[string]string{
"cn-north-1": "aki-9e8f1da7",
}
+func RegionSupportsPV(region string) bool {
+ _, ok := akis[region]
+ return ok
+}
+
func (e *EC2ImageFormat) Set(s string) error {
switch s {
case string(EC2ImageFormatVmdk):
@@ -353,6 +363,9 @@ func (a *API) CreateHVMImage(snapshotID string, name string, description string)
}
func (a *API) CreatePVImage(snapshotID string, name string, description string) (string, error) {
+ if !RegionSupportsPV(a.opts.Region) {
+ return "", NoRegionPVSupport
+ }
params := registerImageParams(snapshotID, name, description, "sd", EC2ImageTypePV)
params.KernelId = aws.String(akis[a.opts.Region])
return a.createImage(params)
@@ -440,6 +453,14 @@ func (a *API) CopyImage(sourceImageID string, regions []string) (map[string]stri
return nil, err
}
+ if *image.VirtualizationType == ec2.VirtualizationTypeParavirtual {
+ for _, region := range regions {
+ if !RegionSupportsPV(region) {
+ return nil, NoRegionPVSupport
+ }
+ }
+ }
+
describeSnapshotRes, err := a.ec2.DescribeSnapshots(&ec2.DescribeSnapshotsInput{
SnapshotIds: []*string{image.BlockDeviceMappings[0].Ebs.SnapshotId},
})
