Skip to content

Commit

Permalink
fix(region): filter unused snapshot (#21561)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioito authored Nov 12, 2024
1 parent 4af0a0f commit 8d1d071
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/climc/shell/compute/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/compute/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
5 changes: 5 additions & 0 deletions pkg/compute/models/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,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
}

Expand Down

0 comments on commit 8d1d071

Please sign in to comment.