From f2d2495be3faaa0e06bddaa6907b2fd3e43b769a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Wed, 4 Feb 2026 14:57:45 +0800 Subject: [PATCH] fix(region): public cloud sku create (#24229) --- pkg/compute/models/server_skus.go | 47 +++++++++++++++++++------------ 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/pkg/compute/models/server_skus.go b/pkg/compute/models/server_skus.go index 32bcee5ad0..579d0d6456 100644 --- a/pkg/compute/models/server_skus.go +++ b/pkg/compute/models/server_skus.go @@ -320,22 +320,6 @@ func (self *SServerSkuManager) ValidateCreateData(ctx context.Context, userCred region, _ = zone.GetRegion() } - if input.CpuCoreCount < 1 || input.CpuCoreCount > options.Options.SkuMaxCpuCount { - return input, httperrors.NewOutOfRangeError("cpu_core_count should be range of 1~%d", options.Options.SkuMaxCpuCount) - } - - if input.MemorySizeMB < 512 || input.MemorySizeMB > 1024*options.Options.SkuMaxMemSize { - return input, httperrors.NewOutOfRangeError("memory_size_mb, shoud be range of 512~%d", 1024*options.Options.SkuMaxMemSize) - } - - if len(input.InstanceTypeCategory) == 0 { - input.InstanceTypeCategory = api.SkuCategoryGeneralPurpose - } - - if !utils.IsInStringArray(input.InstanceTypeCategory, api.SKU_FAMILIES) { - return input, httperrors.NewInputParameterError("instance_type_category shoud be one of %s", api.SKU_FAMILIES) - } - if input.Enabled == nil { enabled := true input.Enabled = &enabled @@ -346,14 +330,41 @@ func (self *SServerSkuManager) ValidateCreateData(ctx context.Context, userCred if region != nil { input.Provider = region.Provider } + if input.Provider == api.CLOUD_PROVIDER_ONECLOUD { input.CloudregionId = api.DEFAULT_REGION_ID } else if utils.IsInStringArray(input.Provider, api.PRIVATE_CLOUD_PROVIDERS) { input.Status = api.SkuStatusCreating } - input.LocalCategory = input.InstanceTypeCategory - input.InstanceTypeFamily = api.InstanceFamilies[input.InstanceTypeCategory] + if !utils.IsInStringArray(input.Provider, api.PUBLIC_CLOUD_PROVIDERS) { + if input.CpuCoreCount < 1 || input.CpuCoreCount > options.Options.SkuMaxCpuCount { + return input, httperrors.NewOutOfRangeError("cpu_core_count should be range of 1~%d", options.Options.SkuMaxCpuCount) + } + + if input.MemorySizeMB < 512 || input.MemorySizeMB > 1024*options.Options.SkuMaxMemSize { + return input, httperrors.NewOutOfRangeError("memory_size_mb, shoud be range of 512~%d", 1024*options.Options.SkuMaxMemSize) + } + + if len(input.InstanceTypeCategory) == 0 { + input.InstanceTypeCategory = api.SkuCategoryGeneralPurpose + } + + if !utils.IsInStringArray(input.InstanceTypeCategory, api.SKU_FAMILIES) { + return input, httperrors.NewInputParameterError("instance_type_category shoud be one of %s", api.SKU_FAMILIES) + } + + input.LocalCategory = input.InstanceTypeCategory + input.InstanceTypeFamily = api.InstanceFamilies[input.InstanceTypeCategory] + } + + if len(input.LocalCategory) == 0 { + input.LocalCategory = input.InstanceTypeCategory + } + + if len(input.InstanceTypeFamily) == 0 { + input.InstanceTypeFamily = api.InstanceFamilies[input.InstanceTypeCategory] + } var err error if len(input.Name) == 0 {