mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #8312 from swordqiu/feature/qj-filter-storage-by-image
feature: filter storages by image
This commit is contained in:
@@ -37,6 +37,7 @@ func init() {
|
||||
Schedtag string `help:"filter storage by schedtag"`
|
||||
|
||||
HostSchedtagId string `help:"filter storage by host schedtag"`
|
||||
ImageId string `help:"filter storage by image"`
|
||||
}
|
||||
R(&StorageListOptions{}, "storage-list", "List storages", func(s *mcclient.ClientSession, opts *StorageListOptions) error {
|
||||
params, err := options.ListStructToParams(opts)
|
||||
|
||||
@@ -186,4 +186,7 @@ type StorageListInput struct {
|
||||
|
||||
// filter by host schedtag
|
||||
HostSchedtagId string `json:"host_schedtag_id"`
|
||||
|
||||
// filter by cachedimage
|
||||
ImageId string `json:"image_id"`
|
||||
}
|
||||
|
||||
@@ -1399,6 +1399,17 @@ func (manager *SStorageManager) ListItemFilter(
|
||||
q = q.In("id", subq.SubQuery())
|
||||
}
|
||||
|
||||
if len(query.ImageId) > 0 {
|
||||
image, err := CachedimageManager.getImageInfo(ctx, userCred, query.ImageId, false)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "CachedimageManager.getImageInfo")
|
||||
}
|
||||
subq := StorageManager.Query("id")
|
||||
storagecaches := StoragecachedimageManager.Query("storagecache_id").Equals("cachedimage_id", image.Id).SubQuery()
|
||||
subq = subq.Join(storagecaches, sqlchemy.Equals(subq.Field("storagecache_id"), storagecaches.Field("storagecache_id")))
|
||||
q = q.In("id", subq.SubQuery())
|
||||
}
|
||||
|
||||
return q, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user