diff --git a/pkg/apis/compute/guests.go b/pkg/apis/compute/guests.go index 0157109b9b..6077a65a1b 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 f13b7a2e48..bb4a4f6809 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) }