From 19b440013705d6302c7c9c492feb16fe4198cc34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Mon, 27 Nov 2023 17:34:35 +0800 Subject: [PATCH] fix(region): revert os dist filter and sort (#18793) --- pkg/apis/compute/guests.go | 2 ++ pkg/compute/models/guests.go | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/pkg/apis/compute/guests.go b/pkg/apis/compute/guests.go index 0157109b9b4..6077a65a1bb 100644 --- a/pkg/apis/compute/guests.go +++ b/pkg/apis/compute/guests.go @@ -73,6 +73,8 @@ type ServerListInput struct { // 列出操作系统为指定值的主机 // enum: linux,windows,vmware OsType []string `json:"os_type"` + // 操作系统发行版 + OsDist []string `json:"os_dist"` // 对列表结果按照磁盘大小进行排序 // enum: asc,desc diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 53121cad9a9..bb4a4f6809f 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -655,6 +655,10 @@ func (manager *SGuestManager) ListItemFilter( if len(query.OsType) > 0 { q = q.In("os_type", query.OsType) } + if len(query.OsDist) > 0 { + metaSQ := db.Metadata.Query().Equals("key", "os_distribution").In("value", query.OsDist).SubQuery() + q = q.Join(metaSQ, sqlchemy.Equals(q.Field("id"), metaSQ.Field("obj_id"))) + } if len(query.VcpuCount) > 0 { q = q.In("vcpu_count", query.VcpuCount) } @@ -780,6 +784,13 @@ func (manager *SGuestManager) QueryDistinctExtraField(q *sqlchemy.SQuery, field if err == nil { return q, nil } + if field == "os_dist" { + metaQuery := db.Metadata.Query("obj_id", "value").Equals("key", "os_distribution").SubQuery() + q = q.AppendField(metaQuery.Field("value", field)).Distinct() + q = q.Join(metaQuery, sqlchemy.Equals(q.Field("id"), metaQuery.Field("obj_id"))) + q.GroupBy(metaQuery.Field("value")) + return q, nil + } guestnets := GuestnetworkManager.Query("guest_id", "network_id").SubQuery() q = q.LeftJoin(guestnets, sqlchemy.Equals(q.Field("id"), guestnets.Field("guest_id"))) q, err = manager.SNetworkResourceBaseManager.QueryDistinctExtraField(q, field)