dbinstance_backups.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 DBInstanceBackupListOptions struct {
  23. options.BaseListOptions
  24. DBInstance string `help:"ID or Name of DBInstance" json:"dbinstance"`
  25. Cloudregion string `help:"ID or Name of cloudregion"`
  26. }
  27. R(&DBInstanceBackupListOptions{}, "dbinstance-backup-list", "List DB instance backups", func(s *mcclient.ClientSession, opts *DBInstanceBackupListOptions) error {
  28. params, err := options.ListStructToParams(opts)
  29. if err != nil {
  30. return err
  31. }
  32. result, err := modules.DBInstanceBackups.List(s, params)
  33. if err != nil {
  34. return err
  35. }
  36. if len(opts.ExportFile) > 0 {
  37. exportList(result, opts.ExportFile, opts.ExportKeys, opts.ExportTexts, modules.DBInstanceBackups.GetColumns(s))
  38. } else {
  39. printList(result, modules.DBInstanceBackups.GetColumns(s))
  40. }
  41. return nil
  42. })
  43. type DBInstanceBackupCreateOptions struct {
  44. INSTANCE string `help:"ID or Name of DBInstance" json:"dbinstance"`
  45. NAME string
  46. Databases []string
  47. Description string
  48. }
  49. R(&DBInstanceBackupCreateOptions{}, "dbinstance-backup-create", "Create DB instance backup", func(s *mcclient.ClientSession, opts *DBInstanceBackupCreateOptions) error {
  50. params := jsonutils.NewDict()
  51. params.Add(jsonutils.NewString(opts.INSTANCE), "dbinstance")
  52. params.Add(jsonutils.NewString(opts.NAME), "name")
  53. params.Add(jsonutils.NewString(opts.Description), "description")
  54. databases := jsonutils.NewArray()
  55. for _, database := range opts.Databases {
  56. databases.Add(jsonutils.NewString(database))
  57. }
  58. params.Add(databases, "databases")
  59. result, err := modules.DBInstanceBackups.Create(s, params)
  60. if err != nil {
  61. return err
  62. }
  63. printObject(result)
  64. return nil
  65. })
  66. type DBInstanceBackupIdOptions struct {
  67. ID string
  68. }
  69. R(&DBInstanceBackupIdOptions{}, "dbinstance-backup-show", "Show DB instance backup", func(s *mcclient.ClientSession, opts *DBInstanceBackupIdOptions) error {
  70. result, err := modules.DBInstanceBackups.Get(s, opts.ID, nil)
  71. if err != nil {
  72. return err
  73. }
  74. printObject(result)
  75. return nil
  76. })
  77. R(&DBInstanceBackupIdOptions{}, "dbinstance-backup-syncstatus", "Sync DB instance backup status", func(s *mcclient.ClientSession, opts *DBInstanceBackupIdOptions) error {
  78. result, err := modules.DBInstanceBackups.PerformAction(s, opts.ID, "syncstatus", nil)
  79. if err != nil {
  80. return err
  81. }
  82. printObject(result)
  83. return nil
  84. })
  85. R(&DBInstanceBackupIdOptions{}, "dbinstance-backup-delete", "Delete DB instance backup", func(s *mcclient.ClientSession, opts *DBInstanceBackupIdOptions) error {
  86. result, err := modules.DBInstanceBackups.Delete(s, opts.ID, nil)
  87. if err != nil {
  88. return err
  89. }
  90. printObject(result)
  91. return nil
  92. })
  93. }