Merge pull request #8312 from swordqiu/feature/qj-filter-storage-by-image

feature: filter storages by image
This commit is contained in:
yunion-ci-robot
2020-10-15 23:08:34 +08:00
committed by GitHub
3 changed files with 15 additions and 0 deletions
+1
View File
@@ -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)
+3
View File
@@ -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"`
}
+11
View File
@@ -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
}