Merge pull request #8887 from tb365/bugfix/tb-bugfix-1120

Bugfix/tb bugfix 1120
This commit is contained in:
Zexi Li
2020-11-20 19:56:39 +08:00
committed by GitHub
9 changed files with 64 additions and 15 deletions
+2 -1
View File
@@ -187,7 +187,8 @@ func (man *SLoadbalancerBackendManager) ValidateBackendVpc(lb *SLoadbalancer, gu
return httperrors.NewBadRequestError("%s", err)
}
if len(lb.VpcId) > 0 {
if vpc.Id != lb.VpcId {
lbVpc := lb.GetVpc()
if lbVpc != nil && !lbVpc.IsEmulated && vpc.Id != lb.VpcId {
return httperrors.NewBadRequestError("guest %s(%s) vpc %s(%s) not same as loadbalancer vpc %s", guest.Name, guest.Id, vpc.Name, vpc.Id, lb.VpcId)
}
return nil
@@ -114,6 +114,10 @@ func (self *SCachedLoadbalancerCertificate) ValidateDeleteCondition(ctx context.
return nil
}
func (self *SCachedLoadbalancerCertificate) ValidatePurgeCondition(ctx context.Context) error {
return nil
}
func (self *SCachedLoadbalancerCertificate) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
return nil
}
+1 -1
View File
@@ -176,7 +176,7 @@ func (lbcert *SCachedLoadbalancerCertificate) purge(ctx context.Context, userCre
lockman.LockObject(ctx, lbcert)
defer lockman.ReleaseObject(ctx, lbcert)
err := lbcert.ValidateDeleteCondition(ctx)
err := lbcert.ValidatePurgeCondition(ctx)
if err != nil {
return err
}
+3 -3
View File
@@ -1205,6 +1205,7 @@ func (self *SAliyunRegionDriver) ValidateCreateElasticcacheData(ctx context.Cont
// validate sku
billingType, _ := data.GetString("billing_type")
zone := zoneV.Model.(*models.SZone)
network := networkV.Model.(*models.SNetwork)
if sku, err := data.GetString("instance_type"); err != nil || len(sku) == 0 {
return nil, httperrors.NewMissingParameterError("instance_type")
} else {
@@ -1214,7 +1215,7 @@ func (self *SAliyunRegionDriver) ValidateCreateElasticcacheData(ctx context.Cont
}
skuModel := _skuModel.(*models.SElasticcacheSku)
if err := ValidateElasticcacheSku(zone.Id, billingType, skuModel); err != nil {
if err := ValidateElasticcacheSku(zone.Id, billingType, skuModel, network); err != nil {
return nil, err
} else {
data.Set("instance_type", jsonutils.NewString(skuModel.InstanceSpec))
@@ -1238,7 +1239,6 @@ func (self *SAliyunRegionDriver) ValidateCreateElasticcacheData(ctx context.Cont
data.Set("billing_cycle", jsonutils.NewString(cycle.String()))
}
network := networkV.Model.(*models.SNetwork)
vpc := network.GetVpc()
if vpc == nil {
return nil, httperrors.NewNotFoundError("network %s related vpc not found", network.GetId())
@@ -1370,7 +1370,7 @@ func (self *SAliyunRegionDriver) ValidateCreateElasticcacheAccountData(ctx conte
accountPrivilegeV.Value)
}
return data, nil
return self.SManagedVirtualizationRegionDriver.ValidateCreateElasticcacheAccountData(ctx, userCred, ownerId, data)
}
func (self *SAliyunRegionDriver) RequestCreateElasticcacheAccount(ctx context.Context, userCred mcclient.TokenCredential, ea *models.SElasticcacheAccount, task taskman.ITask) error {
+10 -5
View File
@@ -2340,7 +2340,7 @@ func validatorSlaveZones(ownerId mcclient.IIdentityProvider, data *jsonutils.JSO
skuModel := _skuModel.(*models.SElasticcacheSku)
for _, zoneId := range zones {
if err := ValidateElasticcacheSku(zoneId, chargeType, skuModel); err != nil {
if err := ValidateElasticcacheSku(zoneId, chargeType, skuModel, nil); err != nil {
return err
}
}
@@ -2350,11 +2350,17 @@ func validatorSlaveZones(ownerId mcclient.IIdentityProvider, data *jsonutils.JSO
return nil
}
func ValidateElasticcacheSku(zoneId string, chargeType string, sku *models.SElasticcacheSku) error {
func ValidateElasticcacheSku(zoneId string, chargeType string, sku *models.SElasticcacheSku, network *models.SNetwork) error {
if sku.ZoneId != zoneId {
return httperrors.NewResourceNotFoundError("zone mismatch, elastic cache sku zone %s != %s", sku.ZoneId, zoneId)
}
if network != nil {
if zone := network.GetZone(); zone != nil && zone.Id != sku.ZoneId {
return httperrors.NewResourceNotFoundError("elastic cache sku zone (%s) and subnet zone (%s) mismatch", sku.ZoneId, zone.Id)
}
}
if chargeType == billing_api.BILLING_TYPE_PREPAID {
if sku.PrepaidStatus != api.SkuStatusAvailable {
return httperrors.NewOutOfResourceError("sku %s is soldout", sku.Name)
@@ -2409,8 +2415,8 @@ func (self *SHuaWeiRegionDriver) ValidateCreateElasticcacheData(ctx context.Cont
sku := instanceTypeV.Model.(*models.SElasticcacheSku)
zoneId, _ := data.GetString("zone_id")
billingType, _ := data.GetString("billing_type")
if err := ValidateElasticcacheSku(zoneId, billingType, sku); err != nil {
network := networkV.Model.(*models.SNetwork)
if err := ValidateElasticcacheSku(zoneId, billingType, sku, network); err != nil {
return nil, err
} else {
data.Set("instance_type", jsonutils.NewString(sku.InstanceSpec))
@@ -2462,7 +2468,6 @@ func (self *SHuaWeiRegionDriver) ValidateCreateElasticcacheData(ctx context.Cont
data.Set("billing_cycle", jsonutils.NewString(cycle.String()))
}
network := networkV.Model.(*models.SNetwork)
vpc := network.GetVpc()
if vpc == nil {
return nil, httperrors.NewNotFoundError("network %s related vpc not found", network.GetId())
+5 -1
View File
@@ -2289,7 +2289,11 @@ func (self *SManagedVirtualizationRegionDriver) RequestElasticcacheUpdateBackupP
}
func (self *SManagedVirtualizationRegionDriver) ValidateCreateElasticcacheAccountData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
return nil, nil
if name, _ := data.GetString("name"); name == "root" {
return nil, httperrors.NewConflictError("account name 'root' is not allowed")
}
return data, nil
}
func (self *SManagedVirtualizationRegionDriver) ValidateCreateElasticcacheAclData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
+3 -3
View File
@@ -1486,7 +1486,8 @@ func (self *SQcloudRegionDriver) ValidateCreateElasticcacheData(ctx context.Cont
billingType, _ := data.GetString("billing_type")
// validate sku
sku := instanceTypeV.Model.(*models.SElasticcacheSku)
if err := ValidateElasticcacheSku(zoneId, billingType, sku); err != nil {
network := networkV.Model.(*models.SNetwork)
if err := ValidateElasticcacheSku(zoneId, billingType, sku, network); err != nil {
return nil, err
} else {
data.Set("instance_type", jsonutils.NewString(sku.InstanceSpec))
@@ -1528,7 +1529,6 @@ func (self *SQcloudRegionDriver) ValidateCreateElasticcacheData(ctx context.Cont
data.Set("billing_cycle", jsonutils.NewString(cycle.String()))
}
network := networkV.Model.(*models.SNetwork)
vpc := network.GetVpc()
if vpc == nil {
return nil, httperrors.NewNotFoundError("network %s related vpc not found", network.GetId())
@@ -1701,7 +1701,7 @@ func (self *SQcloudRegionDriver) ValidateCreateElasticcacheAccountData(ctx conte
return nil, httperrors.NewWeakPasswordError()
}
return data, nil
return self.SManagedVirtualizationRegionDriver.ValidateCreateElasticcacheAccountData(ctx, userCred, ownerId, data)
}
func (self *SQcloudRegionDriver) RequestCreateElasticcacheAccount(ctx context.Context, userCred mcclient.TokenCredential, ea *models.SElasticcacheAccount, task taskman.ITask) error {
@@ -882,7 +882,8 @@ func (self *SElasticcache) GetSecurityGroupIds() ([]string, error) {
func (self *SElasticcache) GetICloudElasticcacheAccount(accountId string) (cloudprovider.ICloudElasticcacheAccount, error) {
segs := strings.Split(accountId, "/")
if len(segs) < 2 {
return nil, errors.Wrap(fmt.Errorf("%s", accountId), "elasticcache.GetICloudElasticcacheAccount invalid account id ")
log.Debugf("elasticcache.GetICloudElasticcacheAccount invalid account id %s", accountId)
return nil, errors.Wrap(cloudprovider.ErrNotFound, "invalid account id")
}
return self.GetICloudElasticcacheAccountByName(segs[1])
@@ -16,6 +16,7 @@ package provider
import (
"context"
"strings"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
@@ -174,6 +175,33 @@ func (self *SAliyunProviderFactory) ValidateUpdateCloudaccountCredential(ctx con
return output, nil
}
func validateClientCloudenv(client *aliyun.SAliyunClient) error {
regions := client.GetIRegions()
if len(regions) == 0 {
return nil
}
isFinanceAccount := false
for i := range regions {
if strings.Contains(regions[i].GetId(), "-finance") {
isFinanceAccount = true
break
}
}
if isFinanceAccount {
if regions[0].GetCloudEnv() != "FinanceCloud" {
return errors.Wrap(httperrors.ErrInvalidCredential, "aksk is aliyun finance account")
}
} else {
if regions[0].GetCloudEnv() == "FinanceCloud" {
return errors.Wrap(httperrors.ErrInvalidCredential, "aksk is not aliyun finance account")
}
}
return nil
}
func (self *SAliyunProviderFactory) GetProvider(cfg cloudprovider.ProviderConfig) (cloudprovider.ICloudProvider, error) {
client, err := aliyun.NewAliyunClient(
aliyun.NewAliyunClientConfig(
@@ -185,6 +213,12 @@ func (self *SAliyunProviderFactory) GetProvider(cfg cloudprovider.ProviderConfig
if err != nil {
return nil, err
}
err = validateClientCloudenv(client)
if err != nil {
return nil, errors.Wrap(err, "validateClientCloudenv")
}
return &SAliyunProvider{
SBaseProvider: cloudprovider.NewBaseProvider(self),
client: client,