From 2fb095bc5b176db4f15fff325a650d056a7c456c Mon Sep 17 00:00:00 2001 From: Qu Xuan Date: Thu, 20 May 2021 14:38:49 +0800 Subject: [PATCH] fix(region): add host_id options for storage filter --- pkg/apis/compute/storage_const.go | 3 +++ pkg/compute/models/storages.go | 5 +++++ pkg/mcclient/options/compute/storage.go | 1 + 3 files changed, 9 insertions(+) diff --git a/pkg/apis/compute/storage_const.go b/pkg/apis/compute/storage_const.go index 7aaddacf0f..1324b8e477 100644 --- a/pkg/apis/compute/storage_const.go +++ b/pkg/apis/compute/storage_const.go @@ -222,4 +222,7 @@ type StorageListInput struct { // filter by cachedimage ImageId string `json:"image_id"` + + // filter storages which attached the specified host + HostId string `json:"host_id"` } diff --git a/pkg/compute/models/storages.go b/pkg/compute/models/storages.go index ec58108056..0b24d71988 100644 --- a/pkg/compute/models/storages.go +++ b/pkg/compute/models/storages.go @@ -1476,6 +1476,11 @@ func (manager *SStorageManager) ListItemFilter( q = q.In("id", subq.SubQuery()) } + if len(query.HostId) > 0 { + sq := HoststorageManager.Query("storage_id").Equals("host_id", query.HostId) + q = q.In("id", sq.SubQuery()) + } + return q, err } diff --git a/pkg/mcclient/options/compute/storage.go b/pkg/mcclient/options/compute/storage.go index 5ba848c5e6..a1fa86ceed 100644 --- a/pkg/mcclient/options/compute/storage.go +++ b/pkg/mcclient/options/compute/storage.go @@ -31,6 +31,7 @@ type StorageListOptions struct { Zone string `help:"List storages in zone" json:"-"` Region string `help:"List storages in region"` Schedtag string `help:"filter storage by schedtag"` + HostId string `help:"filter storages which attached the specified host"` HostSchedtagId string `help:"filter storage by host schedtag"` ImageId string `help:"filter storage by image"`