Skip to content

Commit

Permalink
fix: Merge the host network correctly when preparenet (#7558)
Browse files Browse the repository at this point in the history
  • Loading branch information
rainzm committed Aug 14, 2020
1 parent e099f00 commit eb67c68
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/compute/models/cloudaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
15 changes: 15 additions & 0 deletions pkg/compute/models/cloudaccounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit eb67c68

Please sign in to comment.