mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix: check os_arch when server rebuilding root (#23339)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -175,6 +175,10 @@ func IsARM(osArch string) bool {
|
||||
return utils.IsInStringArray(osArch, ARCH_ARM)
|
||||
}
|
||||
|
||||
func IsX86(osArch string) bool {
|
||||
return utils.IsInStringArray(osArch, ARCH_X86)
|
||||
}
|
||||
|
||||
func IsIllegalSearchDomain(domain string) bool {
|
||||
switch domain {
|
||||
case "cloud.onecloud.io":
|
||||
@@ -182,3 +186,16 @@ func IsIllegalSearchDomain(domain string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func IsSameArch(arch1, arch2 string) bool {
|
||||
if arch1 == arch2 {
|
||||
return true
|
||||
}
|
||||
if IsARM(arch1) && IsARM(arch2) {
|
||||
return true
|
||||
}
|
||||
if IsX86(arch1) && IsX86(arch2) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1919,9 +1919,11 @@ func (self *SGuest) PerformRebuildRoot(
|
||||
}
|
||||
|
||||
// compare os arch
|
||||
if len(self.InstanceType) > 0 {
|
||||
if len(img.Properties["os_arch"]) > 0 && len(self.OsArch) > 0 && !apis.IsSameArch(self.OsArch, img.Properties["os_arch"]) {
|
||||
return nil, httperrors.NewConflictError("root disk image(%s) and guest(%s) OsArch mismatch", img.Properties["os_arch"], self.OsArch)
|
||||
} else if len(self.InstanceType) > 0 {
|
||||
sku, _ := ServerSkuManager.FetchSkuByNameAndProvider(self.InstanceType, region.Provider, true)
|
||||
if sku != nil && len(sku.CpuArch) > 0 && len(img.Properties["os_arch"]) > 0 && !strings.Contains(img.Properties["os_arch"], sku.CpuArch) {
|
||||
if sku != nil && len(sku.CpuArch) > 0 && len(img.Properties["os_arch"]) > 0 && !apis.IsSameArch(img.Properties["os_arch"], sku.CpuArch) {
|
||||
return nil, httperrors.NewConflictError("root disk image(%s) and sku(%s) architecture mismatch", img.Properties["os_arch"], sku.CpuArch)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user