Automatic merge from release/2.5.0 -> release/2.6.0

* commit '6ebc5d9f02f123e62fc0d2b65d1f2f884c0d806b':
  disk-list filter public & private cloud
This commit is contained in:
邱剑
2019-01-24 14:50:25 +08:00
2 changed files with 24 additions and 7 deletions
+15 -7
View File
@@ -11,13 +11,13 @@ import (
func init() {
type DiskListOptions struct {
options.BaseListOptions
Unused *bool `help:"Show unused disks"`
Share *bool `help:"Show Share storage disks"`
Local *bool `help:"Show Local storage disks"`
Guest string `help:"Guest ID or name"`
Storage string `help:"Storage ID or name"`
Type string `help:"Disk type" choices:"sys|data|swap|volume"`
Unused *bool `help:"Show unused disks"`
Share *bool `help:"Show Share storage disks"`
Local *bool `help:"Show Local storage disks"`
Guest string `help:"Guest ID or name"`
Storage string `help:"Storage ID or name"`
Type string `help:"Disk type" choices:"sys|data|swap|volume"`
CloudType string `help:"Public cloud or private cloud" choices:"Public|Private"`
BillingType string `help:"billing type" choices:"postpaid|prepaid"`
}
@@ -26,6 +26,14 @@ func init() {
if err != nil {
return err
}
if len(suboptions.CloudType) > 0 {
if suboptions.CloudType == "Public" {
params.Add(jsonutils.JSONTrue, "public_cloud")
} else if suboptions.CloudType == "Private" {
params.Add(jsonutils.JSONTrue, "private_cloud")
}
}
result, err := modules.Disks.List(s, params)
if err != nil {
return err
+9
View File
@@ -167,6 +167,15 @@ func (manager *SDiskManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu
sq := storages.Query(storages.Field("id")).Filter(sqlchemy.NotIn(storages.Field("storage_type"), STORAGE_LOCAL_TYPES))
q = q.Filter(sqlchemy.In(q.Field("storage_id"), sq))
}
if jsonutils.QueryBoolean(query, "public_cloud", false) {
sq := storages.Query(storages.Field("id")).Filter(sqlchemy.IsNotNull(storages.Field("manager_id")))
q = q.Filter(sqlchemy.In(q.Field("storage_id"), sq))
} else if jsonutils.QueryBoolean(query, "private_cloud", false) {
sq := storages.Query(storages.Field("id")).Filter(sqlchemy.IsNull(storages.Field("manager_id")))
q = q.Filter(sqlchemy.In(q.Field("storage_id"), sq))
}
if jsonutils.QueryBoolean(query, "local", false) {
sq := storages.Query(storages.Field("id")).Filter(sqlchemy.In(storages.Field("storage_type"), STORAGE_LOCAL_TYPES))
q = q.Filter(sqlchemy.In(q.Field("storage_id"), sq))