Merge pull request #1278 from wanyaoqi/feature/wyq/filter-storage-not-attached

filter storage not attached
This commit is contained in:
yunion-ci-robot
2019-06-18 17:22:55 +08:00
committed by GitHub
2 changed files with 8 additions and 1 deletions
+2
View File
@@ -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 {
+6 -1
View File
@@ -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)