feat(region): instance snapshot with_memory filter

This commit is contained in:
Zexi Li
2022-03-07 15:58:31 +08:00
parent 1b0d4e4dfd
commit 35f631745a
3 changed files with 22 additions and 1 deletions
+11 -1
View File
@@ -15,6 +15,8 @@
package compute
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
"yunion.io/x/onecloud/pkg/mcclient/options"
@@ -24,13 +26,21 @@ func init() {
type InstanceSnapshotsListOptions struct {
options.BaseListOptions
GuestId string `help:"guest id" json:"guest_id"`
GuestId string `help:"guest id" json:"guest_id"`
HasMemory bool `help:"contains memory snapshot" json:"-"`
NotHasMemory bool `help:"not contains memory snapshot" json:"-"`
}
R(&InstanceSnapshotsListOptions{}, "instance-snapshot-list", "Show instance snapshots", func(s *mcclient.ClientSession, args *InstanceSnapshotsListOptions) error {
params, err := options.ListStructToParams(args)
if err != nil {
return err
}
if args.HasMemory {
params.Set("with_memory", jsonutils.NewBool(true))
}
if args.NotHasMemory {
params.Set("with_memory", jsonutils.NewBool(false))
}
result, err := modules.InstanceSnapshots.List(s, params)
if err != nil {
return err
+3
View File
@@ -67,4 +67,7 @@ type InstanceSnapshotListInput struct {
// 操作系统类型
OsType []string `json:"os_type"`
// 包含内存快照
WithMemory *bool `json:"with_memory"`
}
+8
View File
@@ -143,6 +143,14 @@ func (manager *SInstanceSnapshotManager) ListItemFilter(
q = q.In("os_type", query.OsType)
}
if query.WithMemory != nil {
if *query.WithMemory {
q = q.IsTrue("with_memory")
} else {
q = q.IsFalse("with_memory")
}
}
return q, nil
}