mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
34 lines
950 B
Go
34 lines
950 B
Go
package sync
|
|
|
|
import (
|
|
"yunion.io/x/onecloud/pkg/scheduler/db/models"
|
|
"yunion.io/x/pkg/utils"
|
|
)
|
|
|
|
const (
|
|
HostNetworkDescBuilderCache = "HostNetworkDescBuilderCache"
|
|
BaremetalNetworkDescBuilderCache = "BaremetalNetworkDescBuilderCache"
|
|
)
|
|
|
|
func avaliableAddress(network *models.WireNetwork) (int, error) {
|
|
totalAddress := utils.IpRangeCount(network.GuestIpStart, network.GuestIpEnd)
|
|
guestNicCount, err := models.GuestNicCountsWithNetworkID(network.ID)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
groupNicCount, err := models.GroupNicCountsWithNetworkID(network.ID)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
baremetalNicCount, err := models.BaremetalNicCountsWithNetworkID(network.ID)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
reserveNicCount, err := models.ReserveNicCountsWithNetworkID(network.ID)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return totalAddress - guestNicCount.Count - groupNicCount.Count - baremetalNicCount.Count - reserveNicCount.Count, nil
|
|
}
|