mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-24 23:41:52 +08:00
fix(region): create redis validate network and sku zone match
This commit is contained in:
@@ -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())
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user