diff --git a/cmd/climc/shell/compute/instance_snapshots.go b/cmd/climc/shell/compute/instance_snapshots.go index dad40d2df8..91ff6d2888 100644 --- a/cmd/climc/shell/compute/instance_snapshots.go +++ b/cmd/climc/shell/compute/instance_snapshots.go @@ -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 diff --git a/pkg/apis/compute/instance_snapshot.go b/pkg/apis/compute/instance_snapshot.go index cb72127594..06f780d3e2 100644 --- a/pkg/apis/compute/instance_snapshot.go +++ b/pkg/apis/compute/instance_snapshot.go @@ -67,4 +67,7 @@ type InstanceSnapshotListInput struct { // 操作系统类型 OsType []string `json:"os_type"` + + // 包含内存快照 + WithMemory *bool `json:"with_memory"` } diff --git a/pkg/compute/models/instance_snapshots.go b/pkg/compute/models/instance_snapshots.go index 0e8fbe19e7..019ccd5fcb 100644 --- a/pkg/compute/models/instance_snapshots.go +++ b/pkg/compute/models/instance_snapshots.go @@ -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 }