mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
+17
-12
@@ -31,6 +31,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"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/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
@@ -96,13 +97,14 @@ func (self *SWire) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenC
|
||||
}
|
||||
|
||||
func (manager *SWireManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
bandwidth, err := data.Int("bandwidth")
|
||||
if err != nil || bandwidth <= 0 {
|
||||
return nil, httperrors.NewInputParameterError("invalid bandwidth")
|
||||
keysV := []validators.IValidator{
|
||||
validators.NewNonNegativeValidator("bandwidth"),
|
||||
validators.NewRangeValidator("mtu", 1, 1000000).Optional(true),
|
||||
}
|
||||
mtu, err := data.Int("mtu")
|
||||
if err != nil || mtu <= 0 {
|
||||
return nil, httperrors.NewInputParameterError("invalid mtu")
|
||||
for _, v := range keysV {
|
||||
if err := v.Validate(data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
vpcStr := jsonutils.GetAnyString(data, []string{"vpc", "vpc_id"})
|
||||
@@ -126,14 +128,17 @@ func (manager *SWireManager) ValidateCreateData(ctx context.Context, userCred mc
|
||||
}
|
||||
|
||||
func (wire *SWire) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
bandwidth, err := data.Int("bandwidth")
|
||||
if err == nil && bandwidth <= 0 {
|
||||
return nil, httperrors.NewInputParameterError("invalid bandwidth")
|
||||
keysV := []validators.IValidator{
|
||||
validators.NewNonNegativeValidator("bandwidth"),
|
||||
validators.NewRangeValidator("mtu", 1, 1000000).Optional(true),
|
||||
}
|
||||
mtu, err := data.Int("mtu")
|
||||
if err == nil && mtu <= 0 {
|
||||
return nil, httperrors.NewInputParameterError("invalid mtu")
|
||||
for _, v := range keysV {
|
||||
v.Optional(true)
|
||||
if err := v.Validate(data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return wire.SStandaloneResourceBase.ValidateUpdateData(ctx, userCred, query, data)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user