添加storage过滤参数

This commit is contained in:
屈轩
2018-08-24 20:58:54 +08:00
parent 128bf00963
commit 7679056f55
+18
View File
@@ -12,6 +12,7 @@ import (
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/pkg/tristate"
"yunion.io/x/pkg/util/compare"
"yunion.io/x/pkg/util/sysutils"
"yunion.io/x/sqlchemy"
)
@@ -654,6 +655,23 @@ func (manager *SStorageManager) ListItemFilter(ctx context.Context, q *sqlchemy.
q = q.Filter(sqlchemy.In(q.Field("zone_id"), sq.SubQuery()))
}
if jsonutils.QueryBoolean(query, "share", false) {
q = q.Filter(sqlchemy.NotIn(q.Field("storage_type"), sysutils.LOCAL_STORAGE_TYPES))
}
if jsonutils.QueryBoolean(query, "local", false) {
q = q.Filter(sqlchemy.In(q.Field("storage_type"), sysutils.LOCAL_STORAGE_TYPES))
}
if jsonutils.QueryBoolean(query, "usable", false) {
hostStorage := HoststorageManager.Query().SubQuery()
q = q.Join(hostStorage, sqlchemy.AND(
sqlchemy.Equals(hostStorage.Field("storage_id"), q.Field("id")),
sqlchemy.In(q.Field("status"), []string{STORAGE_ENABLED, STORAGE_ONLINE}),
sqlchemy.IsTrue(q.Field("enabled")),
))
}
managerStr := jsonutils.GetAnyString(query, []string{"manager", "provider", "manager_id", "provider_id"})
if len(managerStr) > 0 {
provider := CloudproviderManager.FetchCloudproviderByIdOrName(managerStr)