mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
fix: do not set storage-type for prepaid-recycled server
This commit is contained in:
@@ -110,22 +110,25 @@ func (self *SAliyunGuestDriver) ValidateCreateData(ctx context.Context, userCred
|
||||
return nil, httperrors.NewInputParameterError("cannot support more than 1 nic")
|
||||
}
|
||||
for i, disk := range input.Disks {
|
||||
if i == 0 && (disk.SizeMb < 20*1024 || disk.SizeMb > 500*1024) {
|
||||
return nil, httperrors.NewInputParameterError("The system disk size must be in the range of 20GB ~ 500Gb")
|
||||
}
|
||||
minGB := -1
|
||||
maxGB := -1
|
||||
switch disk.Backend {
|
||||
case api.STORAGE_CLOUD_EFFICIENCY, api.STORAGE_CLOUD_SSD, api.STORAGE_CLOUD_ESSD:
|
||||
if disk.SizeMb < 20*1024 || disk.SizeMb > 32768*1024 {
|
||||
return nil, httperrors.NewInputParameterError("The %s disk size must be in the range of 20GB ~ 32768GB", disk.Backend)
|
||||
}
|
||||
minGB = 20
|
||||
maxGB = 32768
|
||||
case api.STORAGE_PUBLIC_CLOUD:
|
||||
if disk.SizeMb < 5*1024 || disk.SizeMb > 2000*1024 {
|
||||
return nil, httperrors.NewInputParameterError("The %s disk size must be in the range of 5GB ~ 2000GB", disk.Backend)
|
||||
}
|
||||
minGB = 5
|
||||
maxGB = 2000
|
||||
case api.STORAGE_EPHEMERAL_SSD:
|
||||
if disk.SizeMb < 5*1024 || disk.SizeMb > 800*1024 {
|
||||
return nil, httperrors.NewInputParameterError("The %s disk size must be in the range of 5GB ~ 800GB", disk.Backend)
|
||||
}
|
||||
minGB = 5
|
||||
maxGB = 800
|
||||
}
|
||||
if i == 0 {
|
||||
minGB = 20
|
||||
maxGB = 500
|
||||
}
|
||||
if disk.SizeMb < minGB*1024 || disk.SizeMb > maxGB*1024 {
|
||||
return nil, httperrors.NewInputParameterError("The %s disk size must be in the range of %dGB ~ %dGB", disk.Backend, minGB, maxGB)
|
||||
}
|
||||
}
|
||||
return input, nil
|
||||
|
||||
@@ -954,17 +954,19 @@ func (manager *SGuestManager) ValidateCreateData(ctx context.Context, userCred m
|
||||
if err != nil {
|
||||
return nil, httperrors.NewGeneralError(err) // should no error
|
||||
}
|
||||
if len(rootDiskConfig.Backend) == 0 {
|
||||
defaultStorageType, _ := data.GetString("default_storage_type")
|
||||
if len(defaultStorageType) > 0 {
|
||||
rootDiskConfig.Backend = defaultStorageType
|
||||
} else {
|
||||
rootDiskConfig.Backend = GetDriver(hypervisor).GetDefaultSysDiskBackend()
|
||||
if input.ResourceType != api.HostResourceTypePrepaidRecycle {
|
||||
if len(rootDiskConfig.Backend) == 0 {
|
||||
defaultStorageType, _ := data.GetString("default_storage_type")
|
||||
if len(defaultStorageType) > 0 {
|
||||
rootDiskConfig.Backend = defaultStorageType
|
||||
} else {
|
||||
rootDiskConfig.Backend = GetDriver(hypervisor).GetDefaultSysDiskBackend()
|
||||
}
|
||||
}
|
||||
sysMinDiskMB := GetDriver(hypervisor).GetMinimalSysDiskSizeGb() * 1024
|
||||
if rootDiskConfig.SizeMb < sysMinDiskMB {
|
||||
rootDiskConfig.SizeMb = sysMinDiskMB
|
||||
}
|
||||
}
|
||||
sysMinDiskMB := GetDriver(hypervisor).GetMinimalSysDiskSizeGb() * 1024
|
||||
if rootDiskConfig.SizeMb < sysMinDiskMB {
|
||||
rootDiskConfig.SizeMb = sysMinDiskMB
|
||||
}
|
||||
log.Debugf("ROOT DISK: %#v", rootDiskConfig)
|
||||
input.Disks[0] = rootDiskConfig
|
||||
@@ -987,26 +989,23 @@ func (manager *SGuestManager) ValidateCreateData(ctx context.Context, userCred m
|
||||
input.Disks[i+1] = diskConfig
|
||||
}
|
||||
|
||||
resourceTypeStr := input.ResourceType
|
||||
durationStr := input.Duration
|
||||
|
||||
if len(durationStr) > 0 {
|
||||
if len(input.Duration) > 0 {
|
||||
|
||||
if !userCred.IsAdminAllow(consts.GetServiceType(), manager.KeywordPlural(), policy.PolicyActionPerform, "renew") {
|
||||
return nil, httperrors.NewForbiddenError("only admin can create prepaid resource")
|
||||
}
|
||||
|
||||
if resourceTypeStr == api.HostResourceTypePrepaidRecycle {
|
||||
if input.ResourceType == api.HostResourceTypePrepaidRecycle {
|
||||
return nil, httperrors.NewConflictError("cannot create prepaid server on prepaid resource type")
|
||||
}
|
||||
|
||||
billingCycle, err := billing.ParseBillingCycle(durationStr)
|
||||
billingCycle, err := billing.ParseBillingCycle(input.Duration)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError("invalid duration %s", durationStr)
|
||||
return nil, httperrors.NewInputParameterError("invalid duration %s", input.Duration)
|
||||
}
|
||||
|
||||
if !GetDriver(hypervisor).IsSupportedBillingCycle(billingCycle) {
|
||||
return nil, httperrors.NewInputParameterError("unsupported duration %s", durationStr)
|
||||
return nil, httperrors.NewInputParameterError("unsupported duration %s", input.Duration)
|
||||
}
|
||||
|
||||
input.BillingType = billing_api.BILLING_TYPE_PREPAID
|
||||
@@ -1088,9 +1087,11 @@ func (manager *SGuestManager) ValidateCreateData(ctx context.Context, userCred m
|
||||
|
||||
}*/
|
||||
|
||||
input, err = GetDriver(hypervisor).ValidateCreateData(ctx, userCred, input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if input.ResourceType != api.HostResourceTypePrepaidRecycle {
|
||||
input, err = GetDriver(hypervisor).ValidateCreateData(ctx, userCred, input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
data, err = manager.SVirtualResourceBaseManager.ValidateCreateData(ctx, userCred, ownerProjId, query, input.JSON(input))
|
||||
@@ -1101,6 +1102,8 @@ func (manager *SGuestManager) ValidateCreateData(ctx context.Context, userCred m
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Debugf("Create data: %s", data)
|
||||
|
||||
if !input.IsSystem {
|
||||
err = manager.checkCreateQuota(ctx, userCred, ownerProjId, input,
|
||||
input.Backup)
|
||||
|
||||
Reference in New Issue
Block a user