yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/qcloud/dbinstance.go (about) 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 15 package qcloud 16 17 import ( 18 "strings" 19 20 "yunion.io/x/pkg/errors" 21 22 api "yunion.io/x/cloudmux/pkg/apis/compute" 23 "yunion.io/x/cloudmux/pkg/cloudprovider" 24 ) 25 26 func (self *SRegion) GetIDBInstances() ([]cloudprovider.ICloudDBInstance, error) { 27 ret := []cloudprovider.ICloudDBInstance{} 28 mysqls, err := self.GetIMySQLs() 29 if err != nil { 30 return nil, errors.Wrapf(err, "GetIMySQLs") 31 } 32 ret = append(ret, mysqls...) 33 tdsqls, err := self.GetITDSQLs() 34 if err != nil { 35 return nil, errors.Wrapf(err, "GetITDSQLs") 36 } 37 ret = append(ret, tdsqls...) 38 return ret, nil 39 } 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 } 47 return nil, cloudprovider.ErrNotFound 48 } 49 50 func (self *SRegion) CreateIDBInstance(opts *cloudprovider.SManagedDBInstanceCreateConfig) (cloudprovider.ICloudDBInstance, error) { 51 if opts.Category == api.QCLOUD_DBINSTANCE_CATEGORY_TDSQL { 52 return nil, cloudprovider.ErrNotImplemented 53 } 54 switch opts.Engine { 55 case api.DBINSTANCE_TYPE_MYSQL: 56 rds, err := self.CreateMySQLDBInstance(opts) 57 if err != nil { 58 return nil, errors.Wrapf(err, "CreateMySQLDBInstance") 59 } 60 return rds, nil 61 } 62 return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "For %s", opts.Engine) 63 }