fix(region): filter unused snapshot (#21563)

This commit is contained in:
屈轩
2024-11-12 11:16:18 +08:00
committed by GitHub
parent 583d5be908
commit 5ac7edf489
3 changed files with 9 additions and 0 deletions
+1
View File
@@ -32,6 +32,7 @@ func init() {
Share *bool `help:"Show shared snapshots"`
DiskType string `help:"Filter by disk type" choices:"sys|data"`
Server string `help:"Filter by server" json:"server_id"`
Unused bool
OrderByGuest string
OrderByDiskName string
+3
View File
@@ -74,6 +74,9 @@ type SnapshotListInput struct {
// list server snapshots
ServerId string `json:"server_id"`
// 未关联任何磁盘
Unused bool `json:"unused"`
// 按虚拟机名称排序
// pattern:asc|desc
OrderByGuest string `json:"order_by_guest"`
+5
View File
@@ -205,6 +205,11 @@ func (manager *SSnapshotManager) ListItemFilter(
q = q.In("disk_id", gdq)
}
if query.Unused {
sq := DiskManager.Query("id").Distinct().SubQuery()
q = q.NotIn("disk_id", sq)
}
return q, nil
}