diff --git a/pkg/apis/compute/network.go b/pkg/apis/compute/network.go index f6b6ede8a9..4292953be7 100644 --- a/pkg/apis/compute/network.go +++ b/pkg/apis/compute/network.go @@ -187,6 +187,12 @@ type NetworkCreateInput struct { // 是否加入自动分配地址池 IsAutoAlloc *bool `json:"is_auto_alloc"` + + // VlanId + VlanId *int `json:"vlan_id"` + + // deprecated + Vlan *int `json:"vlan" yunion-deprecated-by:"vlan_id"` } type NetworkDetails struct { diff --git a/pkg/compute/models/networks.go b/pkg/compute/models/networks.go index a47ba2b649..45cd61c203 100644 --- a/pkg/compute/models/networks.go +++ b/pkg/compute/models/networks.go @@ -1333,6 +1333,20 @@ func (manager *SNetworkManager) ValidateCreateData(ctx context.Context, userCred return input, httperrors.NewInputParameterError("Invalid server_type: %s", input.ServerType) } + { + defaultVlanId := 1 + + if input.VlanId == nil { + input.VlanId = &defaultVlanId + } else if *input.VlanId < 1 { + input.VlanId = &defaultVlanId + } + + if *input.VlanId > 4095 { + return input, httperrors.NewInputParameterError("valid vlan id") + } + } + { if len(input.IfnameHint) == 0 { input.IfnameHint = input.Name