mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #1278 from wanyaoqi/feature/wyq/filter-storage-not-attached
filter storage not attached
This commit is contained in:
@@ -48,6 +48,8 @@ func init() {
|
||||
|
||||
Hypervisor string `help:"filter hosts by hypervisor"`
|
||||
|
||||
StorageNotAttached bool `help:"List hosts not attach specified storage"`
|
||||
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&HostListOptions{}, "host-list", "List hosts", func(s *mcclient.ClientSession, opts *HostListOptions) error {
|
||||
|
||||
@@ -295,6 +295,7 @@ func (manager *SHostManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu
|
||||
}
|
||||
|
||||
storageStr := jsonutils.GetAnyString(query, []string{"storage", "storage_id"})
|
||||
notAttached := jsonutils.QueryBoolean(query, "storage_not_attached", false)
|
||||
if len(storageStr) > 0 {
|
||||
storage, _ := StorageManager.FetchByIdOrName(nil, storageStr)
|
||||
if storage == nil {
|
||||
@@ -302,7 +303,11 @@ func (manager *SHostManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu
|
||||
}
|
||||
hoststorages := HoststorageManager.Query().SubQuery()
|
||||
scopeQuery := hoststorages.Query(hoststorages.Field("host_id")).Equals("storage_id", storage.GetId()).SubQuery()
|
||||
q = q.In("id", scopeQuery)
|
||||
if !notAttached {
|
||||
q = q.In("id", scopeQuery)
|
||||
} else {
|
||||
q = q.NotIn("id", scopeQuery)
|
||||
}
|
||||
}
|
||||
|
||||
q, err = managedResourceFilterByZone(q, query, "", nil)
|
||||
|
||||
Reference in New Issue
Block a user