instance_snapshots.go 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package compute
  15. import (
  16. "yunion.io/x/jsonutils"
  17. "yunion.io/x/onecloud/pkg/mcclient"
  18. modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
  19. "yunion.io/x/onecloud/pkg/mcclient/options"
  20. )
  21. func init() {
  22. type InstanceSnapshotsListOptions struct {
  23. options.BaseListOptions
  24. GuestId string `help:"guest id" json:"guest_id"`
  25. HasMemory bool `help:"contains memory snapshot" json:"-"`
  26. NotHasMemory bool `help:"not contains memory snapshot" json:"-"`
  27. OrderByDiskSnapshotCount string
  28. OrderByGuest string
  29. }
  30. R(&InstanceSnapshotsListOptions{}, "instance-snapshot-list", "Show instance snapshots", func(s *mcclient.ClientSession, args *InstanceSnapshotsListOptions) error {
  31. params, err := options.ListStructToParams(args)
  32. if err != nil {
  33. return err
  34. }
  35. if args.HasMemory {
  36. params.Set("with_memory", jsonutils.NewBool(true))
  37. }
  38. if args.NotHasMemory {
  39. params.Set("with_memory", jsonutils.NewBool(false))
  40. }
  41. result, err := modules.InstanceSnapshots.List(s, params)
  42. if err != nil {
  43. return err
  44. }
  45. printList(result, modules.InstanceSnapshots.GetColumns(s))
  46. return nil
  47. })
  48. type InstanceSnapshotDeleteOptions struct {
  49. ID []string `help:"Delete snapshot id"`
  50. }
  51. R(&InstanceSnapshotDeleteOptions{}, "instance-snapshot-delete", "Delete snapshots", func(s *mcclient.ClientSession, args *InstanceSnapshotDeleteOptions) error {
  52. ret := modules.InstanceSnapshots.BatchDelete(s, args.ID, nil)
  53. printBatchResults(ret, modules.InstanceSnapshots.GetColumns(s))
  54. return nil
  55. })
  56. type InstanceSnapshotPurgeOptions struct {
  57. ID string `help:"Delete snapshot id"`
  58. }
  59. R(&InstanceSnapshotPurgeOptions{}, "instance-snapshot-purge", "Purge snapshots", func(s *mcclient.ClientSession, args *InstanceSnapshotPurgeOptions) error {
  60. result, err := modules.InstanceSnapshots.PerformAction(s, args.ID, "purge", nil)
  61. if err != nil {
  62. return err
  63. }
  64. printObject(result)
  65. return nil
  66. })
  67. type InstanceSnapshotShowOptions struct {
  68. ID string `help:"ID or Name of snapshot"`
  69. }
  70. R(&InstanceSnapshotShowOptions{}, "instance-snapshot-show", "Show snapshot details", func(s *mcclient.ClientSession, args *InstanceSnapshotShowOptions) error {
  71. result, err := modules.InstanceSnapshots.Get(s, args.ID, nil)
  72. if err != nil {
  73. return err
  74. }
  75. printObject(result)
  76. return nil
  77. })
  78. }