diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index 65da6c3ba8..eff714397f 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -3423,6 +3423,22 @@ func (hh *SHost) PostCreate( hh.StartBaremetalCreateTask(ctx, userCred, kwargs, "") } } + if hh.OvnVersion != "" && hh.OvnMappedIpAddr == "" { + HostManager.lockAllocOvnMappedIpAddr(ctx) + defer HostManager.unlockAllocOvnMappedIpAddr(ctx) + addr, err := HostManager.allocOvnMappedIpAddr(ctx) + if err != nil { + log.Errorf("host %s(%s): alloc vpc mapped addr: %v", + hh.Name, hh.Id, err) + } + if _, err := db.Update(hh, func() error { + hh.OvnMappedIpAddr = addr + return nil + }); err != nil { + log.Errorf("host %s(%s): db update vpc mapped addr: %v", + hh.Name, hh.Id, err) + } + } keys := GetHostQuotaKeysFromCreateInput(ownerId, input) quota := SInfrasQuota{Host: 1}