mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 08:03:53 +08:00
fix(region): add storage filter for snapshot (#23106)
This commit is contained in:
@@ -33,6 +33,7 @@ func init() {
|
||||
DiskType string `help:"Filter by disk type" choices:"sys|data"`
|
||||
Server string `help:"Filter by server" json:"server_id"`
|
||||
Unused bool
|
||||
StorageId string `help:"Filter by storage id"`
|
||||
|
||||
OrderByGuest string
|
||||
OrderByDiskName string
|
||||
|
||||
@@ -77,6 +77,9 @@ type SnapshotListInput struct {
|
||||
// 未关联任何磁盘
|
||||
Unused bool `json:"unused"`
|
||||
|
||||
// 按存储过滤
|
||||
StorageId string `json:"storage_id"`
|
||||
|
||||
// 按虚拟机名称排序
|
||||
// pattern:asc|desc
|
||||
OrderByGuest string `json:"order_by_guest"`
|
||||
|
||||
@@ -212,6 +212,10 @@ func (manager *SSnapshotManager) ListItemFilter(
|
||||
q = q.NotIn("disk_id", sq)
|
||||
}
|
||||
|
||||
if len(query.StorageId) > 0 {
|
||||
q = q.Equals("storage_id", query.StorageId)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -297,6 +301,19 @@ func (manager *SSnapshotManager) QueryDistinctExtraField(q *sqlchemy.SQuery, fie
|
||||
return q, httperrors.ErrNotFound
|
||||
}
|
||||
|
||||
func (manager *SSnapshotManager) QueryDistinctExtraFields(q *sqlchemy.SQuery, resource string, fields []string) (*sqlchemy.SQuery, error) {
|
||||
switch resource {
|
||||
case StorageManager.Keyword():
|
||||
storages := StorageManager.Query().SubQuery()
|
||||
for _, field := range fields {
|
||||
q = q.AppendField(storages.Field(field))
|
||||
}
|
||||
q = q.Join(storages, sqlchemy.Equals(q.Field("storage_id"), storages.Field("id")))
|
||||
return q, nil
|
||||
}
|
||||
return q, httperrors.ErrNotFound
|
||||
}
|
||||
|
||||
type sSnapshotGuest struct {
|
||||
DiskId string
|
||||
GuestId string
|
||||
|
||||
Reference in New Issue
Block a user