From 208adf8a02130a94869fb9e464eabbfcdea69a76 Mon Sep 17 00:00:00 2001 From: TangBin Date: Tue, 15 Dec 2020 14:42:17 +0800 Subject: [PATCH] fix(region): aws create storage type fix --- pkg/apis/compute/storage_const.go | 3 ++- pkg/compute/guestdrivers/aws.go | 6 ++++-- pkg/compute/hostdrivers/aws.go | 2 +- pkg/compute/models/capabilities.go | 6 +++++- pkg/multicloud/aws/zone.go | 6 +++++- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/pkg/apis/compute/storage_const.go b/pkg/apis/compute/storage_const.go index 9ed4f15e4c..960a2d971c 100644 --- a/pkg/apis/compute/storage_const.go +++ b/pkg/apis/compute/storage_const.go @@ -45,6 +45,7 @@ const ( // aws storage type STORAGE_GP2_SSD = "gp2" // aws general purpose ssd + STORAGE_GP3_SSD = "gp3" // aws General Purpose SSD (gp3) STORAGE_IO1_SSD = "io1" // aws Provisioned IOPS SSD STORAGE_IO2_SSD = "io2" // aws Provisioned IOPS 2 SSD STORAGE_ST1_HDD = "st1" // aws Throughput Optimized HDD @@ -125,7 +126,7 @@ var ( STORAGE_PUBLIC_CLOUD, STORAGE_CLOUD_SSD, STORAGE_CLOUD_ESSD, STORAGE_CLOUD_ESSD_PL2, STORAGE_CLOUD_ESSD_PL3, STORAGE_EPHEMERAL_SSD, STORAGE_CLOUD_EFFICIENCY, STORAGE_STANDARD_LRS, STORAGE_STANDARDSSD_LRS, STORAGE_PREMIUM_LRS, - STORAGE_GP2_SSD, STORAGE_IO1_SSD, STORAGE_ST1_HDD, STORAGE_SC1_HDD, STORAGE_STANDARD_HDD, + STORAGE_GP2_SSD, STORAGE_GP3_SSD, STORAGE_IO1_SSD, STORAGE_ST1_HDD, STORAGE_SC1_HDD, STORAGE_STANDARD_HDD, STORAGE_LOCAL_BASIC, STORAGE_LOCAL_SSD, STORAGE_CLOUD_BASIC, STORAGE_CLOUD_PREMIUM, STORAGE_HUAWEI_SSD, STORAGE_HUAWEI_SAS, STORAGE_HUAWEI_SATA, STORAGE_OPENSTACK_ISCSI, STORAGE_UCLOUD_CLOUD_NORMAL, STORAGE_UCLOUD_CLOUD_SSD, diff --git a/pkg/compute/guestdrivers/aws.go b/pkg/compute/guestdrivers/aws.go index 374a6acc9c..533fca11e5 100644 --- a/pkg/compute/guestdrivers/aws.go +++ b/pkg/compute/guestdrivers/aws.go @@ -103,6 +103,7 @@ func (self *SAwsGuestDriver) GetInstanceCapability() cloudprovider.SInstanceCapa Storages: cloudprovider.Storage{ DataDisk: []cloudprovider.StorageInfo{ cloudprovider.StorageInfo{StorageType: api.STORAGE_GP2_SSD, MaxSizeGb: 16384, MinSizeGb: 1, StepSizeGb: 1, Resizable: true}, + cloudprovider.StorageInfo{StorageType: api.STORAGE_GP3_SSD, MaxSizeGb: 16384, MinSizeGb: 1, StepSizeGb: 1, Resizable: true}, cloudprovider.StorageInfo{StorageType: api.STORAGE_IO1_SSD, MaxSizeGb: 16384, MinSizeGb: 4, StepSizeGb: 1, Resizable: true}, cloudprovider.StorageInfo{StorageType: api.STORAGE_ST1_HDD, MaxSizeGb: 16384, MinSizeGb: 500, StepSizeGb: 1, Resizable: true}, cloudprovider.StorageInfo{StorageType: api.STORAGE_SC1_HDD, MaxSizeGb: 16384, MinSizeGb: 500, StepSizeGb: 1, Resizable: true}, @@ -157,6 +158,7 @@ func (self *SAwsGuestDriver) GetMinimalSysDiskSizeGb() int { func (self *SAwsGuestDriver) GetStorageTypes() []string { return []string{ api.STORAGE_GP2_SSD, + api.STORAGE_GP3_SSD, api.STORAGE_IO1_SSD, api.STORAGE_IO2_SSD, api.STORAGE_ST1_HDD, @@ -215,10 +217,10 @@ func (self *SAwsGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *mode if !utils.IsInStringArray(guest.Status, []string{api.VM_RUNNING, api.VM_READY}) { return fmt.Errorf("Cannot resize disk when guest in status %s", guest.Status) } - if disk.DiskType == api.DISK_TYPE_SYS && !utils.IsInStringArray(storage.StorageType, []string{api.STORAGE_IO1_SSD, api.STORAGE_IO2_SSD, api.STORAGE_STANDARD_HDD, api.STORAGE_GP2_SSD}) { + if disk.DiskType == api.DISK_TYPE_SYS && !utils.IsInStringArray(storage.StorageType, []string{api.STORAGE_IO1_SSD, api.STORAGE_IO2_SSD, api.STORAGE_STANDARD_HDD, api.STORAGE_GP2_SSD, api.STORAGE_GP3_SSD}) { return fmt.Errorf("Cannot resize system disk with unsupported volumes type %s", storage.StorageType) } - if !utils.IsInStringArray(storage.StorageType, []string{api.STORAGE_GP2_SSD, api.STORAGE_IO1_SSD, api.STORAGE_IO2_SSD, api.STORAGE_ST1_HDD, api.STORAGE_SC1_HDD, api.STORAGE_STANDARD_HDD}) { + if !utils.IsInStringArray(storage.StorageType, []string{api.STORAGE_GP2_SSD, api.STORAGE_GP3_SSD, api.STORAGE_IO1_SSD, api.STORAGE_IO2_SSD, api.STORAGE_ST1_HDD, api.STORAGE_SC1_HDD, api.STORAGE_STANDARD_HDD}) { return fmt.Errorf("Cannot resize %s disk", storage.StorageType) } return nil diff --git a/pkg/compute/hostdrivers/aws.go b/pkg/compute/hostdrivers/aws.go index 6fbe76d78c..e62eaddb90 100644 --- a/pkg/compute/hostdrivers/aws.go +++ b/pkg/compute/hostdrivers/aws.go @@ -45,7 +45,7 @@ func (self *SAwsHostDriver) GetHypervisor() string { } func (self *SAwsHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb int) error { - if storage.StorageType == api.STORAGE_GP2_SSD { + if storage.StorageType == api.STORAGE_GP2_SSD || storage.StorageType == api.STORAGE_GP3_SSD { if sizeGb < 1 || sizeGb > 16384 { return fmt.Errorf("The %s disk size must be in the range of 1G ~ 16384GB", storage.StorageType) } diff --git a/pkg/compute/models/capabilities.go b/pkg/compute/models/capabilities.go index 7e02898d27..a204fb26ae 100644 --- a/pkg/compute/models/capabilities.go +++ b/pkg/compute/models/capabilities.go @@ -515,7 +515,11 @@ func getStorageTypes( if !ok { sts = make([]string, 0) } - sts = append(sts, storageType) + + if !utils.IsInStringArray(storageType, sts) { + sts = append(sts, storageType) + } + hypervisorStorageTypes[storageHypervisor] = sts } addStorageInfo = func(storage *StorageInfo, simpleStorage *SimpleStorageInfo) { diff --git a/pkg/multicloud/aws/zone.go b/pkg/multicloud/aws/zone.go index 91e5b01886..7be6238883 100644 --- a/pkg/multicloud/aws/zone.go +++ b/pkg/multicloud/aws/zone.go @@ -66,7 +66,11 @@ func (self *SZone) getHost() *SHost { func (self *SZone) getStorageType() { if len(self.storageTypes) == 0 { self.storageTypes = StorageTypes - if !utils.IsInStringArray(self.GetId(), []string{"af-south-1", "eu-south-1", "eu-west-3", "sa-east-1", "cn-north-1", "cn-northwest-1"}) { + if utils.IsInStringArray(self.region.GetId(), []string{"cn-north-1", "cn-northwest-1"}) { + self.storageTypes = append(self.storageTypes, api.STORAGE_GP3_SSD) + } + + if !utils.IsInStringArray(self.region.GetId(), []string{"af-south-1", "eu-south-1", "eu-west-3", "sa-east-1", "cn-north-1", "cn-northwest-1"}) { self.storageTypes = append(self.storageTypes, api.STORAGE_IO2_SSD) } }