fix(region,scheduler): check is BIOS boot request on uefi predicate (#23719)

This commit is contained in:
wanyaoqi
2025-11-11 13:45:28 +08:00
committed by GitHub
parent dea5f90e5b
commit 47ac45dfe9
2 changed files with 39 additions and 10 deletions
+1
View File
@@ -52,6 +52,7 @@ type ServerConfig struct {
Name string `json:"name"`
GuestStatus string `json:"guest_status"`
Cdrom string `json:"cdrom"`
Bios string `json:"bios"`
// owner project id
Project string `json:"project_id"`
@@ -21,6 +21,7 @@ import (
"yunion.io/x/pkg/errors"
api "yunion.io/x/onecloud/pkg/apis/image"
"yunion.io/x/onecloud/pkg/compute/models"
"yunion.io/x/onecloud/pkg/scheduler/algorithm/predicates"
"yunion.io/x/onecloud/pkg/scheduler/core"
@@ -65,7 +66,15 @@ func (f *UEFIImagePredicate) isImageUEFI() bool {
if f.cacheImage.UEFI.Bool() {
return true
}
support, err := f.cacheImage.Info.Bool("properties", "uefi_support")
support, err := f.cacheImage.Info.Bool("properties", api.IMAGE_UEFI_SUPPORT)
if err != nil {
return false
}
return support
}
func (f *UEFIImagePredicate) isImageBIOS() bool {
support, err := f.cacheImage.Info.Bool("properties", api.IMAGE_BIOS_SUPPORT)
if err != nil {
return false
}
@@ -74,20 +83,39 @@ func (f *UEFIImagePredicate) isImageUEFI() bool {
func (f *UEFIImagePredicate) Execute(ctx context.Context, u *core.Unit, c core.Candidater) (bool, []core.PredicateFailureReason, error) {
h := predicates.NewPredicateHelper(f, u, c)
bios := u.SchedData().Bios
imgName := f.cacheImage.GetName()
hostName := c.Getter().Name()
imageMsg := fmt.Sprintf("image %s is not UEFI", imgName)
hostMsg := fmt.Sprintf("host %s is not UEFI boot", hostName)
isBIOSImage := f.isImageBIOS()
isUEFIImage := f.isImageUEFI()
if isUEFIImage {
imageMsg = fmt.Sprintf("image %s is UEFI", imgName)
if !isUEFIImage { // if not uefi image, set default bios image
isBIOSImage = true
}
isUEFIHost := c.Getter().Host().IsUEFIBoot()
if isUEFIHost {
hostMsg = fmt.Sprintf("host %s is UEFI boot", hostName)
}
if isUEFIImage != isUEFIHost {
h.Exclude(imageMsg + " but " + hostMsg)
if bios == "UEFI" {
if !isUEFIImage || !isUEFIHost {
h.Exclude(fmt.Sprintf("request boot UEFI, but host %s UEFI is %v, image %s UEFI is %v",
hostName, isUEFIHost, imgName, isUEFIImage))
}
} else if bios == "BIOS" {
if !isBIOSImage || isUEFIHost {
h.Exclude(fmt.Sprintf("request boot BIOS, but host %s UEFI is %v, image %s BIOS is %v",
hostName, isUEFIHost, imgName, isBIOSImage))
}
} else {
if isUEFIHost {
if !isUEFIImage {
h.Exclude(fmt.Sprintf("host %s UEFI is %v, image %s UEFI is %v",
hostName, isUEFIHost, imgName, isUEFIImage))
}
} else {
if !isBIOSImage {
h.Exclude(fmt.Sprintf("host %s UEFI is %v, image %s BIOS is %v",
hostName, isUEFIHost, imgName, isBIOSImage))
}
}
}
return h.GetResult()
}