Automated cherry pick of #25206: fix(region,host): host register with correct hostname (#25234)

* fix(region,host): host register with correct hostname

* fix(region): guest migrate reuse create params schedtag
This commit is contained in:
wanyaoqi
2026-07-28 11:01:36 +08:00
committed by GitHub
parent 4be8bb19a7
commit a4c39057fb
4 changed files with 20 additions and 7 deletions

View File

@@ -542,7 +542,7 @@ func (self *SGuest) PerformMigrateForecast(ctx context.Context, userCred mcclien
}
}
schedParams := self.GetSchedMigrateParams(userCred, input)
schedParams := self.GetSchedMigrateParams(ctx, userCred, input)
if input.ConvertToKvm {
schedParams.Hypervisor = api.HYPERVISOR_KVM
}
@@ -557,12 +557,19 @@ func (self *SGuest) PerformMigrateForecast(ctx context.Context, userCred mcclien
}
func (self *SGuest) GetSchedMigrateParams(
userCred mcclient.TokenCredential,
ctx context.Context, userCred mcclient.TokenCredential,
input *api.ServerMigrateForecastInput,
) *schedapi.ScheduleInput {
schedDesc := self.ToSchedDesc()
if input.PreferHostId != "" {
schedDesc.ServerConfig.PreferHost = input.PreferHostId
} else {
createParams, err := self.GetCreateParams(ctx, userCred)
if err != nil {
log.Errorf("GetSchedMigrateParams failed get create params: %s", err)
} else {
schedDesc.Schedtags = createParams.Schedtags
}
}
schedDesc.ResetCpuNumaPin = input.ResetCpuNumaPin

View File

@@ -7402,6 +7402,10 @@ func (host *SHost) RemoteHealthStatus(ctx context.Context) string {
}
func (host *SHost) GetHostnameByName() string {
if host.Hostname != "" {
return host.Hostname
}
hostname := host.Name
accessIp := strings.Replace(host.AccessIp, ".", "-", -1)
if strings.HasSuffix(host.Name, "-"+accessIp) {

View File

@@ -89,7 +89,7 @@ func (task *GuestMigrateTask) GetSchedParams() (*schedapi.ScheduleInput, error)
input.SkipCpuCheck = skipCpuCheck
input.SkipKernelCheck = skipKernelCheck
}
res := guest.GetSchedMigrateParams(task.GetUserCred(), input)
res := guest.GetSchedMigrateParams(context.Background(), task.GetUserCred(), input)
if devs, _ := guest.GetGuestIsolatedDevices(); len(devs) > 0 {
preferNumaNodesSet := cpuset.NewBuilder()

View File

@@ -1568,12 +1568,13 @@ func (h *SHostInfo) ProbeSyncIsolatedDevices(hostId string, body jsonutils.JSONO
return h.probeSyncIsolatedDevices()
}
func (h *SHostInfo) setHostname(name string) {
h.FullName = name
err := sysutils.SetHostname(name)
func (h *SHostInfo) fetchOsHostname() string {
hn, err := os.Hostname()
if err != nil {
log.Errorf("Fail to set system hostname: %s", err)
log.Fatalf("fail to get hostname %s", err)
return ""
}
return hn
}
func (h *SHostInfo) fetchHostname() string {
@@ -1621,6 +1622,7 @@ func (h *SHostInfo) updateOrCreateHost(hostId string) (*api.HostDetails, error)
if len(hostId) == 0 {
input.GenerateName = h.fetchHostname()
}
input.Hostname = h.fetchOsHostname()
input.AccessIp = masterIp
input.AccessMac = h.GetMasterMac()
var schema = "http"