feat: add 'vlan_id' param when creating network

This commit is contained in:
rainzm
2020-10-15 10:48:36 +08:00
parent 335c8eecc0
commit 7ab4decab3
2 changed files with 20 additions and 0 deletions
+6
View File
@@ -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 {
+14
View File
@@ -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