@@ -3708,8 +3708,8 @@ func (manager *SGuestManager) TotalCount(
37083708 hostTypes []string , resourceTypes []string , providers []string , brands []string , cloudEnv string ,
37093709 since * time.Time ,
37103710 policyResult rbacutils.SPolicyResult ,
3711- ) SGuestCountStat {
3712- return usageTotalGuestResouceCount (ctx , scope , ownerId , rangeObjs , status , hypervisors , includeSystem , pendingDelete , hostTypes , resourceTypes , providers , brands , cloudEnv , since , policyResult )
3711+ ) map [ string ] SGuestCountStat {
3712+ return usageTotalGuestResourceCount (ctx , scope , ownerId , rangeObjs , status , hypervisors , includeSystem , pendingDelete , hostTypes , resourceTypes , providers , brands , cloudEnv , since , policyResult )
37133713}
37143714
37153715func (self * SGuest ) detachNetworks (ctx context.Context , userCred mcclient.TokenCredential , gns []SGuestnetwork , reserve bool ) error {
@@ -4410,7 +4410,7 @@ type SGuestCountStat struct {
44104410 TotalBackupDiskSize int
44114411}
44124412
4413- func usageTotalGuestResouceCount (
4413+ func usageTotalGuestResourceCount (
44144414 ctx context.Context ,
44154415 scope rbacscope.TRbacScope ,
44164416 ownerId mcclient.IIdentityProvider ,
@@ -4424,12 +4424,41 @@ func usageTotalGuestResouceCount(
44244424 providers []string , brands []string , cloudEnv string ,
44254425 since * time.Time ,
44264426 policyResult rbacutils.SPolicyResult ,
4427+ ) map [string ]SGuestCountStat {
4428+ countStat := make (map [string ]SGuestCountStat )
4429+ for _ , arch := range []string {apis .OS_ARCH_ALL , apis .OS_ARCH_X86_64 , apis .OS_ARCH_AARCH64 } {
4430+ allStat := usageTotalGuestResourceCountByArch (
4431+ ctx , scope , ownerId , rangeObjs , status ,
4432+ hypervisors , includeSystem , pendingDelete ,
4433+ hostTypes , resourceTypes , providers , brands ,
4434+ cloudEnv , since , policyResult , arch ,
4435+ )
4436+ countStat [arch ] = allStat
4437+ }
4438+ return countStat
4439+ }
4440+
4441+ func usageTotalGuestResourceCountByArch (
4442+ ctx context.Context ,
4443+ scope rbacscope.TRbacScope ,
4444+ ownerId mcclient.IIdentityProvider ,
4445+ rangeObjs []db.IStandaloneModel ,
4446+ status []string ,
4447+ hypervisors []string ,
4448+ includeSystem bool ,
4449+ pendingDelete bool ,
4450+ hostTypes []string ,
4451+ resourceTypes []string ,
4452+ providers []string , brands []string , cloudEnv string ,
4453+ since * time.Time ,
4454+ policyResult rbacutils.SPolicyResult ,
4455+ osArch string ,
44274456) SGuestCountStat {
44284457 q , guests := _guestResourceCountQuery (
44294458 ctx ,
44304459 scope , ownerId , rangeObjs , status , hypervisors ,
44314460 pendingDelete , hostTypes , resourceTypes , providers , brands , cloudEnv , since ,
4432- policyResult ,
4461+ policyResult , osArch ,
44334462 )
44344463 if ! includeSystem {
44354464 q = q .Filter (sqlchemy .OR (
@@ -4461,9 +4490,11 @@ func _guestResourceCountQuery(
44614490 providers []string , brands []string , cloudEnv string ,
44624491 since * time.Time ,
44634492 policyResult rbacutils.SPolicyResult ,
4493+ osArch string ,
44644494) (* sqlchemy.SQuery , * sqlchemy.SSubQuery ) {
44654495
44664496 guestdisks := GuestdiskManager .Query ().SubQuery ()
4497+
44674498 disks := DiskManager .Query ().SubQuery ()
44684499
44694500 diskQuery := guestdisks .Query (guestdisks .Field ("guest_id" ), sqlchemy .SUM ("guest_disk_size" , disks .Field ("disk_size" )))
@@ -4493,6 +4524,10 @@ func _guestResourceCountQuery(
44934524 } else {
44944525 gq = GuestManager .Query ()
44954526 }
4527+ if osArch != "" && osArch != apis .OS_ARCH_ALL {
4528+ gq = gq .Equals ("os_arch" , osArch )
4529+ }
4530+
44964531 if len (rangeObjs ) > 0 || len (hostTypes ) > 0 || len (resourceTypes ) > 0 || len (providers ) > 0 || len (brands ) > 0 || len (cloudEnv ) > 0 {
44974532 gq = filterGuestByRange (gq , rangeObjs , hostTypes , resourceTypes , providers , brands , cloudEnv )
44984533 }
0 commit comments