mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
fix: Merge the host network correctly when preparenet (#7557)
This commit is contained in:
@@ -650,15 +650,19 @@ func (manager *SCloudaccountManager) fetchEsxiZoneIds() ([]string, error) {
|
||||
// The suggested network mask is 24 and the gateway is x.x.x.1.
|
||||
// The suggests network is the smallest network segment that meets the above conditions.
|
||||
func (manager *SCloudaccountManager) suggestHostNetworks(ips []netutils.IPV4Addr) []api.CASimpleNetConf {
|
||||
if len(ips) == 0 {
|
||||
return nil
|
||||
}
|
||||
sort.Slice(ips, func(i, j int) bool {
|
||||
return ips[i] < ips[j]
|
||||
})
|
||||
var (
|
||||
mask int8 = 24
|
||||
consequent []netutils.IPV4Addr
|
||||
ret []api.CASimpleNetConf
|
||||
mask int8 = 24
|
||||
lastnetAddr netutils.IPV4Addr
|
||||
consequent []netutils.IPV4Addr
|
||||
ret []api.CASimpleNetConf
|
||||
)
|
||||
lastnetAddr, _ := netutils.NewIPV4Addr("0.0.0.0")
|
||||
lastnetAddr = ips[0].NetAddr(mask)
|
||||
consequent = []netutils.IPV4Addr{ips[0]}
|
||||
for i := 1; i < len(ips); i++ {
|
||||
ip := ips[i]
|
||||
|
||||
@@ -71,6 +71,21 @@ func TestSCloudaccount_suggestHostNetworks(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
[]string{
|
||||
"10.155.50.103",
|
||||
"10.155.50.101",
|
||||
"10.155.50.102",
|
||||
},
|
||||
[]api.CASimpleNetConf{
|
||||
{
|
||||
GuestIpStart: "10.155.50.101",
|
||||
GuestIpEnd: "10.155.50.103",
|
||||
GuestIpMask: 24,
|
||||
GuestGateway: "10.155.50.1",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, c := range cases {
|
||||
ins := make([]netutils.IPV4Addr, len(c.in))
|
||||
|
||||
Reference in New Issue
Block a user