From 5be641d123cd223da6468a92dc6825a9087ba525 Mon Sep 17 00:00:00 2001 From: wanyaoqi Date: Mon, 27 Nov 2023 17:12:35 +0800 Subject: [PATCH] fix(region): alloc ovn_mapped_ip_addr on host post create --- pkg/compute/models/hosts.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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}