yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/qcloud/tdsql_database.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  	"yunion.io/x/pkg/errors"
    19  
    20  	api "yunion.io/x/cloudmux/pkg/apis/compute"
    21  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    22  	"yunion.io/x/cloudmux/pkg/multicloud"
    23  )
    24  
    25  type STDSQLDatabase struct {
    26  	rds *STDSQL
    27  	multicloud.SResourceBase
    28  	QcloudTags
    29  
    30  	DbName string
    31  }
    32  
    33  func (self *STDSQLDatabase) GetStatus() string {
    34  	return api.DBINSTANCE_DATABASE_RUNNING
    35  }
    36  
    37  func (self *STDSQLDatabase) GetId() string {
    38  	return self.DbName
    39  }
    40  
    41  func (self *STDSQLDatabase) GetName() string {
    42  	return self.DbName
    43  }
    44  
    45  func (self *STDSQLDatabase) GetGlobalId() string {
    46  	return self.DbName
    47  }
    48  
    49  func (self *STDSQLDatabase) GetCharacterSet() string {
    50  	return ""
    51  }
    52  
    53  func (self *STDSQLDatabase) Delete() error {
    54  	return cloudprovider.ErrNotSupported
    55  }
    56  
    57  func (self *SRegion) GetTDSQLDatabases(id string) ([]STDSQLDatabase, error) {
    58  	params := map[string]string{
    59  		"InstanceId": id,
    60  	}
    61  	resp, err := self.dcdbRequest("DescribeDatabases", params)
    62  	if err != nil {
    63  		return nil, errors.Wrapf(err, "DescribeDatabases")
    64  	}
    65  	ret := []STDSQLDatabase{}
    66  	err = resp.Unmarshal(&ret, "Databases")
    67  	if err != nil {
    68  		return nil, errors.Wrapf(err, "resp.Unmarshal")
    69  	}
    70  	return ret, nil
    71  }
    72  
    73  func (self *STDSQL) GetIDBInstanceDatabases() ([]cloudprovider.ICloudDBInstanceDatabase, error) {
    74  	dbs, err := self.region.GetTDSQLDatabases(self.InstanceId)
    75  	if err != nil {
    76  		return nil, errors.Wrapf(err, "GetTDSQLDatabases")
    77  	}
    78  	ret := []cloudprovider.ICloudDBInstanceDatabase{}
    79  	for i := range dbs {
    80  		dbs[i].rds = self
    81  		ret = append(ret, &dbs[i])
    82  	}
    83  	return ret, nil
    84  }