Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(region): filter unused snapshot #21561

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading