Skip to content

Commit 6ec0769

Browse files
swordqiuQiu Jian
andauthored
fix: check os_arch when server rebuilding root (#23339)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
1 parent d46a701 commit 6ec0769

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

pkg/apis/const.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,27 @@ func IsARM(osArch string) bool {
175175
return utils.IsInStringArray(osArch, ARCH_ARM)
176176
}
177177

178+
func IsX86(osArch string) bool {
179+
return utils.IsInStringArray(osArch, ARCH_X86)
180+
}
181+
178182
func IsIllegalSearchDomain(domain string) bool {
179183
switch domain {
180184
case "cloud.onecloud.io":
181185
return true
182186
}
183187
return false
184188
}
189+
190+
func IsSameArch(arch1, arch2 string) bool {
191+
if arch1 == arch2 {
192+
return true
193+
}
194+
if IsARM(arch1) && IsARM(arch2) {
195+
return true
196+
}
197+
if IsX86(arch1) && IsX86(arch2) {
198+
return true
199+
}
200+
return false
201+
}

pkg/compute/models/guest_actions.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,9 +1919,11 @@ func (self *SGuest) PerformRebuildRoot(
19191919
}
19201920

19211921
// compare os arch
1922-
if len(self.InstanceType) > 0 {
1922+
if len(img.Properties["os_arch"]) > 0 && len(self.OsArch) > 0 && !apis.IsSameArch(self.OsArch, img.Properties["os_arch"]) {
1923+
return nil, httperrors.NewConflictError("root disk image(%s) and guest(%s) OsArch mismatch", img.Properties["os_arch"], self.OsArch)
1924+
} else if len(self.InstanceType) > 0 {
19231925
sku, _ := ServerSkuManager.FetchSkuByNameAndProvider(self.InstanceType, region.Provider, true)
1924-
if sku != nil && len(sku.CpuArch) > 0 && len(img.Properties["os_arch"]) > 0 && !strings.Contains(img.Properties["os_arch"], sku.CpuArch) {
1926+
if sku != nil && len(sku.CpuArch) > 0 && len(img.Properties["os_arch"]) > 0 && !apis.IsSameArch(img.Properties["os_arch"], sku.CpuArch) {
19251927
return nil, httperrors.NewConflictError("root disk image(%s) and sku(%s) architecture mismatch", img.Properties["os_arch"], sku.CpuArch)
19261928
}
19271929
}

0 commit comments

Comments
 (0)