dbinstances.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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/pkg/util/printutils"
  17. "yunion.io/x/onecloud/cmd/climc/shell"
  18. "yunion.io/x/onecloud/pkg/mcclient"
  19. modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
  20. "yunion.io/x/onecloud/pkg/mcclient/options"
  21. "yunion.io/x/onecloud/pkg/mcclient/options/compute"
  22. )
  23. func init() {
  24. cmd := shell.NewResourceCmd(&modules.DBInstance) //.WithContextManager(&modules.Networks)
  25. cmd.List(&compute.DBInstanceListOptions{})
  26. cmd.Create(&compute.DBInstanceCreateOptions{})
  27. cmd.Update(&compute.DBInstanceUpdateOptions{})
  28. cmd.Show(&compute.DBInstanceIdOptions{})
  29. cmd.Delete(&compute.DBInstanceDeleteOptions{})
  30. cmd.Perform("renew", &compute.DBInstanceRenewOptions{})
  31. cmd.Perform("change-config", &compute.DBInstanceChangeConfigOptions{})
  32. cmd.Perform("public-connection", &compute.DBInstancePublicConnectionOptions{})
  33. cmd.Perform("recovery", &compute.DBInstanceRecoveryOptions{})
  34. cmd.Perform("reboot", &compute.DBInstanceIdOptions{})
  35. cmd.Perform("purge", &compute.DBInstanceIdOptions{})
  36. cmd.Perform("syncstatus", &compute.DBInstanceIdOptions{})
  37. cmd.Perform("sync", &compute.DBInstanceIdOptions{})
  38. cmd.Perform("change-owner", &compute.DBInstanceChangeOwnerOptions{})
  39. cmd.PerformWithKeyword("add-tag", "user-metadata", &options.ResourceMetadataOptions{})
  40. cmd.PerformWithKeyword("set-tag", "set-user-metadata", &options.ResourceMetadataOptions{})
  41. cmd.Perform("remote-update", &compute.DBInstanceRemoteUpdateOptions{})
  42. cmd.Perform("set-secgroup", &compute.DBInstanceSetSecgroupOptions{})
  43. type DBInstanceNetworkListOptions struct {
  44. options.BaseListOptions
  45. DBInstance string `help:"ID or Name of DBInstance" json:"dbinstance"`
  46. Network string `help:"Network ID or name"`
  47. }
  48. R(&DBInstanceNetworkListOptions{}, "dbinstance-network-list", "List DB instance networks", func(s *mcclient.ClientSession, opts *DBInstanceNetworkListOptions) error {
  49. params, err := options.ListStructToParams(opts)
  50. if err != nil {
  51. return err
  52. }
  53. var result *printutils.ListResult
  54. if len(opts.DBInstance) > 0 {
  55. result, err = modules.DBInstanceNetworks.ListDescendent(s, opts.DBInstance, params)
  56. } else if len(opts.Network) > 0 {
  57. result, err = modules.DBInstanceNetworks.ListDescendent2(s, opts.Network, params)
  58. } else {
  59. result, err = modules.DBInstanceNetworks.List(s, params)
  60. }
  61. if err != nil {
  62. return err
  63. }
  64. printList(result, modules.DBInstanceNetworks.GetColumns(s))
  65. return nil
  66. })
  67. type DBInstanceParameterListOptions struct {
  68. options.BaseListOptions
  69. DBInstance string `help:"ID or Name of DBInstance" json:"dbinstance"`
  70. }
  71. R(&DBInstanceParameterListOptions{}, "dbinstance-parameter-list", "List DB instance parameters", func(s *mcclient.ClientSession, opts *DBInstanceParameterListOptions) error {
  72. params, err := options.ListStructToParams(opts)
  73. if err != nil {
  74. return err
  75. }
  76. result, err := modules.DBInstanceParameters.List(s, params)
  77. if err != nil {
  78. return err
  79. }
  80. printList(result, modules.DBInstanceParameters.GetColumns(s))
  81. return nil
  82. })
  83. type DBInstancePrivilegeListOptions struct {
  84. options.BaseListOptions
  85. DBInstanceaccount string `help:"ID or Name of DBInstanceaccount" json:"dbinstanceaccount"`
  86. DBInstancedatabase string `help:"ID or Name of DBInstancedatabase" json:"dbinstancedatabase"`
  87. }
  88. R(&DBInstancePrivilegeListOptions{}, "dbinstance-privilege-list", "List DB instance accounts", func(s *mcclient.ClientSession, opts *DBInstancePrivilegeListOptions) error {
  89. params, err := options.ListStructToParams(opts)
  90. if err != nil {
  91. return err
  92. }
  93. result, err := modules.DBInstancePrivileges.List(s, params)
  94. if err != nil {
  95. return err
  96. }
  97. printList(result, modules.DBInstancePrivileges.GetColumns(s))
  98. return nil
  99. })
  100. }