From e2201a80f33b65f28f22a180bb9b92d1fa5a4fa2 Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Mon, 21 Dec 2020 20:42:38 +0800 Subject: [PATCH] fix(region,baremetal): choose candidate network not according by types --- pkg/compute/models/wires.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/compute/models/wires.go b/pkg/compute/models/wires.go index e38f129211..08679e8f7d 100644 --- a/pkg/compute/models/wires.go +++ b/pkg/compute/models/wires.go @@ -804,12 +804,28 @@ func chooseNetworkByAddressCount(nets []*SNetwork) (*SNetwork, *SNetwork) { } func ChooseCandidateNetworks(nets []SNetwork, isExit bool, serverTypes []string) *SNetwork { + matchingNets := make([]*SNetwork, 0) + notMatchingNets := make([]*SNetwork, 0) + for _, s := range serverTypes { net := chooseCandidateNetworksByNetworkType(nets, isExit, s) if net != nil { - return net + if utils.IsInStringArray(net.ServerType, serverTypes) { + matchingNets = append(matchingNets, net) + } else { + notMatchingNets = append(notMatchingNets, net) + } } } + + if len(matchingNets) >= 1 { + return matchingNets[0] + } + + if len(notMatchingNets) >= 1 { + return notMatchingNets[0] + } + return nil }