backup.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. "fmt"
  17. "os"
  18. "yunion.io/x/jsonutils"
  19. "yunion.io/x/onecloud/cmd/climc/shell"
  20. modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
  21. "yunion.io/x/onecloud/pkg/mcclient/options"
  22. "yunion.io/x/onecloud/pkg/mcclient/options/compute"
  23. )
  24. func init() {
  25. bsCmd := shell.NewResourceCmd(&modules.BackupStorages)
  26. bsCmd.List(&compute.BackupStorageListOptions{})
  27. bsCmd.Show(&compute.BackupStorageIdOptions{})
  28. bsCmd.Create(&compute.BackupStorageCreateOptions{})
  29. bsCmd.Update(&compute.BackupStorageUpdateOptions{})
  30. bsCmd.Delete(&compute.BackupStorageIdOptions{})
  31. bsCmd.Perform("public", &options.BasePublicOptions{})
  32. bsCmd.Perform("private", &options.BaseIdOptions{})
  33. bsCmd.Perform("syncstatus", &compute.DiskBackupSyncstatusOptions{})
  34. dbCmd := shell.NewResourceCmd(&modules.DiskBackups)
  35. dbCmd.List(&compute.DiskBackupListOptions{})
  36. dbCmd.Show(&compute.DiskBackupIdOptions{})
  37. dbCmd.DeleteWithParam(&compute.DiskBackupDeleteOptions{})
  38. dbCmd.Create(&compute.DiskBackupCreateOptions{})
  39. dbCmd.Perform("recovery", &compute.DiskBackupRecoveryOptions{})
  40. dbCmd.Perform("syncstatus", &compute.DiskBackupSyncstatusOptions{})
  41. dbCmd.GetWithCustomOptionShow("export-info", func(info jsonutils.JSONObject, opts shell.IGetOpt) {
  42. args := opts.(*compute.DiskBackupExportOptions)
  43. if args.Output != "" {
  44. os.WriteFile(args.Output, []byte(info.String()), 0644)
  45. fmt.Printf("Exported to %s\n", args.Output)
  46. } else {
  47. printObject(info)
  48. }
  49. }, &compute.DiskBackupExportOptions{})
  50. dbCmd.PerformClass("import", &compute.DiskBackupImportOptions{})
  51. ibCmd := shell.NewResourceCmd(&modules.InstanceBackups)
  52. ibCmd.List(&compute.InstanceBackupListOptions{})
  53. ibCmd.Show(&compute.InstanceBackupIdOptions{})
  54. ibCmd.DeleteWithParam(&compute.InstanceBackupDeleteOptions{})
  55. ibCmd.Perform("recovery", &compute.InstanceBackupRecoveryOptions{})
  56. ibCmd.Perform("pack", &compute.InstanceBackupPackOptions{})
  57. // ibCmd.PerformClass("create-from-package", &compute.InstanceBackupManagerCreateFromPackageOptions{})
  58. ibCmd.Create(&compute.InstanceBackupManagerCreateFromPackageOptions{})
  59. ibCmd.Perform("syncstatus", &compute.DiskBackupSyncstatusOptions{})
  60. ibCmd.Perform("set-class-metadata", &options.ResourceMetadataOptions{})
  61. hbsCmd := shell.NewJointCmd(&modules.HostBackupstorages)
  62. hbsCmd.List(&compute.HostBackupStorageListOptions{})
  63. hbsCmd.Show(&compute.HostBackupStorageJoinOptions{})
  64. hbsCmd.Attach(&compute.HostBackupStorageJoinOptions{})
  65. hbsCmd.Detach(&compute.HostBackupStorageJoinOptions{})
  66. }