mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
fix: add options for pre allow ip add
This commit is contained in:
@@ -296,6 +296,13 @@ func (manager *SGuestnetworkManager) newGuestNetwork(
|
||||
lockman.LockObject(ctx, network)
|
||||
defer lockman.ReleaseObject(ctx, network)
|
||||
|
||||
vpc := network.GetVpc()
|
||||
if vpc == nil {
|
||||
return nil, fmt.Errorf("cannot find vpc of network %s(%s)", network.Id, network.Name)
|
||||
}
|
||||
|
||||
provider := vpc.GetProviderName()
|
||||
|
||||
macAddr, err := manager.GenerateMac(network.Id, mac)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -317,7 +324,7 @@ func (manager *SGuestnetworkManager) newGuestNetwork(
|
||||
// if reuse Ip address, no need to check address availability
|
||||
// assign it anyway
|
||||
gn.IpAddr = address
|
||||
} else {
|
||||
} else if provider == api.CLOUD_PROVIDER_ONECLOUD || options.Options.EnablePreAllocateIpAddr {
|
||||
addrTable := network.GetUsedAddresses()
|
||||
recentAddrTable := manager.getRecentlyReleasedIPAddresses(network.Id, network.getAllocTimoutDuration())
|
||||
ipAddr, err := network.GetFreeIP(ctx, userCred, addrTable, recentAddrTable, address, allocDir, reserved)
|
||||
@@ -330,9 +337,7 @@ func (manager *SGuestnetworkManager) newGuestNetwork(
|
||||
gn.IpAddr = ipAddr
|
||||
}
|
||||
|
||||
if vpc := network.GetVpc(); vpc == nil {
|
||||
return nil, fmt.Errorf("cannot find vpc of network %s(%s)", network.Id, network.Name)
|
||||
} else if vpc.Id != api.DEFAULT_VPC_ID && vpc.GetProviderName() == api.CLOUD_PROVIDER_ONECLOUD {
|
||||
if vpc.Id != api.DEFAULT_VPC_ID && provider == api.CLOUD_PROVIDER_ONECLOUD {
|
||||
var err error
|
||||
GuestnetworkManager.lockAllocMappedAddr(ctx)
|
||||
defer GuestnetworkManager.unlockAllocMappedAddr(ctx)
|
||||
@@ -817,11 +822,11 @@ func (self *SGuestnetwork) getMtu(net *SNetwork) int {
|
||||
}
|
||||
|
||||
func (self *SGuestnetwork) IsAllocated() bool {
|
||||
if regutils.MatchMacAddr(self.MacAddr) && (self.Virtual || regutils.MatchIP4Addr(self.IpAddr)) {
|
||||
provider := self.GetGuest().getRegion().Provider
|
||||
if regutils.MatchMacAddr(self.MacAddr) && (self.Virtual || regutils.MatchIP4Addr(self.IpAddr) || (provider != api.CLOUD_PROVIDER_ONECLOUD && !options.Options.EnablePreAllocateIpAddr)) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func GetIPTenantIdPairs() {
|
||||
|
||||
@@ -3020,9 +3020,15 @@ func (self *SGuest) SyncVMNics(ctx context.Context, userCred mcclient.TokenCrede
|
||||
if len(guestnics[i].IpAddr) > 0 && guestnics[i].IpAddr == vnics[i].GetIP() {
|
||||
// mac changed
|
||||
reserve = true
|
||||
removed = append(removed, sRemoveGuestnic{nic: &guestnics[i], reserve: reserve})
|
||||
adds = append(adds, sAddGuestnic{index: i, nic: vnics[i], net: localNet, reserve: reserve})
|
||||
} else if len(guestnics[i].IpAddr) == 0 {
|
||||
db.Update(&guestnics[i], func() error {
|
||||
guestnics[i].IpAddr = vnics[i].GetIP()
|
||||
guestnics[i].MacAddr = vnics[i].GetMAC()
|
||||
return nil
|
||||
})
|
||||
}
|
||||
removed = append(removed, sRemoveGuestnic{nic: &guestnics[i], reserve: reserve})
|
||||
adds = append(adds, sAddGuestnic{index: i, nic: vnics[i], net: localNet, reserve: reserve})
|
||||
}
|
||||
} else {
|
||||
removed = append(removed, sRemoveGuestnic{nic: &guestnics[i]})
|
||||
@@ -3086,7 +3092,7 @@ func (self *SGuest) SyncVMNics(ctx context.Context, userCred mcclient.TokenCrede
|
||||
TryReserved: true,
|
||||
AllocDir: api.IPAllocationDefault,
|
||||
RequireDesignatedIP: true,
|
||||
UseDesignatedIP: false,
|
||||
UseDesignatedIP: true,
|
||||
NicConfs: []SNicConfig{nicConf},
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -114,6 +114,8 @@ type ComputeOptions struct {
|
||||
SyncCloudImagesDay int `default:"1" help:"Days auto sync public cloud images data, default 1 day"`
|
||||
SyncCloudImagesHour int `default:"3" help:"What hour start sync public cloud images, default 03:00"`
|
||||
|
||||
EnablePreAllocateIpAddr bool `help:"Enable private and public cloud private ip pre allocate, default true" default:"true"`
|
||||
|
||||
DefaultImageCacheDir string `default:"image_cache"`
|
||||
|
||||
SnapshotCreateDiskProtocol string `help:"Snapshot create disk protocol" choices:"url|fuse" default:"fuse"`
|
||||
|
||||
Reference in New Issue
Block a user