dbinstance.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 qcloud
  15. import (
  16. "context"
  17. "strings"
  18. "yunion.io/x/pkg/errors"
  19. api "yunion.io/x/cloudmux/pkg/apis/compute"
  20. "yunion.io/x/cloudmux/pkg/cloudprovider"
  21. )
  22. func (self *SRegion) GetIDBInstances() ([]cloudprovider.ICloudDBInstance, error) {
  23. ret := []cloudprovider.ICloudDBInstance{}
  24. mysqls, err := self.GetIMySQLs()
  25. if err != nil {
  26. return nil, errors.Wrapf(err, "GetIMySQLs")
  27. }
  28. ret = append(ret, mysqls...)
  29. tdsqls, err := self.GetITDSQLs()
  30. if err != nil {
  31. return nil, errors.Wrapf(err, "GetITDSQLs")
  32. }
  33. ret = append(ret, tdsqls...)
  34. mssqls, err := self.GetISQLServers()
  35. if err != nil {
  36. return nil, errors.Wrapf(err, "GetISQLServers")
  37. }
  38. ret = append(ret, mssqls...)
  39. return ret, nil
  40. }
  41. func (self *SRegion) GetIDBInstanceById(id string) (cloudprovider.ICloudDBInstance, error) {
  42. if strings.HasPrefix(id, "cdb") {
  43. return self.GetMySQLInstanceById(id)
  44. } else if strings.HasPrefix(id, "tdsqlshard") {
  45. return self.GetTDSQL(id)
  46. } else if strings.HasPrefix(id, "mssql") {
  47. return self.GetSQLServer(id)
  48. }
  49. return nil, cloudprovider.ErrNotFound
  50. }
  51. func (self *SRegion) CreateIDBInstance(opts *cloudprovider.SManagedDBInstanceCreateConfig) (cloudprovider.ICloudDBInstance, error) {
  52. if opts.Category == api.QCLOUD_DBINSTANCE_CATEGORY_TDSQL {
  53. return nil, cloudprovider.ErrNotImplemented
  54. }
  55. switch opts.Engine {
  56. case api.DBINSTANCE_TYPE_MYSQL:
  57. rds, err := self.CreateMySQLDBInstance(opts)
  58. if err != nil {
  59. return nil, errors.Wrapf(err, "CreateMySQLDBInstance")
  60. }
  61. return rds, nil
  62. }
  63. return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "For %s", opts.Engine)
  64. }
  65. func (rds *SMySQLInstance) Update(ctx context.Context, input cloudprovider.SDBInstanceUpdateOptions) error {
  66. if strings.HasPrefix(rds.InstanceId, "cdb") {
  67. return rds.region.Update(rds.InstanceId, input.NAME)
  68. }
  69. return errors.ErrNotImplemented
  70. }