mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): vpc create validate cidr mask length
This commit is contained in:
@@ -1560,3 +1560,14 @@ func (self *SAliyunRegionDriver) IsSupportedElasticcacheSecgroup() bool {
|
||||
func (self *SAliyunRegionDriver) GetMaxElasticcacheSecurityGroupCount() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (self *SAliyunRegionDriver) ValidateCreateVpcData(ctx context.Context, userCred mcclient.TokenCredential, input api.VpcCreateInput) (api.VpcCreateInput, error) {
|
||||
cidrV := validators.NewIPv4PrefixValidator("cidr_block")
|
||||
if err := cidrV.Validate(jsonutils.Marshal(input).(*jsonutils.JSONDict)); err != nil {
|
||||
return input, err
|
||||
}
|
||||
if cidrV.Value.MaskLen < 17 || cidrV.Value.MaskLen > 29 {
|
||||
return input, httperrors.NewInputParameterError("%s request the mask range should be between 17 and 29", self.GetProvider())
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
@@ -1437,3 +1437,14 @@ func (self *SAwsRegionDriver) IsSecurityGroupBelongVpc() bool {
|
||||
func (self *SAwsRegionDriver) IsCertificateBelongToRegion() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SAwsRegionDriver) ValidateCreateVpcData(ctx context.Context, userCred mcclient.TokenCredential, input api.VpcCreateInput) (api.VpcCreateInput, error) {
|
||||
cidrV := validators.NewIPv4PrefixValidator("cidr_block")
|
||||
if err := cidrV.Validate(jsonutils.Marshal(input).(*jsonutils.JSONDict)); err != nil {
|
||||
return input, err
|
||||
}
|
||||
if cidrV.Value.MaskLen < 16 || cidrV.Value.MaskLen > 28 {
|
||||
return input, httperrors.NewInputParameterError("%s request the mask range should be between 16 and 28", self.GetProvider())
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"yunion.io/x/pkg/util/secrules"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -75,3 +76,14 @@ func (self *SAzureRegionDriver) GetSecurityGroupRuleMaxPriority() int {
|
||||
func (self *SAzureRegionDriver) GetSecurityGroupRuleMinPriority() int {
|
||||
return 100
|
||||
}
|
||||
|
||||
func (self *SAzureRegionDriver) ValidateCreateVpcData(ctx context.Context, userCred mcclient.TokenCredential, input api.VpcCreateInput) (api.VpcCreateInput, error) {
|
||||
cidrV := validators.NewIPv4PrefixValidator("cidr_block")
|
||||
if err := cidrV.Validate(jsonutils.Marshal(input).(*jsonutils.JSONDict)); err != nil {
|
||||
return input, err
|
||||
}
|
||||
if cidrV.Value.MaskLen < 8 || cidrV.Value.MaskLen > 29 {
|
||||
return input, httperrors.NewInputParameterError("%s request the mask range should be between 8 and 29", self.GetProvider())
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"yunion.io/x/pkg/util/secrules"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -75,3 +76,14 @@ func (self *SCtyunRegionDriver) ValidateCreateLoadbalancerAclData(ctx context.Co
|
||||
func (self *SCtyunRegionDriver) ValidateCreateLoadbalancerCertificateData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
return nil, httperrors.NewNotImplementedError("%s does not currently support creating loadbalancer certificate", self.GetProvider())
|
||||
}
|
||||
|
||||
func (self *SCtyunRegionDriver) ValidateCreateVpcData(ctx context.Context, userCred mcclient.TokenCredential, input api.VpcCreateInput) (api.VpcCreateInput, error) {
|
||||
cidrV := validators.NewIPv4PrefixValidator("cidr_block")
|
||||
if err := cidrV.Validate(jsonutils.Marshal(input).(*jsonutils.JSONDict)); err != nil {
|
||||
return input, err
|
||||
}
|
||||
if cidrV.Value.MaskLen < 16 || cidrV.Value.MaskLen > 29 {
|
||||
return input, httperrors.NewInputParameterError("%s request the mask range should be between 16 and 29", self.GetProvider())
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -269,3 +270,14 @@ func (self *SGoogleRegionDriver) RequestCreateDBInstanceBackup(ctx context.Conte
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SGoogleRegionDriver) ValidateCreateVpcData(ctx context.Context, userCred mcclient.TokenCredential, input api.VpcCreateInput) (api.VpcCreateInput, error) {
|
||||
var cidrV = validators.NewIPv4PrefixValidator("cidr_block")
|
||||
if err := cidrV.Validate(jsonutils.Marshal(input).(*jsonutils.JSONDict)); err != nil {
|
||||
return input, err
|
||||
}
|
||||
if cidrV.Value.MaskLen < 8 || cidrV.Value.MaskLen > 29 {
|
||||
return input, httperrors.NewInputParameterError("%s request the mask range should be between 8 and 29", self.GetProvider())
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
@@ -2663,3 +2663,14 @@ func (self *SHuaWeiRegionDriver) GetRdsSupportSecgroupCount() int {
|
||||
func (self *SHuaWeiRegionDriver) IsSupportedElasticcacheAutoRenew() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SHuaWeiRegionDriver) ValidateCreateVpcData(ctx context.Context, userCred mcclient.TokenCredential, input api.VpcCreateInput) (api.VpcCreateInput, error) {
|
||||
var cidrV = validators.NewIPv4PrefixValidator("cidr_block")
|
||||
if err := cidrV.Validate(jsonutils.Marshal(input).(*jsonutils.JSONDict)); err != nil {
|
||||
return input, err
|
||||
}
|
||||
if cidrV.Value.MaskLen < 16 || cidrV.Value.MaskLen > 29 {
|
||||
return input, httperrors.NewInputParameterError("%s request the mask range should be between 16 and 29", self.GetProvider())
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"yunion.io/x/pkg/util/secrules"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -71,3 +72,14 @@ func (self *SUcloudRegionDriver) ValidateCreateLoadbalancerAclData(ctx context.C
|
||||
func (self *SUcloudRegionDriver) ValidateCreateLoadbalancerCertificateData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
return nil, httperrors.NewNotImplementedError("%s does not currently support creating loadbalancer certificate", self.GetProvider())
|
||||
}
|
||||
|
||||
func (self *SUcloudRegionDriver) ValidateCreateVpcData(ctx context.Context, userCred mcclient.TokenCredential, input api.VpcCreateInput) (api.VpcCreateInput, error) {
|
||||
var cidrV = validators.NewIPv4PrefixValidator("cidr_block")
|
||||
if err := cidrV.Validate(jsonutils.Marshal(input).(*jsonutils.JSONDict)); err != nil {
|
||||
return input, err
|
||||
}
|
||||
if cidrV.Value.MaskLen < 16 || cidrV.Value.MaskLen > 29 {
|
||||
return input, httperrors.NewInputParameterError("%s request the mask range should be between 16 and 29", self.GetProvider())
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user