mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
Merge pull request #629 in YUNIONIO/onecloud from ~TANGBIN/onecloud:feature/tb-kvm-sku-support to release/2.4.0
* commit '8d4266afad4f0174ed88f6586857a070de921a5f': bugfix skus update InstanceTypeCategory chaset
This commit is contained in:
@@ -40,11 +40,13 @@ func init() {
|
||||
CpuCoreCount int `help:"Cpu Count" required:"true" positional:"true"`
|
||||
MemorySizeMB int `help:"Memory MB" required:"true" positional:"true"`
|
||||
|
||||
OsName *string `help:"OS name/type" choices:"Linux|Windows|Any" default:"Any"`
|
||||
SkuFamily *string `help:"sku family"`
|
||||
SkuCategory *string `help:"sku category" choices:"general_purpose|compute_optimized|memory_optimized|storage_optimized|hardware_accelerated|high_memory|high_storage"`
|
||||
|
||||
SysDiskResizable *bool `help:"system disk is resizable"`
|
||||
SysDiskMaxSizeGB *int `help:"system disk maximal size in gb"`
|
||||
SysDiskResizable *bool `help:"system disk is resizable"`
|
||||
SysDiskType *string `help:"system disk type" default:"local" choices:"local"`
|
||||
SysDiskMaxSizeGB *int `help:"system disk maximal size in gb"`
|
||||
|
||||
AttachedDiskType *string `help:"attached data disk type"`
|
||||
AttachedDiskSizeGB *int `help:"attached data disk size in GB"`
|
||||
@@ -59,8 +61,9 @@ func init() {
|
||||
GPUCount *int `help:"GPU count"`
|
||||
GPUAttachable *bool `help:"Allow attach GPU"`
|
||||
|
||||
Zone *string `help:"Zone ID or name"`
|
||||
Region *string `help:"Region ID or name"`
|
||||
Zone *string `help:"Zone ID or name"`
|
||||
Region *string `help:"Region ID or name"`
|
||||
Provider *string `help:"Provider name" choices:"kvm|esxi"`
|
||||
}
|
||||
R(&ServerSkusCreateOptions{}, "server-sku-create", "Create a server sku record", func(s *mcclient.ClientSession, args *ServerSkusCreateOptions) error {
|
||||
params, err := options.StructToParams(args)
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/tristate"
|
||||
@@ -799,7 +798,9 @@ func (manager *SGuestManager) ValidateCreateData(ctx context.Context, userCred m
|
||||
sku_id, _ := data.GetString("sku_id")
|
||||
if len(sku_id) > 0 {
|
||||
sku_id, vcpuCount, vmemSize, err := validateSkuData(sku_id)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2(ServerSkuManager.Keyword(), sku_id)
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -48,12 +48,12 @@ type SServerSku struct {
|
||||
|
||||
// SkuId string `width:"64" charset:"ascii" nullable:"false" list:"user" create:"admin_required"` // x2.large
|
||||
InstanceTypeFamily string `width:"32" charset:"ascii" nullable:"false" list:"user" create:"admin_optional" update:"admin"` // x2
|
||||
InstanceTypeCategory string `width:"32" charset:"ascii" nullable:"false" list:"user" create:"admin_optional" update:"admin"` // 通用型
|
||||
InstanceTypeCategory string `width:"32" charset:"utf8" nullable:"false" list:"user" create:"admin_optional" update:"admin"` // 通用型
|
||||
|
||||
CpuCoreCount int `nullable:"false" list:"user" create:"admin_required" update:"admin"`
|
||||
MemorySizeMB int `nullable:"false" list:"user" create:"admin_required" update:"admin"`
|
||||
|
||||
OsName string `width:"32" charset:"ascii" nullable:"false" list:"user" create:"admin_required" update:"admin"` // windows|linux|any
|
||||
OsName string `width:"32" charset:"ascii" nullable:"false" list:"user" create:"admin_required" update:"admin" default:"Any"` // Windows|Linux|Any
|
||||
|
||||
SysDiskResizable bool `default:"true" nullable:"false" list:"user" create:"admin_optional" update:"admin"`
|
||||
SysDiskType string `width:"32" charset:"ascii" nullable:"false" list:"user" create:"admin_required" update:"admin"`
|
||||
@@ -80,6 +80,16 @@ type SServerSku struct {
|
||||
Provider string `width:"64" charset:"ascii" nullable:"false" list:"user" create:"admin_optional" update:"admin"`
|
||||
}
|
||||
|
||||
func inWhiteList(provider string) bool {
|
||||
// 只有为true的hypervisor才进行创建和更新操作
|
||||
switch provider {
|
||||
case HYPERVISOR_ESXI, HYPERVISOR_KVM:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SServerSkuManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool {
|
||||
return true
|
||||
}
|
||||
@@ -94,6 +104,15 @@ func (self *SServerSkuManager) ValidateCreateData(ctx context.Context,
|
||||
query jsonutils.JSONObject,
|
||||
data *jsonutils.JSONDict,
|
||||
) (*jsonutils.JSONDict, error) {
|
||||
provider, err := data.GetString("provider")
|
||||
if err != nil || len(provider) == 0 {
|
||||
return nil, httperrors.NewMissingParameterError("provider")
|
||||
}
|
||||
|
||||
if !inWhiteList(provider) {
|
||||
return nil, httperrors.NewInputParameterError("can not create with provider %s", provider)
|
||||
}
|
||||
|
||||
regionStr := jsonutils.GetAnyString(data, []string{"region", "region_id", "cloudregion", "cloudregion_id"})
|
||||
if len(regionStr) > 0 {
|
||||
regionObj, err := CloudregionManager.FetchByIdOrName(userCred, regionStr)
|
||||
@@ -151,11 +170,24 @@ func (self *SServerSkuManager) FetchByZoneId(zoneId string, name string) (db.IMo
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SServerSku) AllowUpdateItem(ctx context.Context, userCred mcclient.TokenCredential) bool {
|
||||
if self.SStandaloneResourceBase.AllowUpdateItem(ctx, userCred) == false {
|
||||
return false
|
||||
}
|
||||
|
||||
return inWhiteList(self.Provider)
|
||||
}
|
||||
|
||||
func (self *SServerSku) ValidateUpdateData(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
provider, err := data.GetString("provider")
|
||||
if err == nil && !inWhiteList(provider) {
|
||||
return nil, httperrors.NewInputParameterError("can not create with provider %s", provider)
|
||||
}
|
||||
|
||||
zoneStr := jsonutils.GetAnyString(data, []string{"zone", "zone_id"})
|
||||
if len(zoneStr) > 0 {
|
||||
zoneObj, err := ZoneManager.FetchByIdOrName(userCred, zoneStr)
|
||||
@@ -170,6 +202,19 @@ func (self *SServerSku) ValidateUpdateData(
|
||||
return self.SStandaloneResourceBase.ValidateUpdateData(ctx, userCred, query, data)
|
||||
}
|
||||
|
||||
func (self *SServerSku) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
if !inWhiteList(self.Provider) {
|
||||
return false
|
||||
}
|
||||
|
||||
count := GuestManager.Query().Equals("sku_id", self.Id).Count()
|
||||
if count == 0 {
|
||||
return self.SStandaloneResourceBase.AllowDeleteItem(ctx, userCred, query, data)
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SServerSku) GetZoneExternalId() (string, error) {
|
||||
zoneObj, err := ZoneManager.FetchById(self.ZoneId)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user