Skip to content

Commit

Permalink
fix(region): revert os dist filter and sort (#18793)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioito authored Nov 27, 2023
1 parent 26454ff commit 19b4400
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/apis/compute/guests.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ type ServerListInput struct {
// 列出操作系统为指定值的主机
// enum: linux,windows,vmware
OsType []string `json:"os_type"`
// 操作系统发行版
OsDist []string `json:"os_dist"`

// 对列表结果按照磁盘大小进行排序
// enum: asc,desc
Expand Down
11 changes: 11 additions & 0 deletions pkg/compute/models/guests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 19b4400

Please sign in to comment.